2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <vconf-internal-bt-keys.h>
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
27 #include "bt-service-common.h"
28 #include "bt-service-event.h"
29 #include "bt-service-main.h"
30 #include "bt-service-adapter.h"
31 #include "bt-service-adapter-le.h"
32 #include "bt-service-device.h"
33 #include "bt-service-avrcp.h"
34 #include "bt-service-obex-server.h"
35 #include "bt-service-rfcomm-server.h"
36 #include "bt-service-audio.h"
37 #include "bt-service-agent.h"
38 #include "bt-service-pbap.h"
39 #include "bt-service-headset-connection.h"
40 #include "bt-service-avrcp-controller.h"
41 #include "bt-service-hid.h"
42 #include "bt-service-proximity.h"
44 #include "bt-service-opp-client.h"
45 #include "bt-service-map-client.h"
46 #include "bt-service-tds.h"
47 #include "bt-service-otp.h"
49 #ifdef TIZEN_FEATURE_BT_DPM
50 #include "bt-service-dpm.h"
53 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
54 static GDBusConnection *manager_conn;
55 static GDBusConnection *obexd_conn;
56 static GDBusConnection *opc_obexd_conn;
57 static GDBusConnection *map_obexd_conn;
59 static GList *p_cache_list = NULL;
61 static guint event_id;
62 static guint le_scan_event_id = 0;
63 static guint session_reinit_timer;
64 guint nap_connected_device_count = 0;
65 static guint hid_connected_device_count = 0;
66 static GList *p_adv_ind_list = NULL;
69 bt_remote_dev_info_t *dev_info;
73 * obexd connection type
81 OBEX_PCSUITE = (1 << 6),
82 OBEX_SYNCEVOLUTION = (1 << 7),
85 } bluetooth_obex_connection_type_t;
87 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
88 void _bt_opc_property_changed_event(GVariant *msg, char *path);
89 void _bt_map_property_changed_event(GVariant *msg, const char *path);
90 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
91 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
92 void _bt_opp_client_event_deinit(void);
93 void _bt_map_client_event_deinit(void);
94 void _bt_handle_network_client_event(GVariant *msg_iter,
96 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
98 void _bt_map_on_transfer_finished(const char *transfer_object_path, const int error);
100 static void __bt_free_bt_le_adv_info_t(gpointer data)
102 bt_le_adv_info_t *adv_info = data;
104 if (adv_info->timer_id)
105 g_source_remove(adv_info->timer_id);
106 adv_info->timer_id = 0;
108 g_free(adv_info->addr);
109 g_free(adv_info->data);
113 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
115 retv_if(!addr, NULL);
116 bt_le_adv_info_t *adv_info = NULL;
117 GList *current = g_list_first((GList *)p_adv_ind_list);
118 while (current && current->data) {
119 adv_info = (bt_le_adv_info_t *)current->data;
120 if (adv_info && !g_strcmp0(adv_info->addr, addr))
122 current = g_list_next(current);
127 static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
129 retv_if(!adv_info, -1);
130 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
131 __bt_free_bt_le_adv_info_t(adv_info);
134 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
139 static void __bt_del_adv_ind_info(char *addr)
142 ret_if(!p_adv_ind_list);
143 bt_le_adv_info_t *adv_info = NULL;
144 GList *current = g_list_first((GList *)p_adv_ind_list);
145 while (current && current->data) {
146 adv_info = (bt_le_adv_info_t *)current->data;
147 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
148 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
149 __bt_free_bt_le_adv_info_t(adv_info);
152 current = g_list_next(current);
156 static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
158 bt_remote_le_dev_info_t le_dev_info;
159 bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
161 memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
163 le_dev_info.address = adv_info->addr;
164 le_dev_info.addr_type = adv_info->addr_type;
165 le_dev_info.rssi = adv_info->rssi;
166 le_dev_info.adv_data = adv_info->data;
167 le_dev_info.adv_data_len = 0;
168 adv_info->timer_id = 0;
170 _bt_send_scan_result_event(&le_dev_info, adv_info);
171 __bt_del_adv_ind_info(adv_info->addr);
176 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
178 ret_if(cache_info == NULL);
179 _bt_free_device_info(cache_info->dev_info);
183 static gboolean __bt_parse_device_properties(GVariant *item,
184 bt_remote_dev_info_t *dev_info)
193 g_variant_iter_init(&iter, item);
194 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
195 if (strcasecmp(key, "Address") == 0) {
196 dev_info->address = g_variant_dup_string(val, &len);
197 } else if (strcasecmp(key, "Class") == 0) {
198 dev_info->class = g_variant_get_uint32(val);
199 } else if (strcasecmp(key, "name") == 0) {
200 if (dev_info->name == NULL)
201 dev_info->name = g_variant_dup_string(val, &len);
202 } else if (strcasecmp(key, "Connected") == 0) {
203 dev_info->connected = g_variant_get_byte(val);
204 } else if (strcasecmp(key, "paired") == 0) {
205 dev_info->paired = g_variant_get_boolean(val);
206 } else if (strcasecmp(key, "Trusted") == 0) {
207 dev_info->trust = g_variant_get_boolean(val);
208 } else if (strcasecmp(key, "RSSI") == 0) {
209 dev_info->rssi = g_variant_get_int16(val);
210 } else if (strcasecmp(key, "LastAddrType") == 0) {
211 dev_info->addr_type = g_variant_get_byte(val);
212 } else if (strcasecmp(key, "UUIDs") == 0) {
216 size = g_variant_get_size(val);
219 uuid_value = (char **)g_variant_get_strv(val, &size);
220 if (dev_info->uuids == NULL)
221 dev_info->uuids = g_malloc0(sizeof(char *) * size);
223 for (i = 0; uuid_value[i] != NULL; i++) {
224 dev_info->uuid_count++;
225 dev_info->uuids[i] = g_strdup(uuid_value[i]);
229 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
230 g_variant_get(val, "q", &dev_info->manufacturer_data_len);
231 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
232 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
233 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
236 if (dev_info->manufacturer_data_len == 0)
237 dev_info->manufacturer_data = g_strdup("");
238 } else if (strcasecmp(key, "ManufacturerData") == 0) {
241 GVariantIter *value_iter;
244 len = g_variant_get_size(val);
248 dev_info->manufacturer_data = g_malloc0(len);
250 g_variant_get(val, "ay", &value_iter);
251 while (g_variant_iter_loop(value_iter, "y", &m_value))
252 dev_info->manufacturer_data[i++] = m_value;
253 g_variant_iter_free(value_iter);
261 static gboolean __bt_parse_interface(GVariant *msg,
262 bt_remote_dev_info_t *dev_info)
265 GVariant *optional_param = NULL;
268 char *interface_name = NULL;
269 GVariant *inner_iter = NULL;
270 g_variant_get(msg, "(&o@a{sa{sv}})",
271 &path, &optional_param);
272 g_variant_iter_init(&iter, optional_param);
274 retv_if(optional_param == NULL, FALSE);
276 while ((child = g_variant_iter_next_value(&iter))) {
277 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
278 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
279 BT_DBG("Found a device: %s", path);
280 if (__bt_parse_device_properties(inner_iter,
281 dev_info) == FALSE) {
282 g_variant_unref(inner_iter);
283 g_variant_unref(child);
284 g_variant_unref(optional_param);
285 BT_ERR("Fail to parse the properies");
288 g_variant_unref(inner_iter);
289 g_variant_unref(child);
290 g_variant_unref(optional_param);
294 g_variant_unref(inner_iter);
295 g_variant_unref(child);
298 g_variant_unref(optional_param);
303 static int __bt_get_owner_info(GVariant *msg, char **name,
304 char **previous, char **current)
306 g_variant_get(msg, "(sss)", name, previous, current);
307 return BLUETOOTH_ERROR_NONE;
310 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
311 char **name, char **uuid)
313 g_variant_get(msg, "(sss)", address, name, uuid);
314 return BLUETOOTH_ERROR_NONE;
317 void __bt_set_device_values(gboolean connected, int state)
319 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
321 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
322 BT_ERR("vconf_get_int failed");
324 if (connected == TRUE)
325 bt_device_state |= state;
326 else if (bt_device_state & state)
327 bt_device_state ^= state;
329 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
330 BT_ERR("vconf_set_int failed");
333 gboolean _bt_discovery_finished_cb(gpointer user_data)
335 int result = BLUETOOTH_ERROR_NONE;
337 GVariant *param = NULL;
338 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
339 if (_bt_get_cancel_by_user() == TRUE)
340 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
342 _bt_set_cancel_by_user(FALSE);
343 _bt_set_discovery_status(FALSE);
344 param = g_variant_new("(i)", result);
345 _bt_send_event(BT_ADAPTER_EVENT,
346 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
353 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
355 int result = BLUETOOTH_ERROR_NONE;
356 le_scan_event_id = 0;
357 GVariant *param = NULL;
358 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
359 if (_bt_get_cancel_by_user() == TRUE)
360 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
362 g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
363 p_adv_ind_list = NULL;
365 _bt_set_cancel_by_user(FALSE);
366 _bt_disable_all_scanner_status();
367 _bt_set_le_scan_status(FALSE);
368 param = g_variant_new("(i)", result);
369 _bt_send_event(BT_LE_ADAPTER_EVENT,
370 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
377 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
381 ret_if(address == NULL);
384 bt_cache_info_t *cache_info;
385 bt_remote_dev_info_t *dev_info;
387 node = g_list_first(p_cache_list);
389 while (node != NULL) {
390 cache_info = (bt_cache_info_t *)node->data;
392 if (cache_info == NULL) {
393 node = g_list_next(node);
397 dev_info = cache_info->dev_info;
398 if (strcasecmp(dev_info->address,
400 BT_DBG("Device Found");
401 if (paired_status == TRUE)
402 cache_info->dev_info->paired = TRUE;
404 cache_info->dev_info->paired = FALSE;
407 node = g_list_next(node);
412 static void __bt_device_remote_connected_properties(
413 bt_remote_dev_info_t *remote_dev_info,
414 char *address, gboolean connected)
416 int result = BLUETOOTH_ERROR_NONE;
418 GVariant *param = NULL;
421 if (remote_dev_info->uuid_count > 0) {
422 for (i = 0; i < remote_dev_info->uuid_count; i++) {
423 char *uuid = remote_dev_info->uuids[i];
424 if (strcasecmp(uuid, HID_UUID) == 0) {
425 int event = BLUETOOTH_EVENT_NONE;
427 event = (connected == TRUE) ?
428 BLUETOOTH_HID_CONNECTED :
429 BLUETOOTH_HID_DISCONNECTED;
430 param = g_variant_new("(is)", result,
432 _bt_send_event(BT_HID_EVENT, event,
442 gboolean __bt_handle_is_flight_mode_enabled(void)
444 int is_flight_mode = 0;
447 if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
448 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
450 BT_ERR("vconf_get_bool failed");
452 return (is_flight_mode == 0) ? FALSE : TRUE;
458 void _bt_handle_adapter_event(GVariant *msg, const char *member)
462 int result = BLUETOOTH_ERROR_NONE;
463 GVariant *param = NULL;
464 ret_if(member == NULL);
466 if (strcasecmp(member, "DeviceCreated") == 0) {
467 char *object_path = NULL;
469 bt_remote_dev_info_t *remote_dev_info;
471 ret_if(_bt_is_device_creating() == FALSE);
473 /* Bonding from remote device */
474 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
476 g_variant_get(msg, "(&o)", &object_path);
477 _bt_convert_device_path_to_address((const char*)object_path, address);
479 remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
480 if (remote_dev_info == NULL) {
485 _bt_free_device_info(remote_dev_info);
487 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
488 char *object_path = NULL;
490 bt_cache_info_t *cache_info;
491 bt_remote_dev_info_t *dev_info;
494 /* Bonding from remote device */
495 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
497 g_variant_get(msg, "(&o)", &object_path);
499 _bt_convert_device_path_to_address((const char *)object_path, address);
501 node = g_list_first(p_cache_list);
503 while (node != NULL) {
504 cache_info = (bt_cache_info_t *)node->data;
506 if (cache_info == NULL) {
507 node = g_list_next(node);
511 dev_info = cache_info->dev_info;
512 if (strcasecmp(dev_info->address,
514 p_cache_list = g_list_remove(p_cache_list,
516 __bt_free_cache_info(cache_info);
519 node = g_list_next(node);
522 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
523 BT_DBG("Advertising Enabled");
527 gboolean status = FALSE;
529 g_variant_get(msg, "(ib)", &slot_id, &status);
531 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
533 /* Send event to application */
534 _bt_set_advertising_status(slot_id, status);
536 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
539 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
541 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
542 param = g_variant_new("(ii)", result,
546 sender = _bt_get_adv_slot_owner(slot_id);
547 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
551 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) {
552 char *name = g_strdup(sender);
554 _bt_unregister_adv_slot_owner(slot_id);
556 /* Advertising disabled, notify TDS */
557 _bt_tds_handle_adv_disabled(name, adv_handle);
560 } else if (strcasecmp(member, "RssiEnabled") == 0) {
561 BT_DBG("RSSI Enabled");
562 gboolean status = FALSE;
563 char *address = NULL;
565 g_variant_get(msg, "(sib)", &address, &link_type, &status);
567 BT_DBG("RSSI Enabled [%s %d]", address, status);
568 param = g_variant_new("(isib)", result,
569 address, link_type, status);
570 _bt_send_event(BT_DEVICE_EVENT,
571 BLUETOOTH_EVENT_RSSI_ENABLED,
574 } else if (strcasecmp(member, "RssiAlert") == 0) {
575 BT_DBG("RSSI Alert");
579 char *address = NULL;
580 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
582 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
583 address, alert_type, rssi_dbm);
584 param = g_variant_new("(isiii)", result,
585 address, link_type, alert_type, rssi_dbm);
586 _bt_send_event(BT_DEVICE_EVENT,
587 BLUETOOTH_EVENT_RSSI_ALERT,
590 } else if (strcasecmp(member, "RawRssi") == 0) {
594 char *address = NULL;
595 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
597 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
598 address, link_type, rssi_dbm);
599 param = g_variant_new("(isii)", result,
600 address, link_type, rssi_dbm);
601 _bt_send_event(BT_DEVICE_EVENT,
602 BLUETOOTH_EVENT_RAW_RSSI,
605 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
606 BT_ERR_C("### Hardware error received from BLUEZ");
607 /* Don't add the recovery logic into platform */
609 _bt_recover_adapter();
611 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
612 BT_ERR_C("### Tx timeout error received from BLUEZ");
613 /* Don't add the recovery logic into platform */
615 _bt_recover_adapter();
621 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
623 GDBusProxy *adapter_proxy;
625 int result = BLUETOOTH_ERROR_NONE;
626 GVariantIter value_iter;
627 GVariant *val = NULL;
628 GVariant *ret = NULL;
630 char *property = NULL;
631 GVariant *param = NULL;
632 g_variant_iter_init(&value_iter, msg);
633 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
634 BT_INFO("Property %s", property);
636 if (strcasecmp(property, "Discovering") == 0) {
637 gboolean discovering = FALSE;
638 g_variant_get(val, "b", &discovering);
639 /* Send event to application */
640 BT_DBG("Discovering %d", discovering);
641 if (discovering == TRUE) {
642 _bt_set_discovery_status(TRUE);
643 param = g_variant_new("(i)", result);
644 _bt_send_event(BT_ADAPTER_EVENT,
645 BLUETOOTH_EVENT_DISCOVERY_STARTED,
648 ret_if(event_id > 0);
650 adapter_proxy = _bt_get_adapter_proxy();
651 ret_if(adapter_proxy == NULL);
653 /* Need to stop searching */
654 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
656 G_DBUS_CALL_FLAGS_NONE,
660 BT_ERR("Dbus Error : %s", err->message);
664 g_variant_unref(ret);
666 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
667 (GSourceFunc)_bt_discovery_finished_cb, NULL);
669 } else if (strcasecmp(property, "LEDiscovering") == 0) {
670 gboolean le_discovering = FALSE;
672 g_variant_get(val, "b", &le_discovering);
673 /* Send event to application */
674 if (le_discovering == TRUE) {
675 _bt_set_le_scan_status(TRUE);
676 param = g_variant_new("(i)", result);
677 _bt_send_event(BT_LE_ADAPTER_EVENT,
678 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
681 ret_if(le_scan_event_id > 0);
683 adapter_proxy = _bt_get_adapter_proxy();
684 ret_if(adapter_proxy == NULL);
686 /* Need to stop searching */
687 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
689 G_DBUS_CALL_FLAGS_NONE,
693 BT_ERR("Dbus Error %s", err->message);
697 g_variant_unref(ret);
699 le_scan_event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
700 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
702 } else if (strcasecmp(property, "Name") == 0) {
704 g_variant_get(val, "s", &name);
705 param = g_variant_new("(is)", result, name);
706 /* Send event to application */
707 _bt_send_event(BT_ADAPTER_EVENT,
708 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
711 } else if (strcasecmp(property, "Alias") == 0) {
713 g_variant_get(val, "s", &alias);
714 param = g_variant_new("(is)", result, alias);
715 /* Send event to application */
716 _bt_send_event(BT_ADAPTER_EVENT,
717 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
720 } else if (strcasecmp(property, "Discoverable") == 0) {
721 gboolean discoverable = FALSE;
723 g_variant_get(val, "b", &discoverable);
724 BT_DBG("discoverable %d", discoverable);
726 if (discoverable == FALSE) {
727 if (_bt_get_discoverable_timeout_property() > 0) {
729 adapter_proxy = _bt_get_adapter_properties_proxy();
730 ret_if(adapter_proxy == NULL);
731 ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
732 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
733 "DiscoverableTimeout",
734 g_variant_new("i", time)),
735 G_DBUS_CALL_FLAGS_NONE,
740 BT_ERR("StopLEDiscovery Failed: %s", err->message);
744 g_variant_unref(ret);
747 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
749 /* Send event to application */
750 BT_INFO("[Connectable]");
751 param = g_variant_new("(in)", result, mode);
752 _bt_send_event(BT_ADAPTER_EVENT,
753 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
756 _bt_get_discoverable_mode(&mode);
758 /* Event will be sent by "DiscoverableTimeout" signal */
759 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
761 g_variant_unref(val);
765 /* Send event to application */
766 BT_INFO("[General Discoverable]");
767 param = g_variant_new("(in)", result, mode);
768 _bt_send_event(BT_ADAPTER_EVENT,
769 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
772 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
773 _bt_get_discoverable_mode(&mode);
775 /* Event was already sent by "Discoverable" signal */
776 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
777 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
779 g_variant_unref(val);
783 /* Send event to application */
784 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
785 _bt_get_discoverable_timeout_property());
786 param = g_variant_new("(in)", result, mode);
787 _bt_send_event(BT_ADAPTER_EVENT,
788 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
790 } else if (strcasecmp(property, "Powered") == 0) {
791 /* TODO: Need to check this operation!! */
792 gboolean powered = FALSE;
795 g_variant_get(val, "b", &powered);
796 BT_DBG("Powered = %d", powered);
797 if (powered == FALSE) {
798 if (TIZEN_FEATURE_BT_USB_DONGLE) {
799 _bt_handle_adapter_removed();
801 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
802 bt_state != VCONFKEY_BT_STATUS_OFF) {
803 if (__bt_handle_is_flight_mode_enabled() == FALSE)
804 _bt_disable_adapter();
806 _bt_handle_adapter_removed();
809 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
810 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
811 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
814 if (TIZEN_FEATURE_BT_USB_DONGLE)
815 _bt_handle_adapter_added();
817 } else if (strcasecmp(property, "Connectable") == 0) {
818 gboolean connectable = FALSE;
820 g_variant_get(val, "b", &connectable);
822 BT_DBG("Connectable property is changed : %d", connectable);
823 param = g_variant_new("(b)", connectable);
824 _bt_send_event(BT_ADAPTER_EVENT,
825 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
828 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
829 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
831 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
833 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
836 GVariantIter *iter = NULL;
837 g_variant_get(val, "as", &iter);
839 ret_if(iter == NULL);
841 while (g_variant_iter_loop(iter, "s", &name)) {
842 BT_DBG("name = %s", name);
843 g_variant_iter_loop(iter, "s", &value);
844 BT_DBG("Value = %s", value);
845 if (FALSE == _bt_update_le_feature_support(name, value))
846 BT_INFO("Fail to update LE feature info");
849 g_variant_iter_free(iter);
850 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
851 gboolean ipsp_initialized = FALSE;
853 g_variant_get(val, "b", &ipsp_initialized);
854 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
855 param = g_variant_new("(b)", ipsp_initialized);
857 /* Send event to application */
858 _bt_send_event(BT_ADAPTER_EVENT,
859 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
862 BT_DBG("property : [%s]", property);
867 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
871 GVariantIter value_iter;
872 GVariant *child = NULL, *val = NULL;
873 char *property = NULL;
874 g_variant_iter_init(&value_iter, msg);
875 while ((child = g_variant_iter_next_value(&value_iter))) {
876 g_variant_get(child, "{sv}", &property, &val);
878 ret_if(property == NULL);
880 BT_DBG("property :%s", property);
882 if (strcasecmp(property, "Status") == 0) {
884 g_variant_get(val, "s", &status);
886 if (strcasecmp(status, "active") == 0) {
887 _bt_obex_transfer_started(path);
888 } else if (strcasecmp(status, "complete") == 0) {
889 _bt_obex_transfer_completed(path, TRUE);
890 _bt_pbap_obex_transfer_completed(path, TRUE);
891 } else if (strcasecmp(status, "error") == 0) {
892 _bt_obex_transfer_completed(path, FALSE);
893 _bt_pbap_obex_transfer_completed(path, FALSE);
896 } else if (strcasecmp(property, "Transferred") == 0) {
897 guint64 transferred = 0;
898 /* As Transferred is expected guint64 so change int to guint64 and
899 * eariler transferred is static because of it can overwrite data
900 * on present on opc_obex_conn or obexd_conn as these are
901 * static memory are in sequential */
902 g_variant_get(val, "t", &transferred);
904 _bt_obex_transfer_progress(path, transferred);
906 /* TODO: MAP, "Complete"? see above */
908 g_variant_unref(val);
909 g_variant_unref(child);
914 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
919 int result = BLUETOOTH_ERROR_NONE;
920 GVariantIter value_iter;
922 char *property = NULL;
924 GVariant *param = NULL;
925 bt_remote_dev_info_t *remote_dev_info;
926 g_variant_iter_init(&value_iter, msg);
927 #ifdef TIZEN_FEATURE_BT_DPM
928 int desktop_state = DPM_BT_ERROR;
930 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
931 BT_DBG("Property %s", property);
932 if (strcasecmp(property, "Connected") == 0) {
935 g_variant_get(val, "i", &connected);
937 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
938 BLUETOOTH_EVENT_DEVICE_CONNECTED :
939 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
941 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
943 _bt_convert_device_path_to_address(path, address);
945 BT_DBG("connected: %d", connected);
946 BT_DBG("address: %s", address);
948 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
950 if (remote_dev_info != NULL) {
951 __bt_device_remote_connected_properties(
952 remote_dev_info, address,
953 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
955 _bt_free_device_info(remote_dev_info);
957 param = g_variant_new("(is)", result, address);
958 /* Send event to application */
959 _bt_send_event(BT_DEVICE_EVENT,
963 } else if (strcasecmp(property, "RSSI") == 0) {
964 bt_remote_dev_info_t *remote_dev_info;
966 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
968 _bt_convert_device_path_to_address(path, address);
969 BT_DBG("address: %s", address);
973 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
974 if (remote_dev_info == NULL) {
976 g_variant_unref(val);
979 BT_DBG("Address type %d", remote_dev_info->addr_type);
981 if (remote_dev_info->addr_type == 0) {
982 BT_DBG("Name %s", remote_dev_info->name);
984 #ifdef TIZEN_FEATURE_BT_DPM
985 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
986 if (desktop_state == DPM_RESTRICTED) {
987 bluetooth_device_class_t device_class;
988 _bt_divide_device_class(&device_class, remote_dev_info->class);
990 if (device_class.major_class ==
991 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
992 _bt_free_device_info(remote_dev_info);
994 g_variant_unref(val);
1000 GVariant *uuids = NULL;
1001 GVariantBuilder *builder = NULL;
1003 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1004 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1005 g_variant_builder_add(builder, "s",
1006 remote_dev_info->uuids[i]);
1008 uuids = g_variant_new("as", builder);
1009 g_variant_builder_unref(builder);
1010 GVariant *manufacturer_data = NULL;
1011 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1012 remote_dev_info->manufacturer_data,
1013 remote_dev_info->manufacturer_data_len,
1016 param = g_variant_new("(isunsbub@asn@ay)", result,
1017 remote_dev_info->address,
1018 remote_dev_info->class,
1019 remote_dev_info->rssi,
1020 remote_dev_info->name,
1021 remote_dev_info->paired,
1022 remote_dev_info->connected,
1023 remote_dev_info->trust,
1025 remote_dev_info->manufacturer_data_len,
1028 _bt_send_event(BT_ADAPTER_EVENT,
1029 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1032 _bt_free_device_info(remote_dev_info);
1033 } else if (strcasecmp(property, "GattConnected") == 0) {
1034 gboolean gatt_connected = FALSE;
1036 g_variant_get(val, "b", &gatt_connected);
1038 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1039 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1041 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1043 _bt_convert_device_path_to_address(path, address);
1045 BT_DBG("gatt_connected: %d", gatt_connected);
1046 BT_DBG("address: %s", address);
1047 param = g_variant_new("(is)", result, address);
1048 /* Send event to application */
1049 _bt_send_event(BT_DEVICE_EVENT,
1053 } else if (strcasecmp(property, "Paired") == 0) {
1054 gboolean paired = FALSE;
1055 bt_remote_dev_info_t *remote_dev_info;
1056 g_variant_get(val, "b", &paired);
1057 _bt_agent_set_canceled(FALSE);
1058 /* BlueZ sends paired signal for each paired device */
1059 /* during activation, We should ignore this, otherwise*/
1060 /* application thinks that a new device got paired */
1061 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1062 BT_DBG("BT is not activated, so ignore this");
1064 g_variant_unref(val);
1068 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1070 _bt_convert_device_path_to_address(path, address);
1072 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1073 if (remote_dev_info == NULL) {
1075 g_variant_unref(val);
1080 if (paired == FALSE) {
1081 BT_INFO("Unpaired: %s", address);
1082 __bt_update_remote_cache_devinfo(address, FALSE);
1083 param = g_variant_new("(is)", result, address);
1084 _bt_send_event(BT_ADAPTER_EVENT,
1085 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1087 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1089 char *last_connected = NULL;
1090 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1091 if (!g_strcmp0(address, last_connected))
1092 _bt_audio_set_auto_connect_device_addr("");
1094 free(last_connected);
1098 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1100 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1101 BT_INFO("### Paired: %s", secure_addr);
1102 __bt_update_remote_cache_devinfo(address, TRUE);
1104 if (_bt_is_device_creating() == TRUE) {
1105 BT_DBG("Try to Pair by me");
1106 _bt_free_device_info(remote_dev_info);
1109 g_variant_unref(val);
1112 GVariant *uuids = NULL;
1113 GVariantBuilder *builder = NULL;
1115 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1116 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1117 g_variant_builder_add(builder, "s",
1118 remote_dev_info->uuids[i]);
1120 uuids = g_variant_new("as", builder);
1121 g_variant_builder_unref(builder);
1122 GVariant *manufacturer_data = NULL;
1123 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1124 remote_dev_info->manufacturer_data,
1125 remote_dev_info->manufacturer_data_len,
1129 param = g_variant_new("(isunsbub@asn@ay)", result,
1130 address, remote_dev_info->class,
1131 remote_dev_info->rssi,
1132 remote_dev_info->name,
1133 remote_dev_info->paired,
1134 remote_dev_info->connected,
1135 remote_dev_info->trust,
1137 remote_dev_info->manufacturer_data_len,
1139 _bt_send_event(BT_ADAPTER_EVENT,
1140 BLUETOOTH_EVENT_BONDING_FINISHED,
1143 _bt_free_device_info(remote_dev_info);
1145 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1146 gboolean paired = FALSE;
1147 bt_remote_dev_info_t *remote_dev_info;
1148 unsigned char auth_info[5] = {0, };
1150 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1151 BT_DBG("BT is not activated, so ignore this");
1153 g_variant_unref(val);
1157 g_variant_get(val, "b", &paired);
1158 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1159 BT_DBG("LegacyPaired: %d", paired);
1160 _bt_convert_device_path_to_address(path, address);
1162 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1163 if (remote_dev_info == NULL) {
1166 g_variant_unref(val);
1169 if (remote_dev_info->is_alias_set == FALSE) {
1170 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1171 if ((remote_dev_info->manufacturer_data_len > 30) &&
1172 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1173 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1175 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1176 1 (discovery version) + 1 (associated service ID)
1177 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1179 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1183 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1184 if (headed_plugin_info->plugin_headed_enabled)
1185 headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1186 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1188 _bt_free_device_info(remote_dev_info);
1190 } else if (strcasecmp(property, "Trusted") == 0) {
1191 gboolean trusted = FALSE;
1193 g_variant_get(val, "b", &trusted);
1195 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1196 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1198 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1200 _bt_convert_device_path_to_address(path, address);
1202 BT_DBG("trusted: %d", trusted);
1203 BT_DBG("address: %s", address);
1204 param = g_variant_new("(is)", result, address);
1205 /* Send event to application */
1206 _bt_send_event(BT_DEVICE_EVENT,
1210 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1213 g_variant_get(val, "u", &trusted);
1215 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1216 _bt_convert_device_path_to_address(path, address);
1218 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1219 _bt_send_event(BT_DEVICE_EVENT,
1220 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1221 g_variant_new("(isi)", result, address, trusted));
1223 } else if (strcasecmp(property, "IpspConnected") == 0) {
1224 gboolean connected = FALSE;
1226 g_variant_get(val, "b", &connected);
1229 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1230 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1232 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1234 _bt_convert_device_path_to_address(path, address);
1236 BT_DBG("Ipspconnected: %d", connected);
1237 BT_DBG("address: %s", address);
1238 param = g_variant_new("(is)", result, address);
1240 /* Send event to application */
1241 _bt_send_event(BT_DEVICE_EVENT,
1245 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1246 char *ifname = NULL;
1248 g_variant_get(val, "s", &ifname);
1250 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1252 _bt_convert_device_path_to_address(path, address);
1254 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1255 BT_DBG("address: %s", address);
1256 param = g_variant_new("(iss)", result, address, ifname);
1258 /* Send event to application */
1259 _bt_send_event(BT_DEVICE_EVENT,
1260 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1268 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1271 int result = BLUETOOTH_ERROR_NONE;
1272 GVariantIter value_iter;
1273 char *property = NULL;
1275 GVariant *val = NULL;
1276 GVariant *child = NULL;
1277 bt_remote_dev_info_t *remote_dev_info;
1278 GVariant *param = NULL;
1279 g_variant_iter_init(&value_iter, msg);
1280 while ((child = g_variant_iter_next_value(&value_iter))) {
1281 g_variant_get(child, "{sv}", &property, &val);
1282 BT_INFO("Property %s", property);
1283 if (strcasecmp(property, "Connected") == 0) {
1284 gboolean connected = FALSE;
1286 g_variant_get(val, "b", &connected);
1288 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1289 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1291 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1293 _bt_convert_device_path_to_address(path, address);
1295 BT_DBG("connected: %d", connected);
1296 BT_DBG("address: %s", address);
1298 remote_dev_info = _bt_get_remote_device_info(address);
1300 if (remote_dev_info != NULL) {
1301 __bt_device_remote_connected_properties(
1302 remote_dev_info, address, connected);
1303 _bt_free_device_info(remote_dev_info);
1305 param = g_variant_new("(is)", result, address);
1306 /* Send event to application */
1307 _bt_send_event(BT_AVRCP_EVENT,
1313 g_variant_unref(child);
1314 g_variant_unref(val);
1319 int get_alert_level_enum(const char *alert)
1323 if (strcmp(alert, "none") == 0)
1324 lvl = BT_PXP_ALERT_NONE;
1325 else if (strcmp(alert, "mild") == 0)
1326 lvl = BT_PXP_ALERT_MILD;
1327 else if (strcmp(alert, "high") == 0)
1328 lvl = BT_PXP_ALERT_HIGH;
1333 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1335 int result = BLUETOOTH_ERROR_NONE;
1338 GVariantIter value_iter;
1339 char *property = NULL;
1341 GVariant *val = NULL;
1342 GVariant *child = NULL;
1343 GVariant *param = NULL;
1344 g_variant_iter_init(&value_iter, msg);
1347 while ((child = g_variant_iter_next_value(&value_iter))) {
1348 g_variant_get(child, "{sv}", &property, &val);
1349 BT_INFO("Property %s", property);
1351 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1352 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1353 char *alert_str = NULL;
1355 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1356 _bt_convert_device_path_to_address(path, address);
1358 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1359 service_type = BT_PXP_PROPERTY_LLS;
1361 service_type = BT_PXP_PROPERTY_IAS;
1363 g_variant_get(val, "s", &alert_str);
1365 alert_lvl = get_alert_level_enum(alert_str);
1367 param = g_variant_new("(isiii)", result, address,
1368 role, service_type, alert_lvl);
1370 /* Send event to application */
1371 _bt_send_event(BT_DEVICE_EVENT,
1372 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1378 g_variant_unref(child);
1379 g_variant_unref(val);
1384 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1386 char *interface_name = NULL;
1387 GVariant *val = NULL;
1389 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1391 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1392 __bt_adapter_property_changed_event(val,
1394 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1395 __bt_device_property_changed_event(val, object_path);
1396 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1397 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1398 __bt_obex_property_changed_event(val,
1400 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1401 __bt_media_control_changed_event(val,
1403 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1404 _bt_handle_avrcp_control_event(val,
1406 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1407 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1408 _bt_handle_network_client_event(val,
1410 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1411 __bt_gatt_char_property_changed_event(val,
1413 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1414 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1415 _bt_handle_pxp_property_changed_event(val,
1416 object_path, BT_PXP_REPORTER_ROLE);
1418 g_variant_unref(val);
1421 void __bt_opc_property_changed_event(GVariant *msg,
1424 GVariantIter value_iter;
1425 char *property = NULL;
1426 GVariant *val = NULL;
1427 GVariant *child = NULL;
1429 g_variant_iter_init(&value_iter, msg);
1430 if ((child = g_variant_iter_next_value(&value_iter))) {
1431 g_variant_get(child, "{sv}", &property, &val);
1432 ret_if(property == NULL);
1434 if (strcasecmp(property, "Status") == 0) {
1435 char *status = NULL;
1436 g_variant_get(val, "s", &status);
1437 BT_DBG("Status is %s", status);
1439 if (strcasecmp(status, "active") == 0)
1440 _bt_obex_client_started(path);
1441 else if (strcasecmp(status, "complete") == 0)
1442 _bt_obex_client_completed(path, TRUE);
1443 else if (strcasecmp(status, "error") == 0)
1444 _bt_obex_client_completed(path, FALSE);
1447 } else if (strcasecmp(property, "Transferred") == 0) {
1448 guint64 transferred = 0;
1449 g_variant_get(val, "t", &transferred);
1451 _bt_obex_client_progress(path, transferred);
1453 BT_DBG("property : [%s]", property);
1456 g_variant_unref(child);
1457 g_variant_unref(val);
1461 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1463 char *interface_name = NULL;
1464 GVariant *value = NULL;
1465 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1466 BT_INFO("interface_name = %s", interface_name);
1467 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1468 __bt_opc_property_changed_event(value,
1471 BT_DBG("interface_name : [%s]", interface_name);
1473 g_variant_unref(value);
1477 void __bt_map_property_changed_event(GVariant *msg,
1481 GVariantIter value_iter;
1482 char *property = NULL;
1483 GVariant *val = NULL;
1484 GVariant *child = NULL;
1486 g_variant_iter_init(&value_iter, msg);
1487 while ((child = g_variant_iter_next_value(&value_iter))) {
1488 g_variant_get(child, "{sv}", &property, &val);
1489 ret_if(property == NULL);
1491 if (strcasecmp(property, "Status") == 0) {
1492 char *status = NULL;
1493 g_variant_get(val, "s", &status);
1494 BT_DBG("Status is %s", status);
1496 if (strcasecmp(status, "active") == 0) {
1497 BT_DBG("EVENT : STARTED");
1498 // currently doing nothing
1499 } else if (strcasecmp(status, "complete") == 0) {
1500 BT_DBG("EVENT : COMPLETED");
1501 _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_NONE);
1502 } else if (strcasecmp(status, "error") == 0) {
1503 BT_DBG("EVENT : FAILED");
1504 _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_INTERNAL);
1507 } else if (strcasecmp(property, "Transferred") == 0) {
1508 guint64 transferred = 0;
1509 g_variant_get(val, "t", &transferred);
1511 BT_DBG("EVENT : PROGRESS CALLBACK");
1512 // currently doing nothing - progress callback type is not used
1514 BT_DBG("OTHER EVENT : property : [%s]", property);
1517 g_variant_unref(child);
1518 g_variant_unref(val);
1522 void _bt_map_property_changed_event(GVariant *msg, const char *path)
1524 BT_DBG("Entered _bt_map_property_changed_event");
1525 char *interface_name = NULL;
1526 GVariant *value = NULL;
1527 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1528 BT_INFO("interface_name = %s", interface_name);
1529 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1530 __bt_map_property_changed_event(value,
1533 BT_DBG("interface_name : [%s]", interface_name);
1535 g_variant_unref(value);
1539 void _bt_handle_input_event(GVariant *msg, const char *path)
1541 int result = BLUETOOTH_ERROR_NONE;
1542 gboolean property_flag = FALSE;
1543 GVariantIter value_iter;
1544 char *property = NULL;
1545 GVariant *child = NULL, *val = NULL;
1546 bt_remote_dev_info_t *remote_dev_info;
1547 GVariant *param = NULL;
1548 g_variant_iter_init(&value_iter, msg);
1549 while ((child = g_variant_iter_next_value(&value_iter))) {
1550 g_variant_get(child, "{sv}", &property, &val);
1552 ret_if(property == NULL);
1554 if (strcasecmp(property, "Connected") == 0) {
1555 int event = BLUETOOTH_EVENT_NONE;
1557 g_variant_get(val, "b", &property_flag);
1559 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1561 _bt_convert_device_path_to_address(path, address);
1563 event = (property_flag == TRUE) ?
1564 BLUETOOTH_HID_CONNECTED :
1565 BLUETOOTH_HID_DISCONNECTED;
1566 param = g_variant_new("(is)", result, address);
1567 _bt_send_event(BT_HID_EVENT, event,
1569 /* Check HID connection type (Keyboard or Mouse) and update the status */
1570 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1572 if (property_flag == TRUE) {
1573 hid_connected_device_count++;
1574 __bt_set_device_values(TRUE,
1575 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1577 hid_connected_device_count--;
1578 if (hid_connected_device_count == 0)
1579 __bt_set_device_values(FALSE,
1580 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1583 if (remote_dev_info != NULL) {
1584 BT_DBG("HID device class [%x]", remote_dev_info->class);
1585 if (remote_dev_info->class &
1586 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1587 __bt_set_device_values(property_flag,
1588 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1592 if (remote_dev_info->class &
1593 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1594 __bt_set_device_values(property_flag,
1595 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1597 _bt_free_device_info(remote_dev_info);
1602 g_variant_unref(val);
1603 g_variant_unref(child);
1607 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1609 int result = BLUETOOTH_ERROR_NONE;
1610 char *address = NULL;
1611 char *device = NULL;
1612 GVariant *param = NULL;
1613 ret_if(member == NULL);
1614 if (strcasecmp(member, "PeerConnected") == 0) {
1615 g_variant_get(msg, "(ss)", &device, &address);
1617 __bt_set_device_values(TRUE,
1618 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1619 param = g_variant_new("(iss)", result, device, address);
1620 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1624 nap_connected_device_count++;
1625 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1626 g_variant_get(msg, "(ss)", &device, &address);
1627 nap_connected_device_count--;
1628 if (nap_connected_device_count == 0)
1629 __bt_set_device_values(FALSE,
1630 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1631 param = g_variant_new("(iss)", result, device, address);
1632 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1639 void _bt_handle_network_client_event(GVariant *msg,
1644 int result = BLUETOOTH_ERROR_NONE;
1645 gboolean property_flag = FALSE;
1646 char *property = NULL;
1647 GVariant *val = NULL;
1648 GVariantIter value_iter;
1649 GVariant *param = NULL;
1650 g_variant_iter_init(&value_iter, msg);
1651 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1652 if (strcasecmp(property, "Connected") == 0) {
1653 int event = BLUETOOTH_EVENT_NONE;
1656 g_variant_get(val, "b", &property_flag);
1657 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1659 _bt_convert_device_path_to_address(path, address);
1661 BT_DBG("property_flag %d", property_flag);
1662 if (property_flag == TRUE) {
1663 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1664 nap_connected_device_count++;
1665 __bt_set_device_values(TRUE,
1666 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1668 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1669 nap_connected_device_count--;
1670 if (nap_connected_device_count == 0)
1671 __bt_set_device_values(FALSE,
1672 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1674 param = g_variant_new("(is)", result, address);
1675 _bt_send_event(BT_NETWORK_EVENT, event,
1684 void __bt_gatt_char_property_changed_event(GVariant *msg,
1687 GVariantIter value_iter;
1688 char *property = NULL;
1689 GVariant *val = NULL;
1690 g_variant_iter_init(&value_iter, msg);
1691 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1692 BT_INFO("Property %s", property);
1694 ret_if(property == NULL);
1696 if (strcasecmp(property, "Notifying") == 0) {
1697 gboolean property_flag = FALSE;
1698 g_variant_get(val, "b", &property_flag);
1699 if (property_flag == TRUE)
1700 BT_DBG("notifying is enabled");
1702 BT_DBG("notifying is disabled");
1707 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1709 ret_if(path == NULL);
1710 if (strcasecmp(member, "GattValueChanged") == 0) {
1711 /* Check TDS seekers waiting for Indication */
1712 _bt_tds_check_indication(path, msg);
1713 #ifdef TIZEN_FEATURE_BT_OTP
1714 _bt_otp_check_indication(path, msg);
1717 BT_INFO("Unhandled event");
1721 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1724 int result = BLUETOOTH_ERROR_NONE;
1726 char *dev_name = NULL;
1727 const char *property = NULL;
1728 GVariant *param = NULL;
1729 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1730 ret_if(path == NULL);
1732 if (strcasecmp(member, "PropertyChanged") == 0) {
1734 g_variant_get(msg, "(s)", &property);
1736 ret_if(property == NULL);
1738 if (strcasecmp(property, "GattConnected") == 0) {
1739 gboolean connected = FALSE;
1741 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1743 _bt_convert_device_path_to_address(path, address);
1744 g_variant_get(msg, "(b)", &connected);
1746 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1747 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1748 param = g_variant_new("(is)", result, address);
1749 _bt_send_event(BT_DEVICE_EVENT,
1753 } else if (strcasecmp(property, "Paired") == 0) {
1754 gboolean paired = FALSE;
1755 bt_remote_dev_info_t *remote_dev_info;
1756 g_variant_get(msg, "(b)", &paired);
1758 ret_if(paired == FALSE);
1760 /* BlueZ sends paired signal for each paired device */
1761 /* during activation, We should ignore this, otherwise*/
1762 /* application thinks that a new device got paired */
1763 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1764 BT_DBG("BT is not activated, so ignore this");
1768 if (_bt_is_device_creating() == TRUE) {
1769 BT_DBG("Try to Pair by me");
1773 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1775 _bt_convert_device_path_to_address(path, address);
1777 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1778 if (remote_dev_info == NULL) {
1782 GVariant *uuids = NULL;
1783 GVariantBuilder *builder = NULL;
1785 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1786 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1787 g_variant_builder_add(builder, "s",
1788 remote_dev_info->uuids[i]);
1790 uuids = g_variant_new("as", builder);
1791 g_variant_builder_unref(builder);
1792 GVariant *manufacturer_data = NULL;
1793 manufacturer_data = g_variant_new_from_data(
1794 G_VARIANT_TYPE_BYTESTRING,
1795 remote_dev_info->manufacturer_data,
1796 remote_dev_info->manufacturer_data_len,
1798 param = g_variant_new("(isunsbub@asn@ay)", result,
1800 remote_dev_info->class,
1801 remote_dev_info->rssi,
1802 remote_dev_info->name,
1803 remote_dev_info->paired,
1804 remote_dev_info->connected,
1805 remote_dev_info->trust,
1807 remote_dev_info->manufacturer_data_len,
1809 _bt_send_event(BT_ADAPTER_EVENT,
1810 BLUETOOTH_EVENT_BONDING_FINISHED,
1812 _bt_free_device_info(remote_dev_info);
1815 } else if (strcasecmp(property, "UUIDs") == 0) {
1816 /* Once we get the updated uuid information after
1817 * reverse service search, update it to application */
1819 bt_remote_dev_info_t *remote_dev_info;
1821 ret_if(_bt_is_device_creating() == TRUE);
1823 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1825 _bt_convert_device_path_to_address(path, address);
1827 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1828 if (remote_dev_info == NULL) {
1833 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1834 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1835 GVariant *uuids = NULL;
1836 GVariantBuilder *builder = NULL;
1838 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1839 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1840 g_variant_builder_add(builder, "s",
1841 remote_dev_info->uuids[i]);
1843 uuids = g_variant_new("as", builder);
1844 g_variant_builder_unref(builder);
1845 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1846 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1849 param = g_variant_new("(isunsbub@asn@ay)", result,
1850 address, remote_dev_info->class,
1851 remote_dev_info->rssi,
1852 remote_dev_info->name,
1853 remote_dev_info->paired,
1854 remote_dev_info->connected,
1855 remote_dev_info->trust,
1857 remote_dev_info->manufacturer_data_len,
1859 _bt_send_event(BT_ADAPTER_EVENT,
1860 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1864 _bt_free_device_info(remote_dev_info);
1867 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1868 unsigned char addr_type = 0;
1870 g_variant_get(msg, "(y)", &addr_type);
1872 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1874 _bt_convert_device_path_to_address(path, address);
1875 dev_name = _bt_get_bonded_device_name(address);
1877 _bt_convert_addr_string_to_secure_string(secure_address, address);
1878 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1879 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1880 !addr_type ? dev_name : secure_address);
1883 _bt_logging_connection(TRUE, addr_type);
1884 param = g_variant_new("(isy)", result, address, addr_type);
1885 /*Send event to application*/
1886 _bt_send_event(BT_DEVICE_EVENT,
1887 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1890 } else if (strcasecmp(member, "Disconnected") == 0) {
1891 unsigned char disc_reason = 0;
1892 unsigned char addr_type = 0;
1893 char *dev_name = NULL;
1894 gboolean sending = FALSE;
1896 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1898 result = disc_reason;
1900 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1902 _bt_convert_device_path_to_address(path, address);
1904 /* 0x00 BDADDR_BRDER
1905 0x01 BDADDR_LE_PUBLIC
1906 0x02 BDADDR_LE_RANDOM */
1907 _bt_convert_addr_string_to_secure_string(secure_address, address);
1908 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1909 BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1910 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1911 !addr_type ? dev_name : secure_address);
1914 _bt_headset_set_local_connection(FALSE);
1915 _bt_logging_connection(FALSE, addr_type);
1918 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1920 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1922 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1923 BT_ERR("vconf_get_int failed");
1925 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1926 bt_device_state, _bt_adapter_get_status());
1928 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1929 _bt_audio_start_auto_connect(TRUE);
1930 } else if (bt_device_state &
1931 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1932 BT_INFO("Disconnected due to turning BT off. Skip a address");
1934 char *last_connected = NULL;
1935 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1936 if (!g_strcmp0(address, last_connected))
1937 _bt_audio_set_auto_connect_device_addr("");
1939 free(last_connected);
1944 /*Check for any OPP transfer on the device and cancel
1947 _bt_obex_check_pending_transfer(address);
1948 _bt_opp_client_is_sending(&sending);
1949 if (sending == TRUE)
1950 _bt_opp_client_check_pending_transfer(address);
1951 /* TODO: MAP? see above */
1953 param = g_variant_new("(isy)", result, address, addr_type);
1954 _bt_send_event(BT_DEVICE_EVENT,
1955 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1958 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1960 char *profile_uuid = NULL;
1961 bt_headset_wait_t *wait_list;
1962 bluetooth_device_address_t bd_addr;
1964 g_variant_get(msg, "(si)", &profile_uuid, &state);
1966 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1968 _bt_convert_device_path_to_address(path, address);
1969 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1971 _bt_convert_addr_string_to_secure_string(secure_address, address);
1972 BT_DBG("Address: %s", secure_address);
1973 BT_DBG("Profile UUID: %s", profile_uuid);
1974 BT_DBG("State: %d", state);
1976 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1977 (state == BT_PROFILE_STATE_CONNECTED)) {
1979 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1980 #ifndef TIZEN_BT_DUAL_HEADSET_CONNECT
1981 bluetooth_device_address_t device_address;
1982 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1985 bt_headset_wait_t *wait_list;
1986 guint restricted = 0x0;
1988 __bt_set_device_values(TRUE,
1989 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1991 __bt_connection_manager_set_state(address, event);
1993 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
1995 if (_bt_headset_get_local_connection() == FALSE) {
1996 if (restricted == 0x0) /* not restricted*/
1997 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1999 /* Connection Started from local device therefore no need to
2000 * intiate connection for pending profile */
2001 _bt_headset_set_local_connection(FALSE);
2003 param = g_variant_new("(is)", result, address);
2004 _bt_send_event(BT_HEADSET_EVENT, event,
2006 #ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
2007 _bt_check_already_connected_headset(BT_AUDIO_A2DP,
2010 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2013 if (g_strcmp0(connected_address, address) != 0) {
2014 _bt_convert_addr_string_to_type(
2015 device_address.addr,
2017 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2018 &device_address, NULL);
2022 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2023 BT_STATE_CONNECTED, address);
2025 wait_list = _bt_get_audio_wait_data();
2026 if (wait_list != NULL &&
2027 (g_strcmp0(wait_list->address, address) == 0))
2028 _bt_rel_wait_data();
2030 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2031 (state == BT_PROFILE_STATE_DISCONNECTED)) {
2033 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2035 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2037 g_free(profile_uuid);
2041 __bt_set_device_values(FALSE,
2042 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2044 __bt_connection_manager_set_state(address, event);
2045 param = g_variant_new("(is)", result, address);
2046 _bt_send_event(BT_HEADSET_EVENT, event,
2048 /* Remove data from the connected list */
2049 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2050 wait_list = _bt_get_audio_wait_data();
2052 if (wait_list == NULL) {
2054 g_free(profile_uuid);
2058 if (((wait_list->type == BT_AUDIO_ALL) &&
2059 (wait_list->ag_flag == TRUE)) ||
2060 (wait_list->type == BT_AUDIO_A2DP) ||
2061 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2062 bluetooth_device_address_t device_address;
2063 _bt_convert_addr_string_to_type(
2064 device_address.addr,
2065 wait_list->address);
2067 _bt_audio_connect(wait_list->req_id,
2072 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2074 if (state == BT_PROFILE_STATE_CONNECTED) {
2075 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2076 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2077 bluetooth_device_address_t device_address;
2079 param = g_variant_new("(is)", result, address);
2080 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2082 connected = _bt_is_headset_type_connected(
2086 if (g_strcmp0(connected_address,
2088 _bt_convert_addr_string_to_type(
2089 device_address.addr,
2091 _bt_audio_disconnect(0,
2093 &device_address, NULL);
2096 BT_DBG("device Path: %s", path);
2097 _bt_add_headset_to_list(BT_AVRCP,
2098 BT_STATE_CONNECTED, address);
2099 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2100 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2101 param = g_variant_new("(is)", result, address);
2102 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2104 /* Remove data from the connected list */
2105 _bt_remove_headset_from_list(BT_AVRCP, address);
2107 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2108 if (state == BT_PROFILE_STATE_CONNECTED) {
2109 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2110 BT_INFO("A2DP Source is connected");
2111 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2112 __bt_set_device_values(TRUE,
2113 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2116 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2117 _bt_audio_set_auto_connect_device_addr(address);
2118 _bt_audio_stop_auto_connect();
2120 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2121 BT_STATE_CONNECTED, address);
2122 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2123 g_variant_new("(is)", result, address));
2124 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2125 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2126 BT_INFO("A2DP Source Disconnected");
2127 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2128 __bt_set_device_values(FALSE,
2129 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2131 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2132 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2133 g_variant_new("(is)", result, address));
2135 wait_list = _bt_get_audio_wait_data();
2136 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2137 bluetooth_device_address_t device_address;
2138 _bt_convert_addr_string_to_type(
2139 device_address.addr,
2140 wait_list->address);
2142 _bt_audio_connect(wait_list->req_id,
2146 /* Now free the wait list */
2147 _bt_rel_wait_data();
2150 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2151 ((state == BT_PROFILE_STATE_CONNECTED) ||
2152 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2154 if (state == BT_PROFILE_STATE_CONNECTED)
2155 event = BLUETOOTH_HID_CONNECTED;
2157 event = BLUETOOTH_HID_DISCONNECTED;
2158 param = g_variant_new("(is)", result, address);
2159 _bt_send_event(BT_HID_EVENT, event,
2162 /* Set the vconf value for device */
2163 if (state == BT_PROFILE_STATE_CONNECTED) {
2164 hid_connected_device_count++;
2165 __bt_set_device_values(TRUE,
2166 VCONFKEY_BT_DEVICE_HID_CONNECTED);
2168 hid_connected_device_count--;
2169 if (hid_connected_device_count == 0)
2170 __bt_set_device_values(FALSE,
2171 VCONFKEY_BT_DEVICE_HID_CONNECTED);
2173 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2174 if (state == BT_PROFILE_STATE_CONNECTED) {
2176 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2177 param = g_variant_new("(is)", result, address);
2178 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2180 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2181 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2182 param = g_variant_new("(is)", result, address);
2183 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2188 g_free(profile_uuid);
2189 } else if (strcasecmp(member, "AdvReport") == 0) {
2191 bt_remote_le_dev_info_t *le_dev_info = NULL;
2192 char *buffer = NULL;
2194 bt_le_adv_info_t *adv_info = NULL;
2195 GVariant *value = NULL;
2196 ret_if(_bt_is_le_scanning() == FALSE);
2198 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2200 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
2201 &le_dev_info->addr_type,
2202 &le_dev_info->adv_type,
2204 &le_dev_info->adv_data_len,
2207 if (value == NULL) {
2208 _bt_free_le_device_info(le_dev_info);
2212 _bt_convert_device_path_to_address(path, le_dev_info->address);
2214 buffer_len = g_variant_get_size(value);
2216 buffer = (char *)g_variant_get_data(value);
2218 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2219 if (le_dev_info->adv_data == NULL &&
2220 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2221 _bt_free_le_device_info(le_dev_info);
2222 g_variant_unref(value);
2226 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2227 _bt_send_scan_result_event(le_dev_info, NULL);
2228 _bt_free_le_device_info(le_dev_info);
2229 g_variant_unref(value);
2233 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2234 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2235 adv_info->addr = g_strdup(le_dev_info->address);
2236 adv_info->addr_type = le_dev_info->addr_type;
2237 adv_info->rssi = le_dev_info->rssi;
2238 adv_info->data_len = le_dev_info->adv_data_len;
2239 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2240 memcpy(adv_info->data, le_dev_info->adv_data,
2241 le_dev_info->adv_data_len);
2243 if (__bt_add_adv_ind_info(adv_info) == 0) {
2244 adv_info->timer_id = g_timeout_add(1000,
2245 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2247 } else { /* SCAN_RSP */
2248 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2250 _bt_send_scan_result_event(le_dev_info, adv_info);
2251 __bt_del_adv_ind_info(le_dev_info->address);
2254 _bt_free_le_device_info(le_dev_info);
2255 g_variant_unref(value);
2256 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2257 guint16 tx_octets = 0;
2258 guint16 tx_time = 0;
2259 guint16 rx_octets = 0;
2260 guint16 rx_time = 0;
2262 g_variant_get(msg, "(qqqq)",
2263 &tx_octets, &tx_time, &rx_octets, &rx_time);
2265 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2266 _bt_convert_device_path_to_address(path, address);
2268 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2269 rx_octets, rx_time);
2270 /* Send event to application */
2271 _bt_send_event(BT_DEVICE_EVENT,
2272 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2274 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2275 gboolean connected = FALSE;
2276 char *ifname = NULL;
2277 GVariant *ipsp_param = NULL;
2279 g_variant_get(msg, "(bs)", &connected, &ifname);
2281 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2282 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2284 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2285 _bt_convert_device_path_to_address(path, address);
2287 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2288 BT_DBG("address: %s", address);
2289 param = g_variant_new("(iss)", result, address, ifname);
2290 ipsp_param = g_variant_new("(ss)", ifname, address);
2293 GDBusProxy *ipsp_proxy;
2295 BT_DBG("IPSP connected, Set Ipv6 Addr");
2296 ipsp_proxy = _bt_get_ipsp_proxy();
2297 if (ipsp_proxy == NULL) {
2298 BT_ERR("can not get ipsp proxy");
2303 g_dbus_proxy_call(ipsp_proxy, "SetIpv6Addr",
2304 ipsp_param, G_DBUS_CALL_FLAGS_NONE,
2305 -1, NULL, NULL, NULL);
2307 BT_DBG("IPSP disconnected");
2308 ipsp_proxy = _bt_get_ipsp_proxy();
2309 if (ipsp_proxy == NULL) {
2310 BT_ERR("can not get ipsp proxy");
2315 g_dbus_proxy_call(ipsp_proxy, "DisableIpsp",
2316 NULL, G_DBUS_CALL_FLAGS_NONE,
2317 -1, NULL, NULL, NULL);
2320 /* Send event to application */
2321 _bt_send_event(BT_DEVICE_EVENT,
2325 } else if (strcasecmp(member, "AttMtuChanged") == 0) {
2326 int result = BLUETOOTH_ERROR_NONE;
2330 g_variant_get(msg, "(q)", &mtu);
2332 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2334 _bt_convert_device_path_to_address(path, address);
2335 _bt_convert_addr_string_to_secure_string(secure_address, address);
2336 BT_DBG("Address : %s MTU changed : %d", secure_address, mtu);
2338 param = g_variant_new("(isqy)",
2344 /* Send the event to application */
2345 _bt_send_event(BT_DEVICE_EVENT,
2346 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
2353 void __bt_set_audio_values(gboolean connected, char *address)
2356 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2358 /* Set the headset name */
2359 if (connected == TRUE)
2360 name = _bt_get_bonded_device_name(address);
2362 name = g_strdup("");
2364 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2365 BT_ERR("vconf_set_str failed");
2369 /* Set the headset state */
2370 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2371 BT_ERR("vconf_get_int failed");
2373 #ifdef TIZEN_SUPPORT_DUAL_HF
2374 if ((connected == TRUE) &&
2375 (FALSE == __bt_is_companion_device(address))) {
2376 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2377 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2378 (FALSE == __bt_is_companion_device(address))) {
2379 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2382 if (connected == TRUE)
2383 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2384 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2385 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2388 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2389 bt_device_state) != 0) {
2390 BT_ERR("vconf_set_int failed");
2394 void _bt_handle_headset_event(GVariant *msg, const char *path)
2396 int result = BLUETOOTH_ERROR_NONE;
2397 gboolean property_flag = FALSE;
2398 char *property = NULL;
2399 GVariant *value = NULL;
2400 GVariant *param = NULL;
2401 g_variant_get(msg, "(sv)", &property, &value);
2402 bluetooth_device_address_t bd_addr;
2404 ret_if(property == NULL);
2406 BT_DBG("Property = %s \n", property);
2407 /* We allow only 1 headset connection (HSP or HFP)*/
2408 if (strcasecmp(property, "Connected") == 0) {
2409 int event = BLUETOOTH_EVENT_NONE;
2410 bt_headset_wait_t *wait_list;
2412 guint restricted = 0x0;
2413 g_variant_get(value, "b", &property_flag);
2415 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2417 _bt_convert_device_path_to_address(path, address);
2418 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2420 if (property_flag == TRUE) {
2421 event = BLUETOOTH_EVENT_AG_CONNECTED;
2422 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2424 if (_bt_headset_get_local_connection() == FALSE) {
2425 if (restricted == 0x0) /* not restricted*/
2426 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2428 _bt_headset_set_local_connection(FALSE);
2432 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2434 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2435 if (previous_state == BT_STATE_DISCONNECTING)
2436 _bt_send_hf_local_term_event(address);
2438 /* Set the State machine here */
2439 __bt_connection_manager_set_state(address, event);
2440 __bt_set_audio_values(property_flag, address);
2441 param = g_variant_new("(is)", result, address);
2442 _bt_send_event(BT_HEADSET_EVENT, event,
2445 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2446 /* Remove data from the connected list */
2447 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2449 wait_list = _bt_get_audio_wait_data();
2450 if (wait_list == NULL) {
2455 bluetooth_device_address_t device_address;
2457 _bt_set_audio_wait_data_flag(TRUE);
2459 _bt_convert_addr_string_to_type(device_address.addr,
2460 wait_list->address);
2461 _bt_audio_connect(wait_list->req_id, wait_list->type,
2462 &device_address, NULL);
2463 _bt_rel_wait_data();
2464 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2465 /* Add data to the connected list */
2466 _bt_add_headset_to_list(BT_AUDIO_HSP,
2467 BT_STATE_CONNECTED, address);
2469 wait_list = _bt_get_audio_wait_data();
2470 if (wait_list != NULL &&
2471 (g_strcmp0(wait_list->address, address) == 0))
2472 _bt_rel_wait_data();
2474 BT_INFO("Check A2DP pending connect");
2475 _bt_audio_check_pending_connect();
2478 } else if (strcasecmp(property, "State") == 0) {
2481 g_variant_get(value, "s", &state);
2483 /* This code assumes we support only 1 headset connection */
2484 /* Need to use the headset list, if we support multi-headsets */
2485 if (strcasecmp(state, "Playing") == 0) {
2486 BT_DBG("Playing: Sco Connected");
2487 } else if (strcasecmp(state, "connected") == 0 ||
2488 strcasecmp(state, "disconnected") == 0) {
2489 BT_DBG("connected/disconnected: Sco Disconnected");
2491 BT_ERR("Not handled state - %s", state);
2496 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2500 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2502 _bt_convert_device_path_to_address(path, address);
2504 spkr_gain = g_variant_get_uint16(value);
2506 BT_DBG("spkr_gain: %d", spkr_gain);
2508 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2509 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2513 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2517 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2519 _bt_convert_device_path_to_address(path, address);
2521 mic_gain = g_variant_get_uint16(value);
2523 param = g_variant_new("(i&sq)", result, address, mic_gain);
2524 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2531 g_variant_unref(value);
2534 void _bt_handle_sink_event(GVariant *msg, const char *path)
2536 GVariantIter value_iter;
2537 char *property = NULL;
2539 bt_headset_wait_t *wait_list;
2541 GVariant *child = NULL;
2542 GVariant *val = NULL;
2543 GVariant *param = NULL;
2544 g_variant_iter_init(&value_iter, msg);
2545 while ((child = g_variant_iter_next_value(&value_iter))) {
2547 g_variant_get(child, "{sv}", &property, &val);
2549 ret_if(property == NULL);
2551 BT_DBG("Property = %s \n", property);
2554 if (strcasecmp(property, "State") == 0) {
2555 int result = BLUETOOTH_ERROR_NONE;
2558 g_variant_get(val, "s", &value);
2559 BT_DBG("value: %s", value);
2561 if (g_strcmp0(value, "disconnected") == 0) {
2564 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2566 _bt_convert_device_path_to_address(path, address);
2568 __bt_set_device_values(FALSE,
2569 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2570 param = g_variant_new("(is)", result, address);
2571 _bt_send_event(BT_HEADSET_EVENT,
2572 BLUETOOTH_EVENT_AV_DISCONNECTED,
2575 /* Remove data from the connected list */
2576 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2577 wait_list = _bt_get_audio_wait_data();
2578 if (wait_list == NULL) {
2581 g_variant_unref(val);
2582 g_variant_unref(child);
2587 if (((wait_list->type == BT_AUDIO_ALL) &&
2588 (wait_list->ag_flag == TRUE)) ||
2589 (wait_list->type == BT_AUDIO_A2DP) ||
2590 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2591 bluetooth_device_address_t device_address;
2592 _bt_convert_addr_string_to_type(
2593 device_address.addr,
2594 wait_list->address);
2596 _bt_audio_connect(wait_list->req_id,
2602 } else if (strcasecmp(value, "Connected") == 0) {
2604 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2605 bluetooth_device_address_t device_address;
2608 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2610 _bt_convert_device_path_to_address(path, address);
2612 __bt_set_device_values(TRUE,
2613 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2614 param = g_variant_new("(is)", result, address);
2615 _bt_send_event(BT_HEADSET_EVENT,
2616 BLUETOOTH_EVENT_AV_CONNECTED,
2618 /* Check for existing Media device to disconnect */
2619 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2622 /* Match connected device address */
2623 if (g_strcmp0(connected_address, address) != 0) {
2624 /* Convert BD adress from string type */
2625 _bt_convert_addr_string_to_type(
2626 device_address.addr,
2628 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2629 &device_address, NULL);
2633 /* Add data to the connected list */
2634 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2635 BT_STATE_CONNECTED, address);
2642 g_variant_unref(val);
2643 g_variant_unref(child);
2647 void _bt_handle_agent_event(GVariant *msg, const char *member)
2649 int result = BLUETOOTH_ERROR_NONE;
2650 char *address = NULL;
2653 GVariant *param = NULL;
2654 ret_if(member == NULL);
2656 if (strcasecmp(member, "ObexAuthorize") == 0) {
2657 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2658 param = g_variant_new("(iss)", result, address, name);
2659 _bt_send_event(BT_OPP_SERVER_EVENT,
2660 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2662 /* TODO: MAP? see above */
2665 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2666 bt_rfcomm_server_info_t *server_info;
2668 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2670 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2671 ret_if(server_info == NULL);
2672 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2673 param = g_variant_new("(isssn)", result, address, uuid, name,
2674 server_info->control_fd);
2675 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2676 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2684 void _bt_handle_tds_provider_event(GVariant *msg, const char *member, const char *path)
2686 BT_INFO("member: %s, path: %s", member, path);
2688 ret_if(path == NULL);
2690 if (strcasecmp(member, "TdsActivationRequested") == 0) {
2691 GVariant *value = NULL;
2693 unsigned char *buffer = NULL;
2694 unsigned char org_id;
2696 g_variant_get(msg, "(y@ay)", &org_id, &value);
2697 BT_DBG("org_id: %.2x", org_id);
2698 len = g_variant_get_size(value);
2701 buffer = (unsigned char *)g_variant_get_data(value);
2702 for (i = 0; i < len; i++)
2703 BT_DBG("%.2x", buffer[i]);
2706 /* Send event only registered client */
2707 _bt_tds_handle_activation_request(path, org_id, buffer, len);
2708 g_variant_unref(value);
2712 static int __bt_get_object_path(GVariant *msg, char **path)
2714 g_variant_get(msg, "(o*)", path, NULL);
2716 return BLUETOOTH_ERROR_INTERNAL;
2718 return BLUETOOTH_ERROR_NONE;
2721 static void __bt_devices_list_free(void)
2723 bt_cache_info_t *cache_info;
2726 node = g_list_first(p_cache_list);
2728 while (node != NULL) {
2729 cache_info = (bt_cache_info_t *)node->data;
2730 p_cache_list = g_list_remove(p_cache_list, cache_info);
2731 __bt_free_cache_info(cache_info);
2733 node = g_list_next(node);
2737 static int __bt_parse_event(GVariant *msg)
2741 char *interface_name = NULL;
2742 GVariant *inner_iter = NULL;
2744 g_variant_iter_init(&iter, msg);
2746 while ((child = g_variant_iter_next_value(&iter))) {
2747 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2748 if (g_strcmp0(interface_name,
2749 BT_DEVICE_INTERFACE) == 0) {
2750 g_variant_unref(inner_iter);
2751 g_variant_unref(child);
2752 return BT_DEVICE_EVENT;
2753 } else if (g_strcmp0(interface_name,
2754 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2755 g_variant_unref(inner_iter);
2756 g_variant_unref(child);
2757 return BT_MEDIA_TRANSFER_EVENT;
2758 } else if (g_strcmp0(interface_name,
2759 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2760 g_variant_unref(inner_iter);
2761 g_variant_unref(child);
2762 return BT_AVRCP_CONTROL_EVENT;
2764 g_variant_unref(inner_iter);
2765 g_variant_unref(child);
2771 static void __bt_manager_event_filter(GDBusConnection *connection,
2772 const gchar *sender_name,
2773 const gchar *object_path,
2774 const gchar *interface_name,
2775 const gchar *signal_name,
2776 GVariant *parameters,
2779 bt_event_type_t bt_event = 0x00;
2780 int result = BLUETOOTH_ERROR_NONE;
2782 char *obj_path = NULL;
2783 GVariant *param = NULL;
2784 if (signal_name == NULL)
2786 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2787 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2789 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2790 if (TIZEN_FEATURE_BT_USB_DONGLE) {
2791 BT_DBG("Enable Adapter");
2792 _bt_enable_adapter();
2794 _bt_handle_adapter_added();
2797 bt_event = __bt_parse_event(value);
2798 if (bt_event == BT_DEVICE_EVENT) {
2799 bt_cache_info_t *cache_info;
2800 bt_remote_dev_info_t *dev_info;
2801 #ifdef TIZEN_FEATURE_BT_DPM
2802 int desktop_state = DPM_BT_ERROR;
2804 ret_if(_bt_is_discovering() == FALSE &&
2805 _bt_is_le_scanning() == FALSE);
2807 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2809 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2811 cache_info->dev_info = dev_info;
2813 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2814 BT_ERR("Fail to parse the properies");
2815 __bt_free_cache_info(cache_info);
2816 g_variant_unref(value);
2820 if (dev_info->addr_type != BDADDR_BREDR) {
2821 /* Whenever emit the property changed from bluez,
2822 some property doesn't reach to bt-service.
2823 So LE device is handled as AdvReport signal */
2824 __bt_free_cache_info(cache_info);
2825 g_variant_unref(value);
2829 if (dev_info->name == NULL)
2830 /* If Remote device name is NULL or still RNR is not done
2831 * then display address as name.
2833 dev_info->name = g_strdup(dev_info->address);
2835 #ifdef TIZEN_FEATURE_BT_DPM
2836 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
2837 if (desktop_state == DPM_RESTRICTED) {
2838 bluetooth_device_class_t device_class;
2839 _bt_divide_device_class(&device_class, dev_info->class);
2840 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2842 if (device_class.major_class ==
2843 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2844 __bt_free_cache_info(cache_info);
2845 g_variant_unref(value);
2851 GVariant *uuids = NULL;
2852 GVariantBuilder *builder = NULL;
2854 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2855 for (i = 0; i < dev_info->uuid_count; i++) {
2856 g_variant_builder_add(builder, "s",
2857 dev_info->uuids[i]);
2859 uuids = g_variant_new("as", builder);
2860 g_variant_builder_unref(builder);
2861 GVariant *manufacturer_data = NULL;
2862 manufacturer_data = g_variant_new_from_data(
2863 G_VARIANT_TYPE_BYTESTRING,
2864 dev_info->manufacturer_data,
2865 dev_info->manufacturer_data_len,
2867 param = g_variant_new("(isunsbub@asn@ay)", result,
2873 dev_info->connected,
2876 dev_info->manufacturer_data_len,
2878 _bt_send_event(BT_ADAPTER_EVENT,
2879 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2881 p_cache_list = g_list_append(p_cache_list, cache_info);
2882 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2883 BT_DBG("Device path : %s ", obj_path);
2884 _bt_set_control_device_path(obj_path);
2887 g_variant_unref(value);
2888 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2889 if (TIZEN_FEATURE_BT_USB_DONGLE) {
2890 BT_DBG("InterfacesRemoved");
2891 _bt_handle_adapter_removed();
2893 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2894 bt_event = BT_MEDIA_TRANSFER_EVENT;
2895 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2896 bt_event = BT_DEVICE_EVENT;
2897 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2898 bt_event = BT_AVRCP_CONTROL_EVENT;
2900 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2901 _bt_handle_adapter_event(parameters, signal_name);
2902 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2903 BT_INFO("Object Path %s", obj_path);
2904 _bt_remove_control_device_path(obj_path);
2907 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2910 char *previous = NULL;
2911 char *current = NULL;
2913 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2914 BT_ERR("Fail to get the owner info");
2918 if (*current != '\0') {
2927 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2928 BT_INFO_C("### Bluetoothd is terminated");
2929 if (_bt_adapter_get_status() != BT_DEACTIVATING &&
2930 _bt_adapter_get_status() != BT_DEACTIVATED) {
2931 BT_INFO_C("### Recover it");
2932 _bt_recover_adapter();
2934 _bt_handle_adapter_removed();
2935 __bt_devices_list_free();
2938 _bt_obex_server_check_allocation(&value);
2940 if (value == TRUE) {
2941 /* Check if the obex server was terminated abnormally */
2942 _bt_obex_server_check_termination(name);
2945 _bt_rfcomm_server_check_existence(&value);
2947 if (value == TRUE) {
2948 /* The obex server was terminated abnormally */
2949 _bt_rfcomm_server_check_termination(name);
2952 /* Stop advertising started by terminated process */
2953 _bt_stop_advertising_by_terminated_process(name);
2955 _bt_stop_le_scan(name);
2957 /* Stop the Proximity reporter service */
2958 _bt_proximity_reporter_stop_by_terminated_process(name);
2960 /* Stop the Transport Discovery service */
2961 _bt_tds_stop_by_terminated_process(name);
2966 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2967 const char *path = object_path;
2969 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2970 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2973 _bt_handle_property_changed_event(parameters, object_path);
2974 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2975 _bt_handle_adapter_event(parameters, signal_name);
2976 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2977 _bt_handle_input_event(parameters, object_path);
2978 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2979 _bt_handle_network_server_event(parameters, signal_name);
2980 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2981 _bt_handle_headset_event(parameters, object_path);
2982 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2983 _bt_handle_sink_event(parameters, object_path);
2984 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2985 _bt_handle_agent_event(parameters, signal_name);
2986 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2987 _bt_handle_device_event(parameters, signal_name, object_path);
2988 } else if (g_strcmp0(interface_name, BT_TDS_PROVIDER_INTERFACE) == 0) {
2989 _bt_handle_tds_provider_event(parameters, signal_name, object_path);
2990 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2991 _bt_handle_gatt_event(parameters, signal_name, object_path);
2997 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
3000 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
3001 char *interface_name = NULL;
3003 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
3004 retv_if(interface_name == NULL, FALSE);
3006 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
3007 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
3015 static void __bt_obexd_event_filter(GDBusConnection *connection,
3016 const gchar *sender_name,
3017 const gchar *object_path,
3018 const gchar *interface_name,
3019 const gchar *signal_name,
3020 GVariant *parameters,
3023 const char *member = signal_name;
3024 char *obj_path = NULL;
3025 ret_if(member == NULL);
3027 if (strcasecmp(member, "InterfacesAdded") == 0) {
3028 if (__bt_get_object_path(parameters, &obj_path)) {
3029 BT_ERR("Fail to get the path");
3032 BT_INFO("object_path = [%s]", obj_path);
3034 /*Handle OPP_SERVER_CONNECTED_EVENT here */
3035 /* TODO: MAP? see above */
3036 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
3037 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
3042 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
3043 BT_DBG("Obex_Server_Session_Transfer connected");
3044 _bt_obex_transfer_connected(obj_path);
3047 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3048 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
3049 /* TODO: MAP? see above */
3050 if (__bt_get_object_path(parameters, &obj_path)) {
3051 BT_ERR("Fail to get the path");
3054 BT_INFO("object_path = [%s]", obj_path);
3056 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3057 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3058 BT_DBG("Call PBAP Disconnected");
3059 _bt_obex_pbap_client_disconnect(obj_path);
3062 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
3063 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
3068 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
3069 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
3072 _bt_obex_transfer_disconnected(obj_path);
3075 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
3076 const char *path = object_path;
3078 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
3079 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
3080 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3081 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3082 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
3086 _bt_handle_property_changed_event(parameters, path);
3092 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
3096 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
3097 char *interface_name = NULL;
3099 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
3101 retv_if(interface_name == NULL, FALSE);
3103 if (strcasecmp(interface_name,
3104 BT_OBEX_TRANSFER_INTERFACE) == 0) {
3115 static void __bt_opc_event_filter(GDBusConnection *connection,
3116 const gchar *sender_name,
3117 const gchar *object_path,
3118 const gchar *interface_name,
3119 const gchar *signal_name,
3120 GVariant *parameters,
3123 const char *member = signal_name;
3124 char *obj_path = NULL;
3125 if (strcasecmp(member, "InterfacesAdded") == 0) {
3126 BT_DBG("InterfacesAdded");
3127 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3129 if (__bt_get_object_path(parameters, &obj_path)) {
3130 BT_ERR("Fail to get the path");
3134 BT_DBG("object_path = %s", obj_path);
3136 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3137 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3138 || strstr(obj_path, "transfer") == NULL) {
3141 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3142 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3143 BT_DBG("Going to call opc disconnected");
3144 _bt_opc_disconnected(obj_path);
3147 _bt_sending_files();
3149 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3150 char *path = (char *)object_path;
3151 BT_INFO("object_path %s", path);
3152 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3153 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3154 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3158 _bt_opc_property_changed_event(parameters, path);
3164 int _bt_opp_client_event_init(void)
3166 GError *error = NULL;
3168 if (opc_obexd_conn == NULL) {
3169 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3171 if (!opc_obexd_conn) {
3173 BT_ERR("Unable to connect to dbus: %s", error->message);
3174 g_clear_error(&error);
3176 return BLUETOOTH_ERROR_INTERNAL;
3180 if (_bt_register_service_event(opc_obexd_conn,
3181 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3182 g_object_unref(opc_obexd_conn);
3183 opc_obexd_conn = NULL;
3184 return BLUETOOTH_ERROR_INTERNAL;
3187 return BLUETOOTH_ERROR_NONE;
3190 void _bt_opp_client_event_deinit(void)
3192 if (opc_obexd_conn) {
3193 _bt_unregister_service_event(opc_obexd_conn,
3194 BT_OPP_CLIENT_EVENT);
3195 g_object_unref(opc_obexd_conn);
3196 opc_obexd_conn = NULL;
3200 static void __bt_map_event_filter(GDBusConnection *connection,
3201 const gchar *sender_name,
3202 const gchar *object_path,
3203 const gchar *interface_name,
3204 const gchar *signal_name,
3205 GVariant *parameters,
3208 BT_DBG("Entered __bt_map_event_filter");
3209 const char *member = signal_name;
3211 if (strcasecmp(member, "InterfacesAdded") == 0) {
3212 BT_DBG("------------------------------------ADDED------------------------------------");
3213 // currently doing nothing
3214 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3215 BT_DBG("------------------------------------REMOVED------------------------------------");
3216 // TODO check if something should be called here?
3217 //_bt_map_on_transfer_finished(object_path, error);
3218 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3219 BT_DBG("------------------------------------CLIENT EVENT------------------------------------");
3220 _bt_map_property_changed_event(parameters, object_path);
3226 int _bt_map_client_event_init(void)
3228 GError *error = NULL;
3230 if (map_obexd_conn == NULL) {
3231 map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3233 if (!map_obexd_conn) {
3235 BT_ERR("Unable to connect to dbus: %s", error->message);
3236 g_clear_error(&error);
3238 return BLUETOOTH_ERROR_INTERNAL;
3242 if (_bt_register_service_event(map_obexd_conn,
3243 BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3244 g_object_unref(map_obexd_conn);
3245 map_obexd_conn = NULL;
3246 return BLUETOOTH_ERROR_INTERNAL;
3249 return BLUETOOTH_ERROR_NONE;
3252 void _bt_map_client_event_deinit(void)
3254 if (map_obexd_conn) {
3255 _bt_unregister_service_event(map_obexd_conn,
3256 BT_MAP_CLIENT_EVENT);
3257 g_object_unref(map_obexd_conn);
3258 map_obexd_conn = NULL;
3262 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3268 static int subs_interface_added_id = -1;
3269 static int subs_interface_removed_id = -1;
3270 static int subs_name_owner_id = -1;
3271 static int subs_property_id = -1;
3272 static int subs_adapter_id = -1;
3273 static int subs_gatt_id = -1;
3276 if (subs_interface_added_id == -1) {
3277 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3278 NULL, BT_MANAGER_INTERFACE,
3279 BT_INTERFACES_ADDED, NULL, NULL, 0,
3280 __bt_manager_event_filter,
3283 if (subs_interface_removed_id == -1) {
3284 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3285 NULL, BT_MANAGER_INTERFACE,
3286 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3287 __bt_manager_event_filter,
3290 if (subs_name_owner_id == -1) {
3291 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3292 NULL, BT_FREEDESKTOP_INTERFACE,
3293 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3294 __bt_manager_event_filter,
3297 if (subs_property_id == -1) {
3298 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3299 NULL, BT_PROPERTIES_INTERFACE,
3300 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3301 __bt_manager_event_filter,
3304 if (subs_adapter_id == -1) {
3305 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3306 NULL, BT_ADAPTER_INTERFACE,
3307 NULL, NULL, NULL, 0,
3308 __bt_manager_event_filter,
3311 if (subs_gatt_id == -1) {
3312 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3313 NULL, BT_GATT_CHAR_INTERFACE,
3314 NULL, NULL, NULL, 0,
3315 __bt_manager_event_filter,
3319 if (subs_interface_added_id != -1) {
3320 g_dbus_connection_signal_unsubscribe(conn,
3321 subs_interface_added_id);
3322 subs_interface_added_id = -1;
3324 if (subs_interface_removed_id != -1) {
3325 g_dbus_connection_signal_unsubscribe(conn,
3326 subs_interface_removed_id);
3327 subs_interface_removed_id = -1;
3329 if (subs_name_owner_id != -1) {
3330 g_dbus_connection_signal_unsubscribe(conn,
3331 subs_name_owner_id);
3332 subs_name_owner_id = -1;
3334 if (subs_property_id != -1) {
3335 g_dbus_connection_signal_unsubscribe(conn,
3337 subs_property_id = -1;
3339 if (subs_adapter_id != -1) {
3340 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3341 subs_adapter_id = -1;
3343 if (subs_gatt_id != -1) {
3344 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3351 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3357 static int subs_device_id = -1;
3360 if (subs_device_id == -1) {
3361 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3362 NULL, BT_DEVICE_INTERFACE,
3363 NULL, NULL, NULL, 0,
3364 __bt_manager_event_filter,
3368 if (subs_device_id != -1) {
3369 g_dbus_connection_signal_unsubscribe(conn,
3371 subs_device_id = -1;
3377 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3383 static int subs_input_id = -1;
3386 if (subs_input_id == -1) {
3387 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3388 NULL, BT_INPUT_INTERFACE,
3389 NULL, NULL, NULL, 0,
3390 __bt_manager_event_filter,
3394 if (subs_input_id != -1) {
3395 g_dbus_connection_signal_unsubscribe(conn,
3403 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3409 static int subs_serv_id = -1;
3410 static int subs_client_id = -1;
3413 if (subs_serv_id == -1) {
3414 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3415 NULL, BT_NETWORK_SERVER_INTERFACE,
3416 NULL, NULL, NULL, 0,
3417 __bt_manager_event_filter,
3420 if (subs_client_id == -1) {
3421 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3422 NULL, BT_NETWORK_CLIENT_INTERFACE,
3423 NULL, NULL, NULL, 0,
3424 __bt_manager_event_filter,
3428 if (subs_serv_id != -1) {
3429 g_dbus_connection_signal_unsubscribe(conn,
3433 if (subs_client_id != -1) {
3434 g_dbus_connection_signal_unsubscribe(conn,
3436 subs_client_id = -1;
3442 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3448 static int subs_headset_id = -1;
3449 static int subs_sink_id = -1;
3452 if (subs_headset_id == -1) {
3453 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3454 NULL, BT_HEADSET_INTERFACE,
3455 NULL, NULL, NULL, 0,
3456 __bt_manager_event_filter,
3459 if (subs_sink_id == -1) {
3460 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3461 NULL, BT_SINK_INTERFACE,
3462 NULL, NULL, NULL, 0,
3463 __bt_manager_event_filter,
3467 if (subs_headset_id != -1) {
3468 g_dbus_connection_signal_unsubscribe(conn,
3470 subs_headset_id = -1;
3472 if (subs_sink_id != -1) {
3473 g_dbus_connection_signal_unsubscribe(conn,
3481 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3487 static int subs_opp_server_interface_added_id = -1;
3488 static int subs_opp_server_interface_removed_id = -1;
3489 static int subs_opp_server_property_id = -1;
3493 if (subs_opp_server_interface_added_id == -1) {
3494 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3495 NULL, BT_MANAGER_INTERFACE,
3496 BT_INTERFACES_ADDED, NULL, NULL, 0,
3497 __bt_obexd_event_filter,
3500 if (subs_opp_server_interface_removed_id == -1) {
3501 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3502 NULL, BT_MANAGER_INTERFACE,
3503 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3504 __bt_obexd_event_filter,
3507 if (subs_opp_server_property_id == -1) {
3508 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3509 NULL, BT_PROPERTIES_INTERFACE,
3510 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3511 __bt_obexd_event_filter,
3515 if (subs_opp_server_interface_added_id != -1) {
3516 g_dbus_connection_signal_unsubscribe(conn,
3517 subs_opp_server_interface_added_id);
3518 subs_opp_server_interface_added_id = -1;
3520 if (subs_opp_server_interface_removed_id != -1) {
3521 g_dbus_connection_signal_unsubscribe(conn,
3522 subs_opp_server_interface_removed_id);
3523 subs_opp_server_interface_removed_id = -1;
3525 if (subs_opp_server_property_id != -1) {
3526 g_dbus_connection_signal_unsubscribe(conn,
3527 subs_opp_server_property_id);
3528 subs_opp_server_property_id = -1;
3534 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3540 static int subs_opp_client_interface_added_id = -1;
3541 static int subs_opp_client_interface_removed_id = -1;
3542 static int subs_opp_client_property_id = -1;
3546 if (subs_opp_client_interface_added_id == -1) {
3547 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3548 NULL, BT_MANAGER_INTERFACE,
3549 BT_INTERFACES_ADDED, NULL, NULL, 0,
3550 __bt_opc_event_filter,
3553 if (subs_opp_client_interface_removed_id == -1) {
3554 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3555 NULL, BT_MANAGER_INTERFACE,
3556 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3557 __bt_opc_event_filter,
3560 if (subs_opp_client_property_id == -1) {
3561 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3562 NULL, BT_PROPERTIES_INTERFACE,
3563 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3564 __bt_opc_event_filter,
3568 if (subs_opp_client_interface_added_id != -1) {
3569 g_dbus_connection_signal_unsubscribe(conn,
3570 subs_opp_client_interface_added_id);
3571 subs_opp_client_interface_added_id = -1;
3573 if (subs_opp_client_interface_removed_id != -1) {
3574 g_dbus_connection_signal_unsubscribe(conn,
3575 subs_opp_client_interface_removed_id);
3576 subs_opp_client_interface_removed_id = -1;
3578 if (subs_opp_client_property_id != -1) {
3579 g_dbus_connection_signal_unsubscribe(conn,
3580 subs_opp_client_property_id);
3581 subs_opp_client_property_id = -1;
3587 int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
3593 static int subs_map_client_interface_added_id = -1;
3594 static int subs_map_client_interface_removed_id = -1;
3595 static int subs_map_client_property_id = -1;
3599 if (subs_map_client_interface_added_id == -1) {
3600 subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3601 NULL, BT_MANAGER_INTERFACE,
3602 BT_INTERFACES_ADDED, NULL, NULL, 0,
3603 __bt_map_event_filter,
3606 if (subs_map_client_interface_removed_id == -1) {
3607 subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3608 NULL, BT_MANAGER_INTERFACE,
3609 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3610 __bt_map_event_filter,
3613 if (subs_map_client_property_id == -1) {
3614 subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn,
3615 NULL, BT_PROPERTIES_INTERFACE,
3616 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3617 __bt_map_event_filter,
3621 if (subs_map_client_interface_added_id != -1) {
3622 g_dbus_connection_signal_unsubscribe(conn,
3623 subs_map_client_interface_added_id);
3624 subs_map_client_interface_added_id = -1;
3626 if (subs_map_client_interface_removed_id != -1) {
3627 g_dbus_connection_signal_unsubscribe(conn,
3628 subs_map_client_interface_removed_id);
3629 subs_map_client_interface_removed_id = -1;
3631 if (subs_map_client_property_id != -1) {
3632 g_dbus_connection_signal_unsubscribe(conn,
3633 subs_map_client_property_id);
3634 subs_map_client_property_id = -1;
3640 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3646 static int subs_a2dp_source_id = -1;
3647 static int subs_a2dp_sink_id = -1;
3650 if (subs_a2dp_source_id == -1) {
3651 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3652 NULL, BT_A2DP_SOURCE_INTERFACE,
3653 NULL, NULL, NULL, 0,
3654 __bt_opc_event_filter,
3657 if (subs_a2dp_sink_id == -1) {
3658 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3659 NULL, BT_SINK_INTERFACE,
3660 NULL, NULL, NULL, 0,
3661 __bt_opc_event_filter,
3665 if (subs_a2dp_source_id != -1) {
3666 g_dbus_connection_signal_unsubscribe(conn,
3667 subs_a2dp_source_id);
3668 subs_a2dp_source_id = -1;
3670 if (subs_a2dp_sink_id != -1) {
3671 g_dbus_connection_signal_unsubscribe(conn,
3673 subs_a2dp_sink_id = -1;
3679 int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscribe)
3684 static int subs_custom_id = -1;
3687 if (subs_custom_id == -1) {
3688 subs_custom_id = g_dbus_connection_signal_subscribe(conn,
3689 NULL, BT_TDS_PROVIDER_INTERFACE,
3690 NULL, NULL, NULL, 0,
3691 __bt_manager_event_filter,
3695 if (subs_custom_id != -1) {
3696 g_dbus_connection_signal_unsubscribe(conn,
3698 subs_custom_id = -1;
3705 static void __bt_dump_event_filter(GDBusConnection *connection,
3706 const gchar *sender_name,
3707 const gchar *object_path,
3708 const gchar *interface_name,
3709 const gchar *signal_name,
3710 GVariant *parameters,
3716 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3722 static int subs_source_id = -1;
3725 if (subs_source_id == -1) {
3726 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3727 NULL, BT_DUMP_SERVICE_INTERFACE,
3728 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3729 __bt_dump_event_filter,
3733 if (subs_source_id != -1) {
3734 g_dbus_connection_signal_unsubscribe(conn,
3736 subs_source_id = -1;
3742 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3746 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3748 switch (event_type) {
3749 case BT_MANAGER_EVENT:
3750 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3752 case BT_DEVICE_EVENT:
3753 _bt_register_device_subscribe_signal(g_conn, TRUE);
3756 _bt_register_input_subscribe_signal(g_conn, TRUE);
3758 case BT_NETWORK_EVENT:
3759 _bt_register_network_subscribe_signal(g_conn, TRUE);
3761 case BT_HEADSET_EVENT:
3762 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3764 case BT_OPP_SERVER_EVENT:
3765 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3766 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3769 case BT_OPP_CLIENT_EVENT:
3770 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3771 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3773 case BT_MAP_CLIENT_EVENT:
3774 BT_ERR("BT_MAP_CLIENT_EVENT: register service event");
3775 _bt_register_map_client_subscribe_signal(g_conn, TRUE);
3777 case BT_A2DP_SOURCE_EVENT:
3778 BT_INFO("A2dp Source event");
3779 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3782 BT_INFO("TDS provider event");
3783 _bt_register_tds_provider_subscribe_signal(g_conn, TRUE);
3786 BT_ERR("Unknown event");
3787 return BLUETOOTH_ERROR_INTERNAL;
3790 return BLUETOOTH_ERROR_NONE;
3793 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3797 ret_if(g_conn == NULL);
3799 switch (event_type) {
3800 case BT_MANAGER_EVENT:
3801 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3802 _bt_register_device_subscribe_signal(g_conn, FALSE);
3803 _bt_register_input_subscribe_signal(g_conn, FALSE);
3804 _bt_register_network_subscribe_signal(g_conn, FALSE);
3805 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3807 case BT_OPP_SERVER_EVENT:
3808 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3810 case BT_OPP_CLIENT_EVENT:
3811 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3813 case BT_MAP_CLIENT_EVENT:
3814 _bt_register_map_client_subscribe_signal(g_conn, FALSE);
3817 BT_ERR("Unknown event");
3824 static int __bt_init_manager_receiver(void)
3828 GError *error = NULL;
3830 if (manager_conn == NULL) {
3831 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3832 if (error != NULL) {
3833 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3834 g_clear_error(&error);
3836 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3839 if (_bt_register_service_event(manager_conn,
3840 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3842 if (_bt_register_service_event(manager_conn,
3843 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3846 if (_bt_register_service_event(manager_conn,
3847 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3850 if (_bt_register_service_event(manager_conn,
3851 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3854 if (_bt_register_service_event(manager_conn,
3855 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3858 if (_bt_register_service_event(manager_conn,
3859 BT_TDS_EVENT) != BLUETOOTH_ERROR_NONE)
3862 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3863 return BLUETOOTH_ERROR_NONE;
3866 g_object_unref(manager_conn);
3867 manager_conn = NULL;
3872 return BLUETOOTH_ERROR_INTERNAL;
3875 static int __bt_init_obexd_receiver(void)
3878 if (!TIZEN_PROFILE_TV) { /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3879 GError *error = NULL;
3881 if (obexd_conn == NULL) {
3882 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3883 if (error != NULL) {
3884 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3885 g_clear_error(&error);
3887 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3890 if (_bt_register_service_event(obexd_conn,
3891 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3892 BT_ERR("Error while registering service event");
3893 g_object_unref(obexd_conn);
3895 return BLUETOOTH_ERROR_INTERNAL;
3900 return BLUETOOTH_ERROR_NONE;
3903 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3905 static int retry_cnt = 0;
3906 int result = BLUETOOTH_ERROR_NONE;
3910 result = __bt_init_obexd_receiver();
3911 if (result != BLUETOOTH_ERROR_NONE) {
3912 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3913 then it is not the timing issue. Just can't use the session bus connection */
3914 if (retry_cnt > 100) {
3915 BT_ERR("Fail to init obexd receiver by 50 times.");
3917 session_reinit_timer = 0;
3921 BT_DBG("Retry to initialize the obexd receiver");
3926 session_reinit_timer = 0;
3933 /* To receive the event from bluez */
3934 int _bt_init_service_event_receiver(void)
3940 result = __bt_init_manager_receiver();
3941 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3943 result = __bt_init_obexd_receiver();
3944 if (result != BLUETOOTH_ERROR_NONE) {
3945 BT_ERR("Fail to init obexd receiver");
3947 /* Try to re-initialize obexd receiver in the timer */
3948 if (session_reinit_timer > 0)
3949 g_source_remove(session_reinit_timer);
3951 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3952 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3957 return BLUETOOTH_ERROR_NONE;
3960 void _bt_deinit_service_event_receiver(void)
3964 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3966 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3968 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3971 g_object_unref(manager_conn);
3972 manager_conn = NULL;
3976 g_object_unref(obexd_conn);
3981 g_source_remove(event_id);
3984 if (le_scan_event_id > 0)
3985 g_source_remove(le_scan_event_id);
3986 le_scan_event_id = 0;