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"
43 #include "bt-service-opp-client.h"
45 #ifdef TIZEN_DPM_ENABLE
46 #include "bt-service-dpm.h"
49 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
50 static GDBusConnection *manager_conn;
51 static GDBusConnection *obexd_conn;
52 static GDBusConnection *opc_obexd_conn;
54 static GList *p_cache_list = NULL;
56 static guint event_id;
57 guint nap_connected_device_count = 0;
58 static guint hid_connected_device_count = 0;
59 static GList *p_adv_ind_list = NULL;
62 bt_remote_dev_info_t *dev_info;
66 * obexd connection type
74 OBEX_PCSUITE = (1 << 6),
75 OBEX_SYNCEVOLUTION = (1 << 7),
77 } bluetooth_obex_connection_type_t;
79 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
80 void _bt_opc_property_changed_event(GVariant *msg, char *path);
81 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
82 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
83 void _bt_opp_client_event_deinit(void);
84 void _bt_handle_network_client_event(GVariant *msg_iter,
86 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
89 static void __bt_free_bt_le_adv_info_t(gpointer data)
91 bt_le_adv_info_t *adv_info = data;
93 if (adv_info->timer_id)
94 g_source_remove(adv_info->timer_id);
95 adv_info->timer_id = 0;
97 g_free(adv_info->addr);
98 g_free(adv_info->data);
102 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
104 retv_if(!addr, NULL);
105 bt_le_adv_info_t *adv_info = NULL;
106 GList *current = g_list_first((GList *)p_adv_ind_list);
107 while(current && current->data) {
108 adv_info = (bt_le_adv_info_t *)current->data;
109 if (adv_info && !g_strcmp0(adv_info->addr, addr))
111 current = g_list_next(current);
116 static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
118 retv_if(!adv_info, -1);
119 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
120 __bt_free_bt_le_adv_info_t(adv_info);
123 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
128 static void __bt_del_adv_ind_info(char *addr)
131 ret_if(!p_adv_ind_list);
132 bt_le_adv_info_t *adv_info = NULL;
133 GList *current = g_list_first((GList *)p_adv_ind_list);
134 while (current && current->data) {
135 adv_info = (bt_le_adv_info_t *)current->data;
136 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
137 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
138 __bt_free_bt_le_adv_info_t(adv_info);
141 current = g_list_next(current);
145 static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
147 bt_remote_le_dev_info_t le_dev_info;
148 bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
150 memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
152 le_dev_info.address = adv_info->addr;
153 le_dev_info.addr_type = adv_info->addr_type;
154 le_dev_info.rssi = adv_info->rssi;
155 le_dev_info.adv_data = adv_info->data;
156 le_dev_info.adv_data_len = 0;
157 adv_info->timer_id = 0;
159 _bt_send_scan_result_event(&le_dev_info, adv_info);
160 __bt_del_adv_ind_info(adv_info->addr);
165 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
167 ret_if(cache_info == NULL);
168 _bt_free_device_info(cache_info->dev_info);
172 static gboolean __bt_parse_device_properties(GVariant *item,
173 bt_remote_dev_info_t *dev_info)
182 g_variant_iter_init(&iter, item);
183 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
184 if (strcasecmp(key, "Address") == 0) {
185 dev_info->address = g_variant_dup_string(val, &len);
186 } else if (strcasecmp(key, "Class") == 0) {
187 dev_info->class = g_variant_get_uint32(val);
188 } else if (strcasecmp(key, "name") == 0) {
189 if (dev_info->name == NULL)
190 dev_info->name = g_variant_dup_string(val, &len);
191 } else if (strcasecmp(key, "Connected") == 0) {
192 dev_info->connected = g_variant_get_byte(val);
193 } else if (strcasecmp(key, "paired") == 0) {
194 dev_info->paired = g_variant_get_boolean(val);
195 } else if (strcasecmp(key, "Trusted") == 0) {
196 dev_info->trust = g_variant_get_boolean(val);
197 } else if (strcasecmp(key, "RSSI") == 0) {
198 dev_info->rssi = g_variant_get_int16(val);
199 } else if (strcasecmp(key, "LastAddrType") == 0) {
200 dev_info->addr_type = g_variant_get_byte(val);
201 } else if (strcasecmp(key, "UUIDs") == 0) {
205 size = g_variant_get_size(val);
208 uuid_value = (char **)g_variant_get_strv(val, &size);
209 if (dev_info->uuids == NULL)
210 dev_info->uuids = g_malloc0(sizeof(char *) * size);
212 for (i = 0; uuid_value[i] != NULL; i++) {
213 dev_info->uuid_count++;
214 dev_info->uuids[i] = g_strdup(uuid_value[i]);
218 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
219 g_variant_get(val, "q", &dev_info->manufacturer_data_len);
220 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
221 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
222 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
225 if (dev_info->manufacturer_data_len == 0)
226 dev_info->manufacturer_data = g_strdup("");
227 } else if (strcasecmp(key, "ManufacturerData") == 0) {
230 GVariantIter *value_iter;
233 len = g_variant_get_size(val);
237 dev_info->manufacturer_data = g_malloc0(len);
239 g_variant_get(val, "ay", &value_iter);
240 while (g_variant_iter_loop(value_iter, "y", &m_value))
241 dev_info->manufacturer_data[i++] = m_value;
242 g_variant_iter_free(value_iter);
250 static gboolean __bt_parse_interface(GVariant *msg,
251 bt_remote_dev_info_t *dev_info)
254 GVariant *optional_param = NULL;
257 char *interface_name = NULL;
258 GVariant *inner_iter = NULL;
259 g_variant_get(msg, "(&o@a{sa{sv}})",
260 &path, &optional_param);
261 g_variant_iter_init(&iter, optional_param);
263 retv_if(optional_param == NULL, FALSE);
265 while ((child = g_variant_iter_next_value(&iter))) {
266 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
267 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
268 BT_DBG("Found a device: %s", path);
269 if (__bt_parse_device_properties(inner_iter,
270 dev_info) == FALSE) {
271 g_variant_unref(inner_iter);
272 g_variant_unref(child);
273 g_variant_unref(optional_param);
274 BT_ERR("Fail to parse the properies");
277 g_variant_unref(inner_iter);
278 g_variant_unref(child);
279 g_variant_unref(optional_param);
283 g_variant_unref(inner_iter);
284 g_variant_unref(child);
287 g_variant_unref(optional_param);
292 static int __bt_get_owner_info(GVariant *msg, char **name,
293 char **previous, char **current)
295 g_variant_get(msg, "(sss)", name, previous, current);
296 return BLUETOOTH_ERROR_NONE;
299 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
300 char **name, char **uuid)
302 g_variant_get(msg, "(sss)", address, name, uuid);
303 return BLUETOOTH_ERROR_NONE;
306 void __bt_set_device_values(gboolean connected, int state)
308 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
310 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) {
311 BT_ERR("vconf_get_int failed");
314 if (connected == TRUE)
315 bt_device_state |= state;
316 else if (bt_device_state & state)
317 bt_device_state ^= state;
319 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) {
320 BT_ERR("vconf_set_int failed");
324 gboolean _bt_discovery_finished_cb(gpointer user_data)
326 int result = BLUETOOTH_ERROR_NONE;
328 GVariant *param = NULL;
329 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
330 if (_bt_get_cancel_by_user() == TRUE) {
331 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
334 _bt_set_cancel_by_user(FALSE);
335 _bt_set_discovery_status(FALSE);
336 param = g_variant_new("(i)", result);
337 _bt_send_event(BT_ADAPTER_EVENT,
338 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
345 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
347 int result = BLUETOOTH_ERROR_NONE;
349 GVariant *param = NULL;
350 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
351 if (_bt_get_cancel_by_user() == TRUE) {
352 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
355 g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
356 p_adv_ind_list = NULL;
358 _bt_set_cancel_by_user(FALSE);
359 _bt_disable_all_scanner_status();
360 _bt_set_le_scan_status(FALSE);
361 param = g_variant_new("(i)", result);
362 _bt_send_event(BT_LE_ADAPTER_EVENT,
363 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
370 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
374 ret_if(address == NULL);
377 bt_cache_info_t *cache_info;
378 bt_remote_dev_info_t *dev_info;
380 node = g_list_first(p_cache_list);
382 while (node != NULL) {
383 cache_info = (bt_cache_info_t *)node->data;
385 if (cache_info == NULL) {
386 node = g_list_next(node);
390 dev_info = cache_info->dev_info;
391 if (strcasecmp(dev_info->address,
393 BT_DBG("Device Found");
394 if (paired_status == TRUE)
395 cache_info->dev_info->paired = TRUE;
397 cache_info->dev_info->paired = FALSE;
400 node = g_list_next(node);
405 static void __bt_device_remote_connected_properties(
406 bt_remote_dev_info_t *remote_dev_info,
407 char *address, gboolean connected)
409 int result = BLUETOOTH_ERROR_NONE;
411 GVariant *param = NULL;
414 if (remote_dev_info->uuid_count > 0) {
415 for (i = 0; i < remote_dev_info->uuid_count; i++) {
416 char *uuid = remote_dev_info->uuids[i];
417 if (strcasecmp(uuid, HID_UUID) == 0) {
418 int event = BLUETOOTH_EVENT_NONE;
420 event = (connected == TRUE) ?
421 BLUETOOTH_HID_CONNECTED :
422 BLUETOOTH_HID_DISCONNECTED;
423 param = g_variant_new("(is)", result,
425 _bt_send_event(BT_HID_EVENT, event,
435 void _bt_handle_adapter_event(GVariant *msg, const char *member)
439 int result = BLUETOOTH_ERROR_NONE;
440 GVariant *param = NULL;
441 ret_if(member == NULL);
443 if (strcasecmp(member, "DeviceCreated") == 0) {
444 char *object_path = NULL;
446 bt_remote_dev_info_t *remote_dev_info;
448 ret_if(_bt_is_device_creating() == FALSE);
450 /* Bonding from remote device */
451 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
453 g_variant_get(msg, "(&o)", &object_path);
454 _bt_convert_device_path_to_address((const char*)object_path, address);
456 remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
457 if (remote_dev_info == NULL) {
462 _bt_free_device_info(remote_dev_info);
464 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
465 char *object_path = NULL;
467 bt_cache_info_t *cache_info;
468 bt_remote_dev_info_t *dev_info;
471 /* Bonding from remote device */
472 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
476 g_variant_get(msg, "(&o)", &object_path);
478 _bt_convert_device_path_to_address((const char *)object_path, address);
480 node = g_list_first(p_cache_list);
482 while (node != NULL) {
483 cache_info = (bt_cache_info_t *)node->data;
485 if (cache_info == NULL) {
486 node = g_list_next(node);
490 dev_info = cache_info->dev_info;
491 if (strcasecmp(dev_info->address,
493 p_cache_list = g_list_remove(p_cache_list,
495 __bt_free_cache_info(cache_info);
498 node = g_list_next(node);
501 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
502 BT_DBG("Advertising Enabled");
506 gboolean status = FALSE;
508 g_variant_get(msg, "(ib)", &slot_id, &status);
510 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
512 /* Send event to application */
513 _bt_set_advertising_status(slot_id, status);
515 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
518 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
520 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
521 param = g_variant_new("(ii)", result,
526 sender = _bt_get_adv_slot_owner(slot_id);
527 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
531 _bt_send_event(BT_ADAPTER_EVENT, event, param);
534 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
535 _bt_unregister_adv_slot_owner(slot_id);
536 } else if (strcasecmp(member, "RssiEnabled") == 0) {
537 BT_DBG("RSSI Enabled");
538 gboolean status = FALSE;
539 char *address = NULL;
541 g_variant_get(msg, "(sib)", &address, &link_type, &status);
543 BT_DBG("RSSI Enabled [%s %d]", address, status);
544 param = g_variant_new("(isib)", result,
545 address, link_type, status);
546 _bt_send_event(BT_DEVICE_EVENT,
547 BLUETOOTH_EVENT_RSSI_ENABLED,
550 } else if (strcasecmp(member, "RssiAlert") == 0) {
551 BT_DBG("RSSI Alert");
555 char *address = NULL;
556 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
558 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
559 address, alert_type, rssi_dbm);
560 param = g_variant_new("(isiii)", result,
561 address, link_type, alert_type, rssi_dbm);
562 _bt_send_event(BT_DEVICE_EVENT,
563 BLUETOOTH_EVENT_RSSI_ALERT,
566 } else if (strcasecmp(member, "RawRssi") == 0) {
570 char *address = NULL;
571 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
573 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
574 address, link_type, rssi_dbm);
575 param = g_variant_new("(isii)", result,
576 address, link_type, rssi_dbm);
577 _bt_send_event(BT_DEVICE_EVENT,
578 BLUETOOTH_EVENT_RAW_RSSI,
581 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
582 BT_ERR_C("Hardware error received from BLUEZ");
583 _bt_recover_adapter();
584 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
585 BT_ERR_C("Tx timeout error received from BLUEZ");
586 _bt_recover_adapter();
591 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
593 GDBusProxy *adapter_proxy;
595 int result = BLUETOOTH_ERROR_NONE;
596 GVariantIter value_iter;
597 GVariant *val = NULL;
598 GVariant *ret = NULL;
600 char *property = NULL;
601 GVariant *param = NULL;
602 g_variant_iter_init(&value_iter, msg);
603 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
604 BT_INFO("Property %s", property);
606 if (strcasecmp(property, "Discovering") == 0) {
607 gboolean discovering = FALSE;
608 g_variant_get(val, "b", &discovering);
609 /* Send event to application */
610 BT_DBG("Discovering %d", discovering);
611 if (discovering == TRUE) {
612 _bt_set_discovery_status(TRUE);
613 param = g_variant_new("(i)", result);
614 _bt_send_event(BT_ADAPTER_EVENT,
615 BLUETOOTH_EVENT_DISCOVERY_STARTED,
618 ret_if(event_id > 0);
620 adapter_proxy = _bt_get_adapter_proxy();
621 ret_if(adapter_proxy == NULL);
623 /* Need to stop searching */
624 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
626 G_DBUS_CALL_FLAGS_NONE,
630 BT_ERR("Dbus Error : %s", err->message);
634 g_variant_unref(ret);
636 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
637 (GSourceFunc)_bt_discovery_finished_cb, NULL);
639 } else if (strcasecmp(property, "LEDiscovering") == 0) {
640 gboolean le_discovering = FALSE;
642 g_variant_get(val, "b", &le_discovering);
643 /* Send event to application */
644 if (le_discovering == TRUE) {
645 _bt_set_le_scan_status(TRUE);
646 param = g_variant_new("(i)", result);
647 _bt_send_event(BT_LE_ADAPTER_EVENT,
648 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
651 ret_if(event_id > 0);
653 adapter_proxy = _bt_get_adapter_proxy();
654 ret_if(adapter_proxy == NULL);
656 /* Need to stop searching */
657 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
659 G_DBUS_CALL_FLAGS_NONE,
663 BT_ERR("Dbus Error %s", err->message);
667 g_variant_unref(ret);
669 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
670 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
672 } else if (strcasecmp(property, "Name") == 0) {
674 g_variant_get(val, "s", &name);
675 param = g_variant_new("(is)", result, name);
676 /* Send event to application */
677 _bt_send_event(BT_ADAPTER_EVENT,
678 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
681 } else if (strcasecmp(property, "Alias") == 0) {
683 g_variant_get(val, "s", &alias);
684 param = g_variant_new("(is)", result, alias);
685 /* Send event to application */
686 _bt_send_event(BT_ADAPTER_EVENT,
687 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
690 } else if (strcasecmp(property, "Discoverable") == 0) {
691 gboolean discoverable = FALSE;
693 g_variant_get(val, "b", &discoverable);
694 BT_DBG("discoverable %d", discoverable);
696 if (discoverable == FALSE) {
697 if (_bt_get_discoverable_timeout_property() > 0) {
699 adapter_proxy = _bt_get_adapter_properties_proxy();
700 ret_if(adapter_proxy == NULL);
701 ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
702 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
703 "DiscoverableTimeout",
704 g_variant_new("i", time)),
705 G_DBUS_CALL_FLAGS_NONE,
710 BT_ERR("StopLEDiscovery Failed: %s", err->message);
714 g_variant_unref(ret);
717 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
719 /* Send event to application */
720 BT_INFO("[Connectable]");
721 param = g_variant_new("(in)", result, mode);
722 _bt_send_event(BT_ADAPTER_EVENT,
723 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
726 _bt_get_discoverable_mode(&mode);
728 /* Event will be sent by "DiscoverableTimeout" signal */
729 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
731 g_variant_unref(val);
735 /* Send event to application */
736 BT_INFO("[General Discoverable]");
737 param = g_variant_new("(in)", result, mode);
738 _bt_send_event(BT_ADAPTER_EVENT,
739 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
742 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
743 _bt_get_discoverable_mode(&mode);
745 /* Event was already sent by "Discoverable" signal */
746 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
747 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
749 g_variant_unref(val);
753 /* Send event to application */
754 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
755 _bt_get_discoverable_timeout_property());
756 param = g_variant_new("(in)", result, mode);
757 _bt_send_event(BT_ADAPTER_EVENT,
758 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
760 } else if (strcasecmp(property, "Powered") == 0) {
761 /* TODO: Need to check this operation!! */
762 gboolean powered = FALSE;
765 g_variant_get(val, "b", &powered);
766 BT_DBG("Powered = %d", powered);
767 if (powered == FALSE) {
769 _bt_handle_adapter_removed();
771 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
772 bt_state != VCONFKEY_BT_STATUS_OFF) {
773 _bt_disable_adapter();
776 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
777 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
778 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
782 _bt_handle_adapter_added();
785 } else if (strcasecmp(property, "Connectable") == 0) {
786 gboolean connectable = FALSE;
788 g_variant_get(val, "b", &connectable);
790 BT_DBG("Connectable property is changed : %d", connectable);
791 param = g_variant_new("(b)", connectable);
792 _bt_send_event(BT_ADAPTER_EVENT,
793 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
796 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
797 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
799 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
801 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
804 GVariantIter *iter = NULL;
805 g_variant_get(val, "as", &iter);
806 while (g_variant_iter_loop(iter, "s", &name)) {
807 BT_DBG("name = %s", name);
808 g_variant_iter_loop(iter, "s", &value);
809 BT_DBG("Value = %s", value);
810 if (FALSE == _bt_update_le_feature_support(name, value))
811 BT_INFO("Fail to update LE feature info");
814 g_variant_iter_free(iter);
815 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
816 gboolean ipsp_initialized = FALSE;
818 g_variant_get(val, "b", &ipsp_initialized);
819 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
820 param = g_variant_new("(b)", ipsp_initialized);
822 /* Send event to application */
823 _bt_send_event(BT_ADAPTER_EVENT,
824 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
827 BT_DBG("property : [%s]", property);
832 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
836 GVariantIter value_iter;
837 GVariant *child = NULL, *val = NULL;
838 char *property = NULL;
839 g_variant_iter_init(&value_iter, msg);
840 while ((child = g_variant_iter_next_value(&value_iter))) {
841 g_variant_get(child, "{sv}", &property, &val);
843 ret_if(property == NULL);
845 BT_DBG("property :%s", property);
847 if (strcasecmp(property, "Status") == 0) {
849 g_variant_get(val, "s", &status);
851 if (strcasecmp(status, "active") == 0) {
852 _bt_obex_transfer_started(path);
853 } else if (strcasecmp(status, "complete") == 0) {
854 _bt_obex_transfer_completed(path, TRUE);
855 _bt_pbap_obex_transfer_completed(path, TRUE);
856 } else if (strcasecmp(status, "error") == 0) {
857 _bt_obex_transfer_completed(path, FALSE);
858 _bt_pbap_obex_transfer_completed(path, FALSE);
861 } else if (strcasecmp(property, "Transferred") == 0) {
862 guint64 transferred = 0;
863 /* As Transferred is expected guint64 so change int to guint64 and
864 * eariler transferred is static because of it can overwrite data
865 * on present on opc_obex_conn or obexd_conn as these are
866 * static memory are in sequential */
867 g_variant_get(val, "t", &transferred);
869 _bt_obex_transfer_progress(path, transferred);
872 g_variant_unref(val);
873 g_variant_unref(child);
878 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
883 int result = BLUETOOTH_ERROR_NONE;
884 GVariantIter value_iter;
886 char *property = NULL;
888 GVariant *param = NULL;
889 bt_remote_dev_info_t *remote_dev_info;
890 g_variant_iter_init(&value_iter, msg);
891 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
892 BT_DBG("Property %s", property);
893 if (strcasecmp(property, "Connected") == 0) {
896 g_variant_get(val, "i", &connected);
898 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
899 BLUETOOTH_EVENT_DEVICE_CONNECTED :
900 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
902 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
904 _bt_convert_device_path_to_address(path, address);
906 BT_DBG("connected: %d", connected);
907 BT_DBG("address: %s", address);
909 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
911 if (remote_dev_info != NULL) {
912 __bt_device_remote_connected_properties(
913 remote_dev_info, address,
914 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
916 _bt_free_device_info(remote_dev_info);
918 param = g_variant_new("(is)", result, address);
919 /* Send event to application */
920 _bt_send_event(BT_DEVICE_EVENT,
924 } else if (strcasecmp(property, "RSSI") == 0) {
925 bt_remote_dev_info_t *remote_dev_info;
927 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
929 _bt_convert_device_path_to_address(path, address);
930 BT_DBG("address: %s", address);
932 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
933 if (remote_dev_info == NULL) {
935 g_variant_unref(val);
939 BT_DBG("Address type %d", remote_dev_info->addr_type);
941 if (remote_dev_info->addr_type == 0) {
942 BT_DBG("Name %s", remote_dev_info->name);
944 #ifdef TIZEN_DPM_ENABLE
945 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
947 bluetooth_device_class_t device_class;
948 _bt_divide_device_class(&device_class, remote_dev_info->class);
950 if (device_class.major_class ==
951 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
952 _bt_free_device_info(remote_dev_info);
954 g_variant_unref(val);
961 GVariant *uuids = NULL;
962 GVariantBuilder *builder = NULL;
964 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
965 for (i = 0; i < remote_dev_info->uuid_count; i++) {
966 g_variant_builder_add(builder, "s",
967 remote_dev_info->uuids[i]);
969 uuids = g_variant_new("as", builder);
970 g_variant_builder_unref(builder);
971 GVariant *manufacturer_data = NULL;
972 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
973 remote_dev_info->manufacturer_data,
974 remote_dev_info->manufacturer_data_len,
977 param = g_variant_new("(isunsbub@asn@ay)", result,
978 remote_dev_info->address,
979 remote_dev_info->class,
980 remote_dev_info->rssi,
981 remote_dev_info->name,
982 remote_dev_info->paired,
983 remote_dev_info->connected,
984 remote_dev_info->trust,
986 remote_dev_info->manufacturer_data_len,
989 _bt_send_event(BT_ADAPTER_EVENT,
990 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
994 _bt_free_device_info(remote_dev_info);
995 } else if (strcasecmp(property, "GattConnected") == 0) {
996 gboolean gatt_connected = FALSE;
998 g_variant_get(val, "b", &gatt_connected);
1000 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1001 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1003 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1005 _bt_convert_device_path_to_address(path, address);
1007 BT_DBG("gatt_connected: %d", gatt_connected);
1008 BT_DBG("address: %s", address);
1009 param = g_variant_new("(is)", result, address);
1010 /* Send event to application */
1011 _bt_send_event(BT_DEVICE_EVENT,
1015 } else if (strcasecmp(property, "Paired") == 0) {
1016 gboolean paired = FALSE;
1017 bt_remote_dev_info_t *remote_dev_info;
1018 g_variant_get(val, "b", &paired);
1019 _bt_agent_set_canceled(FALSE);
1020 /* BlueZ sends paired signal for each paired device */
1021 /* during activation, We should ignore this, otherwise*/
1022 /* application thinks that a new device got paired */
1023 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1024 BT_DBG("BT is not activated, so ignore this");
1026 g_variant_unref(val);
1030 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1032 _bt_convert_device_path_to_address(path, address);
1034 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1035 if (remote_dev_info == NULL) {
1037 g_variant_unref(val);
1042 if (paired == FALSE) {
1043 BT_INFO("Unpaired: %s", address);
1044 __bt_update_remote_cache_devinfo(address, FALSE);
1045 param = g_variant_new("(is)", result, address);
1046 _bt_send_event(BT_ADAPTER_EVENT,
1047 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1049 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1051 char *last_connected = NULL;
1052 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1053 if (!g_strcmp0(address, last_connected))
1054 _bt_audio_set_auto_connect_device_addr("");
1056 free(last_connected);
1060 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1062 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1063 BT_INFO("### Paired: %s", secure_addr);
1064 __bt_update_remote_cache_devinfo(address, TRUE);
1066 if (_bt_is_device_creating() == TRUE) {
1067 BT_DBG("Try to Pair by me");
1068 _bt_free_device_info(remote_dev_info);
1071 g_variant_unref(val);
1074 GVariant *uuids = NULL;
1075 GVariantBuilder *builder = NULL;
1077 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1078 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1079 g_variant_builder_add(builder, "s",
1080 remote_dev_info->uuids[i]);
1082 uuids = g_variant_new("as", builder);
1083 g_variant_builder_unref(builder);
1084 GVariant *manufacturer_data = NULL;
1085 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1086 remote_dev_info->manufacturer_data,
1087 remote_dev_info->manufacturer_data_len,
1091 param = g_variant_new("(isunsbub@asn@ay)", result,
1092 address, remote_dev_info->class,
1093 remote_dev_info->rssi,
1094 remote_dev_info->name,
1095 remote_dev_info->paired,
1096 remote_dev_info->connected,
1097 remote_dev_info->trust,
1099 remote_dev_info->manufacturer_data_len,
1101 _bt_send_event(BT_ADAPTER_EVENT,
1102 BLUETOOTH_EVENT_BONDING_FINISHED,
1105 _bt_free_device_info(remote_dev_info);
1107 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1108 gboolean paired = FALSE;
1109 bt_remote_dev_info_t *remote_dev_info;
1110 unsigned char auth_info[5] = {0, };
1112 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1113 BT_DBG("BT is not activated, so ignore this");
1115 g_variant_unref(val);
1119 g_variant_get(val, "b", &paired);
1120 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1121 BT_DBG("LegacyPaired: %d", paired);
1122 _bt_convert_device_path_to_address(path, address);
1124 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1125 if (remote_dev_info == NULL) {
1128 g_variant_unref(val);
1131 if (remote_dev_info->is_alias_set == FALSE) {
1132 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1133 if ((remote_dev_info->manufacturer_data_len > 30) &&
1134 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1135 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1137 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1138 1 (discovery version) + 1 (associated service ID)
1139 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1141 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1145 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1146 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1147 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1149 _bt_free_device_info(remote_dev_info);
1151 } else if (strcasecmp(property, "Trusted") == 0) {
1152 gboolean trusted = FALSE;
1154 g_variant_get(val, "b", &trusted);
1156 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1157 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1159 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1161 _bt_convert_device_path_to_address(path, address);
1163 BT_DBG("trusted: %d", trusted);
1164 BT_DBG("address: %s", address);
1165 param = g_variant_new("(is)", result, address);
1166 /* Send event to application */
1167 _bt_send_event(BT_DEVICE_EVENT,
1171 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1174 g_variant_get(val, "u", &trusted);
1176 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1177 _bt_convert_device_path_to_address(path, address);
1179 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1180 _bt_send_event(BT_DEVICE_EVENT,
1181 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1182 g_variant_new("(isi)", result, address, trusted));
1184 } else if (strcasecmp(property, "IpspConnected") == 0) {
1185 gboolean connected = FALSE;
1187 g_variant_get(val, "b", &connected);
1190 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1191 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1193 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1195 _bt_convert_device_path_to_address(path, address);
1197 BT_DBG("Ipspconnected: %d", connected);
1198 BT_DBG("address: %s", address);
1199 param = g_variant_new("(is)", result, address);
1201 /* Send event to application */
1202 _bt_send_event(BT_DEVICE_EVENT,
1206 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1207 char *ifname = NULL;
1209 g_variant_get(val, "s", &ifname);
1211 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1213 _bt_convert_device_path_to_address(path, address);
1215 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1216 BT_DBG("address: %s", address);
1217 param = g_variant_new("(iss)", result, address, ifname);
1219 /* Send event to application */
1220 _bt_send_event(BT_DEVICE_EVENT,
1221 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1229 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1232 int result = BLUETOOTH_ERROR_NONE;
1233 GVariantIter value_iter;
1234 char *property = NULL;
1236 GVariant *val = NULL;
1237 GVariant *child = NULL;
1238 bt_remote_dev_info_t *remote_dev_info;
1239 GVariant *param = NULL;
1240 g_variant_iter_init(&value_iter, msg);
1241 while ((child = g_variant_iter_next_value(&value_iter))) {
1242 g_variant_get(child, "{sv}", &property, &val);
1243 BT_INFO("Property %s", property);
1244 if (strcasecmp(property, "Connected") == 0) {
1245 gboolean connected = FALSE;
1247 g_variant_get(val, "b", &connected);
1249 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1250 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1252 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1254 _bt_convert_device_path_to_address(path, address);
1256 BT_DBG("connected: %d", connected);
1257 BT_DBG("address: %s", address);
1259 remote_dev_info = _bt_get_remote_device_info(address);
1261 if (remote_dev_info != NULL) {
1262 __bt_device_remote_connected_properties(
1263 remote_dev_info, address, connected);
1264 _bt_free_device_info(remote_dev_info);
1266 param = g_variant_new("(is)", result, address);
1267 /* Send event to application */
1268 _bt_send_event(BT_AVRCP_EVENT,
1274 g_variant_unref(child);
1275 g_variant_unref(val);
1280 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1282 char *interface_name = NULL;
1283 GVariant *val = NULL;
1285 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1287 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1288 __bt_adapter_property_changed_event(val,
1290 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1291 __bt_device_property_changed_event(val, object_path);
1292 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1293 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1294 __bt_obex_property_changed_event(val,
1296 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1297 __bt_media_control_changed_event(val,
1299 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1300 _bt_handle_avrcp_control_event(val,
1302 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1303 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1304 _bt_handle_network_client_event(val,
1306 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1307 __bt_gatt_char_property_changed_event(val,
1310 g_variant_unref(val);
1313 void __bt_opc_property_changed_event(GVariant *msg,
1316 GVariantIter value_iter;
1317 char *property = NULL;
1318 GVariant *val = NULL;
1319 GVariant *child = NULL;
1321 g_variant_iter_init(&value_iter, msg);
1322 while ((child = g_variant_iter_next_value(&value_iter))) {
1323 g_variant_get(child, "{sv}", &property, &val);
1324 ret_if(property == NULL);
1326 if (strcasecmp(property, "Status") == 0) {
1327 char *status = NULL;
1328 g_variant_get(val, "s", &status);
1329 BT_DBG("Status is %s", status);
1331 if (strcasecmp(status, "active") == 0) {
1332 _bt_obex_client_started(path);
1333 } else if (strcasecmp(status, "complete") == 0) {
1334 _bt_obex_client_completed(path, TRUE);
1335 } else if (strcasecmp(status, "error") == 0) {
1336 _bt_obex_client_completed(path, FALSE);
1339 } else if (strcasecmp(property, "Transferred") == 0) {
1340 guint64 transferred = 0;
1341 g_variant_get(val, "t", &transferred);
1343 _bt_obex_client_progress(path, transferred);
1345 BT_DBG("property : [%s]", property);
1348 g_variant_unref(child);
1349 g_variant_unref(val);
1353 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1355 char *interface_name = NULL;
1356 GVariant *value = NULL;
1357 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1358 BT_INFO("interface_name = %s", interface_name);
1359 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1360 __bt_opc_property_changed_event(value,
1363 BT_DBG("interface_name : [%s]", interface_name);
1365 g_variant_unref(value);
1369 void _bt_handle_input_event(GVariant *msg, const char *path)
1371 int result = BLUETOOTH_ERROR_NONE;
1372 gboolean property_flag = FALSE;
1373 GVariantIter value_iter;
1374 char *property = NULL;
1375 GVariant *child = NULL, *val = NULL;
1376 bt_remote_dev_info_t *remote_dev_info;
1377 GVariant *param = NULL;
1378 g_variant_iter_init(&value_iter, msg);
1379 while ((child = g_variant_iter_next_value(&value_iter))) {
1380 g_variant_get(child, "{sv}", &property, &val);
1382 ret_if(property == NULL);
1384 if (strcasecmp(property, "Connected") == 0) {
1385 int event = BLUETOOTH_EVENT_NONE;
1387 g_variant_get(val, "b", &property_flag);
1389 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1391 _bt_convert_device_path_to_address(path, address);
1393 event = (property_flag == TRUE) ?
1394 BLUETOOTH_HID_CONNECTED :
1395 BLUETOOTH_HID_DISCONNECTED;
1396 param = g_variant_new("(is)", result, address);
1397 _bt_send_event(BT_HID_EVENT, event,
1399 /* Check HID connection type (Keyboard or Mouse) and update the status */
1400 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1402 if (property_flag == TRUE) {
1403 hid_connected_device_count++;
1404 __bt_set_device_values(TRUE,
1405 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1407 hid_connected_device_count--;
1408 if (hid_connected_device_count == 0)
1409 __bt_set_device_values(FALSE,
1410 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1413 if (remote_dev_info != NULL) {
1414 BT_DBG("HID device class [%x]", remote_dev_info->class);
1415 if (remote_dev_info->class &
1416 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1417 __bt_set_device_values(property_flag,
1418 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1422 if (remote_dev_info->class &
1423 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1424 __bt_set_device_values(property_flag,
1425 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1427 _bt_free_device_info(remote_dev_info);
1432 g_variant_unref(val);
1433 g_variant_unref(child);
1437 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1439 int result = BLUETOOTH_ERROR_NONE;
1440 char *address = NULL;
1441 char *device = NULL;
1442 GVariant *param = NULL;
1443 ret_if(member == NULL);
1444 if (strcasecmp(member, "PeerConnected") == 0) {
1445 g_variant_get(msg, "(ss)", &device, &address);
1447 __bt_set_device_values(TRUE,
1448 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1449 param = g_variant_new("(iss)", result, device, address);
1450 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1454 nap_connected_device_count++;
1455 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1456 g_variant_get(msg, "(ss)", &device, &address);
1457 nap_connected_device_count--;
1458 if (nap_connected_device_count == 0)
1459 __bt_set_device_values(FALSE,
1460 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1461 param = g_variant_new("(iss)", result, device, address);
1462 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1469 void _bt_handle_network_client_event(GVariant *msg,
1474 int result = BLUETOOTH_ERROR_NONE;
1475 gboolean property_flag = FALSE;
1476 char *property = NULL;
1477 GVariant *val = NULL;
1478 GVariantIter value_iter;
1479 GVariant *param = NULL;
1480 g_variant_iter_init(&value_iter, msg);
1481 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1482 if (strcasecmp(property, "Connected") == 0) {
1483 int event = BLUETOOTH_EVENT_NONE;
1486 g_variant_get(val, "b", &property_flag);
1487 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1489 _bt_convert_device_path_to_address(path, address);
1491 BT_DBG("property_flag %d", property_flag);
1492 if (property_flag == TRUE) {
1493 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1494 nap_connected_device_count++;
1495 __bt_set_device_values(TRUE,
1496 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1498 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1499 nap_connected_device_count--;
1500 if (nap_connected_device_count == 0)
1501 __bt_set_device_values(FALSE,
1502 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1504 param = g_variant_new("(is)", result, address);
1505 _bt_send_event(BT_NETWORK_EVENT, event,
1514 void __bt_gatt_char_property_changed_event(GVariant *msg,
1517 GVariantIter value_iter;
1518 char *property = NULL;
1519 char * char_handle = NULL;
1520 GVariant *val = NULL;
1521 int result = BLUETOOTH_ERROR_NONE;
1522 GVariant *param = NULL;
1523 g_variant_iter_init(&value_iter, msg);
1524 char_handle = g_strdup(path);
1525 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1526 BT_INFO("Property %s", property);
1528 ret_if(property == NULL);
1530 if (strcasecmp(property, "Notifying") == 0) {
1531 gboolean property_flag = FALSE;
1532 g_variant_get(val, "b", &property_flag);
1533 if (property_flag == TRUE)
1534 BT_DBG("notifying is enabled");
1536 BT_DBG("notifying is disabled");
1537 } else if (strcasecmp(property, "ChangedValue") == 0) {
1539 GByteArray *gp_byte_array = NULL;
1540 BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
1543 gp_byte_array = g_byte_array_new();
1544 len = g_variant_get_size(val);
1545 BT_DBG("Len = %d", len);
1546 g_byte_array_append(gp_byte_array,
1547 (const guint8 *) g_variant_get_data(val), len);
1548 if (gp_byte_array->len != 0) {
1549 GVariant *byte_array = NULL;
1550 byte_array = g_variant_new_from_data(
1551 G_VARIANT_TYPE_BYTESTRING,
1552 gp_byte_array->data,
1555 param = g_variant_new("(is@ay)", result, char_handle,
1558 /* Send event only registered client */
1559 _bt_send_char_value_changed_event(param);
1561 g_byte_array_free(gp_byte_array, TRUE);
1565 g_free(char_handle);
1568 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1570 ret_if(path == NULL);
1572 if (strcasecmp(member, "GattValueChanged") == 0) {
1575 /*** Debug only ***/
1576 GVariant *value = NULL;
1578 char *buffer = NULL;
1580 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1581 value_len = g_variant_get_size(value);
1582 if (value_len > 0) {
1583 char buf[8 * 5 + 1] = { 0 };
1586 buffer = (char *)g_variant_get_data(value);
1587 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1589 for (i = 0; i < to; i++)
1590 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1592 BT_DBG("GATT Val[%d] %s", value_len, buf);
1594 g_variant_unref(value);
1598 /* Send event only registered client */
1599 _bt_send_char_value_changed_event(msg);
1604 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1607 int result = BLUETOOTH_ERROR_NONE;
1609 char *dev_name = NULL;
1610 const char *property = NULL;
1611 GVariant *param = NULL;
1612 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1613 ret_if(path == NULL);
1615 if (strcasecmp(member, "PropertyChanged") == 0) {
1617 g_variant_get(msg, "(s)", &property);
1619 ret_if(property == NULL);
1621 if (strcasecmp(property, "GattConnected") == 0) {
1622 gboolean connected = FALSE;
1624 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1625 ret_if(address == NULL);
1627 _bt_convert_device_path_to_address(path, address);
1628 g_variant_get(msg, "(b)", &connected);
1630 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1631 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1632 param = g_variant_new("(is)", result, address);
1633 _bt_send_event(BT_DEVICE_EVENT,
1637 } else if (strcasecmp(property, "Paired") == 0) {
1638 gboolean paired = FALSE;
1639 bt_remote_dev_info_t *remote_dev_info;
1640 g_variant_get(msg, "(b)", &paired);
1642 ret_if(paired == FALSE);
1644 /* BlueZ sends paired signal for each paired device */
1645 /* during activation, We should ignore this, otherwise*/
1646 /* application thinks that a new device got paired */
1647 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1648 BT_DBG("BT is not activated, so ignore this");
1652 if (_bt_is_device_creating() == TRUE) {
1653 BT_DBG("Try to Pair by me");
1657 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1658 ret_if(address == NULL);
1660 _bt_convert_device_path_to_address(path, address);
1662 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1663 if (remote_dev_info == NULL) {
1667 GVariant *uuids = NULL;
1668 GVariantBuilder *builder = NULL;
1670 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1671 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1672 g_variant_builder_add(builder, "s",
1673 remote_dev_info->uuids[i]);
1675 uuids = g_variant_new("as", builder);
1676 g_variant_builder_unref(builder);
1677 GVariant *manufacturer_data = NULL;
1678 manufacturer_data = g_variant_new_from_data(
1679 G_VARIANT_TYPE_BYTESTRING,
1680 remote_dev_info->manufacturer_data,
1681 remote_dev_info->manufacturer_data_len,
1683 param = g_variant_new("(isunsbub@asn@ay)", result,
1685 remote_dev_info->class,
1686 remote_dev_info->rssi,
1687 remote_dev_info->name,
1688 remote_dev_info->paired,
1689 remote_dev_info->connected,
1690 remote_dev_info->trust,
1692 remote_dev_info->manufacturer_data_len,
1694 _bt_send_event(BT_ADAPTER_EVENT,
1695 BLUETOOTH_EVENT_BONDING_FINISHED,
1697 _bt_free_device_info(remote_dev_info);
1700 } else if (strcasecmp(property, "UUIDs") == 0) {
1701 /* Once we get the updated uuid information after
1702 * reverse service search, update it to application */
1704 bt_remote_dev_info_t *remote_dev_info;
1706 ret_if(_bt_is_device_creating() == TRUE);
1708 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1709 ret_if(address == NULL);
1711 _bt_convert_device_path_to_address(path, address);
1713 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1714 if (remote_dev_info == NULL) {
1719 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1720 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1721 GVariant *uuids = NULL;
1722 GVariantBuilder *builder = NULL;
1724 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1725 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1726 g_variant_builder_add(builder, "s",
1727 remote_dev_info->uuids[i]);
1729 uuids = g_variant_new("as", builder);
1730 g_variant_builder_unref(builder);
1731 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1732 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1735 param = g_variant_new("(isunsbub@asn@ay)", result,
1736 address, remote_dev_info->class,
1737 remote_dev_info->rssi,
1738 remote_dev_info->name,
1739 remote_dev_info->paired,
1740 remote_dev_info->connected,
1741 remote_dev_info->trust,
1743 remote_dev_info->manufacturer_data_len,
1745 _bt_send_event(BT_ADAPTER_EVENT,
1746 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1750 _bt_free_device_info(remote_dev_info);
1753 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1754 unsigned char addr_type = 0;
1756 g_variant_get(msg, "(y)", &addr_type);
1758 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1759 ret_if(address == NULL);
1761 _bt_convert_device_path_to_address(path, address);
1762 dev_name = _bt_get_bonded_device_name(address);
1764 _bt_convert_addr_string_to_secure_string(secure_address, address);
1765 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1766 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1767 !addr_type ? dev_name : secure_address);
1770 _bt_logging_connection(TRUE, addr_type);
1771 param = g_variant_new("(isy)", result, address, addr_type);
1772 /*Send event to application*/
1773 _bt_send_event(BT_DEVICE_EVENT,
1774 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1777 } else if (strcasecmp(member, "Disconnected") == 0) {
1778 unsigned char disc_reason = 0;
1779 unsigned char addr_type = 0;
1780 char *dev_name = NULL;
1781 gboolean sending = FALSE;
1783 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1785 result = disc_reason;
1787 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1788 ret_if(address == NULL);
1790 _bt_convert_device_path_to_address(path, address);
1792 /* 0x00 BDADDR_BRDER
1793 0x01 BDADDR_LE_PUBLIC
1794 0x02 BDADDR_LE_RANDOM */
1795 _bt_convert_addr_string_to_secure_string(secure_address, address);
1796 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1797 BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1798 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1799 !addr_type ? dev_name : secure_address);
1802 _bt_headset_set_local_connection(FALSE);
1803 _bt_logging_connection(FALSE, addr_type);
1806 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1808 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1810 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1811 BT_ERR("vconf_get_int failed");
1813 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1814 bt_device_state, _bt_adapter_get_status());
1816 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1817 _bt_audio_start_auto_connect(TRUE);
1818 } else if (bt_device_state &
1819 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1820 BT_INFO("Disconnected due to turning BT off. Skip a address");
1822 char *last_connected = NULL;
1823 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1824 if (!g_strcmp0(address, last_connected))
1825 _bt_audio_set_auto_connect_device_addr("");
1827 free(last_connected);
1832 /*Check for any OPP transfer on the device and cancel
1835 _bt_obex_check_pending_transfer(address);
1836 _bt_opp_client_is_sending(&sending);
1838 _bt_opp_client_check_pending_transfer(address);
1840 param = g_variant_new("(isy)", result, address, addr_type);
1841 _bt_send_event(BT_DEVICE_EVENT,
1842 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1845 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1847 char *profile_uuid = NULL;
1848 bt_headset_wait_t *wait_list;
1849 bluetooth_device_address_t bd_addr;
1851 g_variant_get(msg, "(si)", &profile_uuid, &state);
1853 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1854 ret_if(address == NULL);
1856 _bt_convert_device_path_to_address(path, address);
1857 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1859 _bt_convert_addr_string_to_secure_string(secure_address, address);
1860 BT_DBG("Address: %s", secure_address);
1861 BT_DBG("Profile UUID: %s", profile_uuid);
1862 BT_DBG("State: %d", state);
1864 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1865 (state == BT_PROFILE_STATE_CONNECTED)) {
1867 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1868 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1869 bluetooth_device_address_t device_address;
1871 bt_headset_wait_t *wait_list;
1872 guint restricted = 0x0;
1874 __bt_set_device_values(TRUE,
1875 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1877 __bt_connection_manager_set_state(address, event);
1879 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
1881 if (_bt_headset_get_local_connection() == FALSE) {
1882 if (restricted == 0x0) /* not restricted*/
1883 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1885 /* Connection Started from local device therefore no need to
1886 * intiate connection for pending profile */
1887 _bt_headset_set_local_connection(FALSE);
1889 param = g_variant_new("(is)", result, address);
1890 _bt_send_event(BT_HEADSET_EVENT, event,
1892 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1895 if (g_strcmp0(connected_address, address) != 0) {
1896 _bt_convert_addr_string_to_type(
1897 device_address.addr,
1899 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1900 &device_address, NULL);
1904 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1905 BT_STATE_CONNECTED, address);
1907 wait_list = _bt_get_audio_wait_data();
1908 if (wait_list != NULL &&
1909 (g_strcmp0(wait_list->address, address) == 0))
1910 _bt_rel_wait_data();
1912 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1913 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1915 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1917 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1919 g_free(profile_uuid);
1923 __bt_set_device_values(FALSE,
1924 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1926 __bt_connection_manager_set_state(address, event);
1927 param = g_variant_new("(is)", result, address);
1928 _bt_send_event(BT_HEADSET_EVENT, event,
1930 /* Remove data from the connected list */
1931 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1932 wait_list = _bt_get_audio_wait_data();
1934 if (wait_list == NULL) {
1936 g_free(profile_uuid);
1940 if (((wait_list->type == BT_AUDIO_ALL) &&
1941 (wait_list->ag_flag == TRUE)) ||
1942 (wait_list->type == BT_AUDIO_A2DP) ||
1943 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1944 bluetooth_device_address_t device_address;
1945 _bt_convert_addr_string_to_type(
1946 device_address.addr,
1947 wait_list->address);
1949 _bt_audio_connect(wait_list->req_id,
1952 wait_list->out_param1);
1954 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1956 if (state == BT_PROFILE_STATE_CONNECTED) {
1957 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1958 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1959 bluetooth_device_address_t device_address;
1961 param = g_variant_new("(is)", result, address);
1962 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1964 connected = _bt_is_headset_type_connected(
1968 if (g_strcmp0(connected_address,
1970 _bt_convert_addr_string_to_type(
1971 device_address.addr,
1973 _bt_audio_disconnect(0,
1975 &device_address, NULL);
1978 BT_DBG("device Path: %s", path);
1979 _bt_add_headset_to_list(BT_AVRCP,
1980 BT_STATE_CONNECTED, address);
1981 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1982 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1983 param = g_variant_new("(is)", result, address);
1984 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1986 /* Remove data from the connected list */
1987 _bt_remove_headset_from_list(BT_AVRCP, address);
1989 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1990 if (state == BT_PROFILE_STATE_CONNECTED) {
1991 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1992 BT_INFO("A2DP Source is connected");
1993 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
1994 __bt_set_device_values(TRUE,
1995 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
1998 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1999 _bt_audio_set_auto_connect_device_addr(address);
2000 _bt_audio_stop_auto_connect();
2002 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2003 BT_STATE_CONNECTED, address);
2004 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2005 g_variant_new("(is)", result, address));
2006 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2007 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2008 BT_INFO("A2DP Source Disconnected");
2009 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2010 __bt_set_device_values(FALSE,
2011 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2013 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2014 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2015 g_variant_new("(is)", result, address));
2017 wait_list = _bt_get_audio_wait_data();
2018 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2019 bluetooth_device_address_t device_address;
2020 _bt_convert_addr_string_to_type(
2021 device_address.addr,
2022 wait_list->address);
2024 _bt_audio_connect(wait_list->req_id,
2027 wait_list->out_param1);
2028 /* Now free the wait list */
2029 _bt_rel_wait_data();
2032 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2033 ((state == BT_PROFILE_STATE_CONNECTED) ||
2034 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2036 if (state == BT_PROFILE_STATE_CONNECTED)
2037 event = BLUETOOTH_HID_CONNECTED;
2039 event = BLUETOOTH_HID_DISCONNECTED;
2040 param = g_variant_new("(is)", result, address);
2041 _bt_send_event(BT_HID_EVENT, event,
2043 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2044 if (state == BT_PROFILE_STATE_CONNECTED) {
2046 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2047 param = g_variant_new("(is)", result, address);
2048 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2050 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2051 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2052 param = g_variant_new("(is)", result, address);
2053 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2058 g_free(profile_uuid);
2059 } else if (strcasecmp(member, "AdvReport") == 0) {
2061 bt_remote_le_dev_info_t *le_dev_info = NULL;
2062 char *buffer = NULL;
2064 bt_le_adv_info_t *adv_info = NULL;
2065 GVariant *value = NULL;
2066 ret_if(_bt_is_le_scanning() == FALSE);
2068 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2069 if (le_dev_info == NULL)
2072 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
2073 &le_dev_info->addr_type,
2074 &le_dev_info->adv_type,
2076 &le_dev_info->adv_data_len,
2078 _bt_convert_device_path_to_address(path, le_dev_info->address);
2080 buffer_len = g_variant_get_size(value);
2082 buffer = (char *)g_variant_get_data(value);
2084 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2085 if (le_dev_info->adv_data == NULL &&
2086 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2087 _bt_free_le_device_info(le_dev_info);
2088 g_variant_unref(value);
2092 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2093 _bt_send_scan_result_event(le_dev_info, NULL);
2094 _bt_free_le_device_info(le_dev_info);
2095 g_variant_unref(value);
2099 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2100 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2101 if (adv_info == NULL) {
2102 _bt_free_le_device_info(le_dev_info);
2103 g_variant_unref(value);
2107 adv_info->addr = g_strdup(le_dev_info->address);
2108 adv_info->addr_type = le_dev_info->addr_type;
2109 adv_info->rssi = le_dev_info->rssi;
2110 adv_info->data_len = le_dev_info->adv_data_len;
2111 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2112 if (adv_info->data) {
2113 memcpy(adv_info->data, le_dev_info->adv_data,
2114 le_dev_info->adv_data_len);
2117 if (__bt_add_adv_ind_info(adv_info) == 0) {
2118 adv_info->timer_id = g_timeout_add(1000,
2119 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2121 } else { /* SCAN_RSP */
2122 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2124 _bt_send_scan_result_event(le_dev_info, adv_info);
2125 __bt_del_adv_ind_info(le_dev_info->address);
2128 _bt_free_le_device_info(le_dev_info);
2129 g_variant_unref(value);
2130 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2131 guint16 tx_octets = 0;
2132 guint16 tx_time = 0;
2133 guint16 rx_octets = 0;
2134 guint16 rx_time = 0;
2136 g_variant_get(msg, "(qqqq)",
2137 &tx_octets, &tx_time, &rx_octets, &rx_time);
2139 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2140 _bt_convert_device_path_to_address(path, address);
2142 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2143 rx_octets, rx_time);
2144 /* Send event to application */
2145 _bt_send_event(BT_DEVICE_EVENT,
2146 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2148 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2149 gboolean connected = FALSE;
2150 char *ifname = NULL;
2152 g_variant_get(msg, "(bs)", &connected, &ifname);
2154 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2155 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2157 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2158 _bt_convert_device_path_to_address(path, address);
2160 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2161 BT_DBG("address: %s", address);
2162 param = g_variant_new("(iss)", result, address, ifname);
2164 /* Send event to application */
2165 _bt_send_event(BT_DEVICE_EVENT,
2173 void __bt_set_audio_values(gboolean connected, char *address)
2176 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2178 /* Set the headset name */
2179 if (connected == TRUE) {
2180 name = _bt_get_bonded_device_name(address);
2182 name = g_strdup("");
2185 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
2187 BT_ERR("vconf_set_str failed");
2192 /* Set the headset state */
2193 if (vconf_get_int(VCONFKEY_BT_DEVICE,
2194 &bt_device_state) != 0) {
2195 BT_ERR("vconf_get_int failed");
2198 #ifdef TIZEN_SUPPORT_DUAL_HF
2199 if ((connected == TRUE) &&
2200 (FALSE == __bt_is_companion_device(address))) {
2201 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2202 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2203 (FALSE == __bt_is_companion_device(address))) {
2204 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2207 if (connected == TRUE) {
2208 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2209 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
2210 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2214 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2215 bt_device_state) != 0) {
2216 BT_ERR("vconf_set_int failed");
2220 void _bt_handle_headset_event(GVariant *msg, const char *path)
2222 int result = BLUETOOTH_ERROR_NONE;
2223 gboolean property_flag = FALSE;
2224 char *property = NULL;
2225 GVariant *value = NULL;
2226 GVariant *param = NULL;
2227 g_variant_get(msg, "(sv)", &property, &value);
2228 bluetooth_device_address_t bd_addr;
2230 ret_if(property == NULL);
2232 BT_DBG("Property = %s \n", property);
2233 /* We allow only 1 headset connection (HSP or HFP)*/
2234 if (strcasecmp(property, "Connected") == 0) {
2235 int event = BLUETOOTH_EVENT_NONE;
2236 bt_headset_wait_t *wait_list;
2238 guint restricted = 0x0;
2239 g_variant_get(value, "b", &property_flag);
2241 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2242 if (address == NULL)
2245 _bt_convert_device_path_to_address(path, address);
2246 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2248 if (property_flag == TRUE) {
2249 event = BLUETOOTH_EVENT_AG_CONNECTED;
2250 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2252 if (_bt_headset_get_local_connection() == FALSE) {
2253 if (restricted == 0x0) /* not restricted*/
2254 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2256 _bt_headset_set_local_connection(FALSE);
2260 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2262 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2263 if (previous_state == BT_STATE_DISCONNECTING)
2264 _bt_send_hf_local_term_event(address);
2266 /* Set the State machine here */
2267 __bt_connection_manager_set_state(address, event);
2268 __bt_set_audio_values(property_flag, address);
2269 param = g_variant_new("(is)", result, address);
2270 _bt_send_event(BT_HEADSET_EVENT, event,
2273 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2274 /* Remove data from the connected list */
2275 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2277 wait_list = _bt_get_audio_wait_data();
2278 if (wait_list == NULL) {
2283 bluetooth_device_address_t device_address;
2285 _bt_set_audio_wait_data_flag(TRUE);
2287 _bt_convert_addr_string_to_type(device_address.addr,
2288 wait_list->address);
2289 _bt_audio_connect(wait_list->req_id, wait_list->type,
2290 &device_address, wait_list->out_param1);
2291 _bt_rel_wait_data();
2292 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2293 /* Add data to the connected list */
2294 _bt_add_headset_to_list(BT_AUDIO_HSP,
2295 BT_STATE_CONNECTED, address);
2297 wait_list = _bt_get_audio_wait_data();
2298 if (wait_list != NULL &&
2299 (g_strcmp0(wait_list->address, address) == 0))
2300 _bt_rel_wait_data();
2302 BT_INFO("Check A2DP pending connect");
2303 _bt_audio_check_pending_connect();
2306 } else if (strcasecmp(property, "State") == 0) {
2309 g_variant_get(value, "s", &state);
2311 /* This code assumes we support only 1 headset connection */
2312 /* Need to use the headset list, if we support multi-headsets */
2313 if (strcasecmp(state, "Playing") == 0) {
2314 BT_DBG("Playing: Sco Connected");
2315 } else if (strcasecmp(state, "connected") == 0 ||
2316 strcasecmp(state, "disconnected") == 0) {
2317 BT_DBG("connected/disconnected: Sco Disconnected");
2319 BT_ERR("Not handled state - %s", state);
2324 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2328 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2330 _bt_convert_device_path_to_address(path, address);
2332 spkr_gain = g_variant_get_uint16(value);
2334 BT_DBG("spkr_gain: %d", spkr_gain);
2336 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2337 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2341 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2345 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2347 _bt_convert_device_path_to_address(path, address);
2349 mic_gain = g_variant_get_uint16(value);
2351 param = g_variant_new("(i&sq)", result, address, mic_gain);
2352 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2359 g_variant_unref(value);
2362 void _bt_handle_sink_event(GVariant *msg, const char *path)
2364 GVariantIter value_iter;
2365 char *property = NULL;
2367 bt_headset_wait_t *wait_list;
2369 GVariant *child = NULL;
2370 GVariant *val = NULL;
2371 GVariant *param = NULL;
2372 g_variant_iter_init(&value_iter, msg);
2373 while ((child = g_variant_iter_next_value(&value_iter))) {
2375 g_variant_get(child, "{sv}", &property, &val);
2377 ret_if(property == NULL);
2379 BT_DBG("Property = %s \n", property);
2382 if (strcasecmp(property, "State") == 0) {
2383 int result = BLUETOOTH_ERROR_NONE;
2386 g_variant_get(val, "s", &value);
2387 BT_DBG("value: %s", value);
2389 if (g_strcmp0(value, "disconnected") == 0) {
2392 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2394 _bt_convert_device_path_to_address(path, address);
2396 __bt_set_device_values(FALSE,
2397 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2398 param = g_variant_new("(is)", result, address);
2399 _bt_send_event(BT_HEADSET_EVENT,
2400 BLUETOOTH_EVENT_AV_DISCONNECTED,
2403 /* Remove data from the connected list */
2404 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2405 wait_list = _bt_get_audio_wait_data();
2406 if (wait_list == NULL) {
2409 g_variant_unref(val);
2410 g_variant_unref(child);
2415 if (((wait_list->type == BT_AUDIO_ALL) &&
2416 (wait_list->ag_flag == TRUE)) ||
2417 (wait_list->type == BT_AUDIO_A2DP) ||
2418 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2419 bluetooth_device_address_t device_address;
2420 _bt_convert_addr_string_to_type(
2421 device_address.addr,
2422 wait_list->address);
2424 _bt_audio_connect(wait_list->req_id,
2427 wait_list->out_param1);
2430 } else if (strcasecmp(value, "Connected") == 0) {
2432 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2433 bluetooth_device_address_t device_address;
2436 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2438 _bt_convert_device_path_to_address(path, address);
2440 __bt_set_device_values(TRUE,
2441 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2442 param = g_variant_new("(is)", result, address);
2443 _bt_send_event(BT_HEADSET_EVENT,
2444 BLUETOOTH_EVENT_AV_CONNECTED,
2446 /* Check for existing Media device to disconnect */
2447 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2450 /* Match connected device address */
2451 if (g_strcmp0(connected_address, address) != 0) {
2452 /* Convert BD adress from string type */
2453 _bt_convert_addr_string_to_type(
2454 device_address.addr,
2456 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2457 &device_address, NULL);
2461 /* Add data to the connected list */
2462 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2463 BT_STATE_CONNECTED, address);
2470 g_variant_unref(val);
2471 g_variant_unref(child);
2475 void _bt_handle_agent_event(GVariant *msg, const char *member)
2477 int result = BLUETOOTH_ERROR_NONE;
2478 char *address = NULL;
2481 GVariant *param = NULL;
2482 ret_if(member == NULL);
2484 if (strcasecmp(member, "ObexAuthorize") == 0) {
2485 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2486 param = g_variant_new("(iss)", result, address, name);
2487 _bt_send_event(BT_OPP_SERVER_EVENT,
2488 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2492 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2493 bt_rfcomm_server_info_t *server_info;
2495 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2497 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2498 ret_if(server_info == NULL);
2499 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2500 param = g_variant_new("(isssn)", result, address, uuid, name,
2501 server_info->control_fd);
2502 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2503 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2511 static int __bt_get_object_path(GVariant *msg, char **path)
2513 g_variant_get(msg, "(o*)", path, NULL);
2515 return BLUETOOTH_ERROR_INTERNAL;
2517 return BLUETOOTH_ERROR_NONE;
2520 static void __bt_devices_list_free(void)
2522 bt_cache_info_t *cache_info;
2525 node = g_list_first(p_cache_list);
2527 while (node != NULL) {
2528 cache_info = (bt_cache_info_t *)node->data;
2529 p_cache_list = g_list_remove(p_cache_list, cache_info);
2530 __bt_free_cache_info(cache_info);
2532 node = g_list_next(node);
2536 static int __bt_parse_event(GVariant *msg)
2540 char *interface_name = NULL;
2541 GVariant *inner_iter = NULL;
2543 g_variant_iter_init(&iter, msg);
2545 while ((child = g_variant_iter_next_value(&iter))) {
2546 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2547 if (g_strcmp0(interface_name,
2548 BT_DEVICE_INTERFACE) == 0) {
2549 g_variant_unref(inner_iter);
2550 g_variant_unref(child);
2551 return BT_DEVICE_EVENT;
2552 } else if (g_strcmp0(interface_name,
2553 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2554 g_variant_unref(inner_iter);
2555 g_variant_unref(child);
2556 return BT_MEDIA_TRANSFER_EVENT;
2557 } else if (g_strcmp0(interface_name,
2558 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2559 g_variant_unref(inner_iter);
2560 g_variant_unref(child);
2561 return BT_AVRCP_CONTROL_EVENT;
2563 g_variant_unref(inner_iter);
2564 g_variant_unref(child);
2570 static void __bt_manager_event_filter(GDBusConnection *connection,
2571 const gchar *sender_name,
2572 const gchar *object_path,
2573 const gchar *interface_name,
2574 const gchar *signal_name,
2575 GVariant *parameters,
2578 bt_event_type_t bt_event = 0x00;
2579 int result = BLUETOOTH_ERROR_NONE;
2581 char *obj_path = NULL;
2582 GVariant *param = NULL;
2583 if (signal_name == NULL)
2585 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2586 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2588 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2589 #ifdef USB_BLUETOOTH
2590 BT_DBG("Enable Adapter");
2591 _bt_enable_adapter();
2593 _bt_handle_adapter_added();
2596 bt_event = __bt_parse_event(value);
2597 if (bt_event == BT_DEVICE_EVENT) {
2598 bt_cache_info_t *cache_info;
2599 bt_remote_dev_info_t *dev_info;
2601 ret_if(_bt_is_discovering() == FALSE &&
2602 _bt_is_le_scanning() == FALSE);
2604 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2605 ret_if(cache_info == NULL);
2607 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2608 if (dev_info == NULL) {
2609 __bt_free_cache_info(cache_info);
2613 cache_info->dev_info = dev_info;
2615 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2616 BT_ERR("Fail to parse the properies");
2617 __bt_free_cache_info(cache_info);
2618 g_variant_unref(value);
2622 if (dev_info->addr_type != BDADDR_BREDR) {
2623 /* Whenever emit the property changed from bluez,
2624 some property doesn't reach to bt-service.
2625 So LE device is handled as AdvReport signal */
2626 __bt_free_cache_info(cache_info);
2627 g_variant_unref(value);
2631 if (dev_info->name == NULL)
2632 /* If Remote device name is NULL or still RNR is not done
2633 * then display address as name.
2635 dev_info->name = g_strdup(dev_info->address);
2637 #ifdef TIZEN_DPM_ENABLE
2638 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
2640 bluetooth_device_class_t device_class;
2641 _bt_divide_device_class(&device_class, dev_info->class);
2642 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2644 if (device_class.major_class ==
2645 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2646 __bt_free_cache_info(cache_info);
2647 g_variant_unref(value);
2653 GVariant *uuids = NULL;
2654 GVariantBuilder *builder = NULL;
2656 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2657 for (i = 0; i < dev_info->uuid_count; i++) {
2658 g_variant_builder_add(builder, "s",
2659 dev_info->uuids[i]);
2661 uuids = g_variant_new("as", builder);
2662 g_variant_builder_unref(builder);
2663 GVariant *manufacturer_data = NULL;
2664 manufacturer_data = g_variant_new_from_data(
2665 G_VARIANT_TYPE_BYTESTRING,
2666 dev_info->manufacturer_data,
2667 dev_info->manufacturer_data_len,
2669 param = g_variant_new("(isunsbub@asn@ay)", result,
2675 dev_info->connected,
2678 dev_info->manufacturer_data_len,
2680 _bt_send_event(BT_ADAPTER_EVENT,
2681 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2683 p_cache_list = g_list_append(p_cache_list, cache_info);
2684 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2685 BT_DBG("Device path : %s ", obj_path);
2686 _bt_set_control_device_path(obj_path);
2689 g_variant_unref(value);
2690 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2691 #ifdef USB_BLUETOOTH
2692 BT_DBG("InterfacesRemoved");
2693 _bt_handle_adapter_removed();
2695 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2696 bt_event = BT_MEDIA_TRANSFER_EVENT;
2697 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2698 bt_event = BT_DEVICE_EVENT;
2699 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2700 bt_event = BT_AVRCP_CONTROL_EVENT;
2702 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2703 _bt_handle_adapter_event(parameters, signal_name);
2704 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2705 BT_INFO("Object Path %s", obj_path);
2706 _bt_remove_control_device_path(obj_path);
2709 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2712 char *previous = NULL;
2713 char *current = NULL;
2715 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2716 BT_ERR("Fail to get the owner info");
2720 if (*current != '\0') {
2729 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2730 BT_DBG("Bluetoothd is terminated");
2731 if (_bt_adapter_get_status() == BT_ACTIVATED)
2734 _bt_handle_adapter_removed();
2735 __bt_devices_list_free();
2738 _bt_obex_server_check_allocation(&value);
2740 if (value == TRUE) {
2741 /* Check if the obex server was terminated abnormally */
2742 _bt_obex_server_check_termination(name);
2745 _bt_rfcomm_server_check_existence(&value);
2747 if (value == TRUE) {
2748 /* The obex server was terminated abnormally */
2749 _bt_rfcomm_server_check_termination(name);
2752 /* Stop advertising started by terminated process */
2753 _bt_stop_advertising_by_terminated_process(name);
2755 _bt_stop_le_scan(name);
2759 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2760 const char *path = object_path;
2762 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2763 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2766 _bt_handle_property_changed_event(parameters, object_path);
2767 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2768 _bt_handle_adapter_event(parameters, signal_name);
2769 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2770 _bt_handle_input_event(parameters, object_path);
2771 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2772 _bt_handle_network_server_event(parameters, signal_name);
2773 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2774 _bt_handle_headset_event(parameters, object_path);
2775 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2776 _bt_handle_sink_event(parameters, object_path);
2777 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2778 _bt_handle_agent_event(parameters, signal_name);
2779 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2780 _bt_handle_device_event(parameters, signal_name, object_path);
2781 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2782 _bt_handle_gatt_event(parameters, signal_name, object_path);
2788 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2791 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2792 char *interface_name = NULL;
2794 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2795 retv_if(interface_name == NULL, FALSE);
2797 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2798 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2806 static void __bt_obexd_event_filter(GDBusConnection *connection,
2807 const gchar *sender_name,
2808 const gchar *object_path,
2809 const gchar *interface_name,
2810 const gchar *signal_name,
2811 GVariant *parameters,
2814 const char *member = signal_name;
2815 char *obj_path = NULL;
2816 ret_if(member == NULL);
2818 if (strcasecmp(member, "InterfacesAdded") == 0) {
2819 if (__bt_get_object_path(parameters, &obj_path)) {
2820 BT_ERR("Fail to get the path");
2823 BT_INFO("object_path = [%s]", obj_path);
2825 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2826 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2827 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2832 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2833 BT_DBG("Obex_Server_Session_Transfer connected");
2834 _bt_obex_transfer_connected(obj_path);
2837 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2838 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2839 if (__bt_get_object_path(parameters, &obj_path)) {
2840 BT_ERR("Fail to get the path");
2843 BT_INFO("object_path = [%s]", obj_path);
2845 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2846 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2847 BT_DBG("Call PBAP Disconnected");
2848 _bt_obex_pbap_client_disconnect(obj_path);
2851 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2852 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2857 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2858 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
2861 _bt_obex_transfer_disconnected(obj_path);
2864 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2865 const char *path = object_path;
2867 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2868 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2869 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2870 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2871 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2875 _bt_handle_property_changed_event(parameters, path);
2881 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2885 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2886 char *interface_name = NULL;
2888 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2890 retv_if(interface_name == NULL, FALSE);
2892 if (strcasecmp(interface_name,
2893 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2904 static void __bt_opc_event_filter(GDBusConnection *connection,
2905 const gchar *sender_name,
2906 const gchar *object_path,
2907 const gchar *interface_name,
2908 const gchar *signal_name,
2909 GVariant *parameters,
2912 const char *member = signal_name;
2913 char *obj_path = NULL;
2914 if (strcasecmp(member, "InterfacesAdded") == 0) {
2915 BT_DBG("InterfacesAdded");
2916 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2918 if (__bt_get_object_path(parameters, &obj_path)) {
2919 BT_ERR("Fail to get the path");
2923 BT_DBG("object_path = %s", obj_path);
2925 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2926 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2927 || strstr(obj_path, "transfer") == NULL) {
2930 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2931 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2932 BT_DBG("Going to call opc disconnected");
2933 _bt_opc_disconnected(obj_path);
2936 _bt_sending_files();
2938 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
2939 char *path = (char *)object_path;
2940 BT_INFO("object_path %s", path);
2941 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2942 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2943 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2947 _bt_opc_property_changed_event(parameters, path);
2953 int _bt_opp_client_event_init(void)
2955 GError *error = NULL;
2957 if (opc_obexd_conn == NULL) {
2958 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2960 if (!opc_obexd_conn) {
2962 BT_ERR("Unable to connect to dbus: %s", error->message);
2963 g_clear_error(&error);
2965 return BLUETOOTH_ERROR_INTERNAL;
2969 if (_bt_register_service_event(opc_obexd_conn,
2970 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2971 g_object_unref(opc_obexd_conn);
2972 opc_obexd_conn = NULL;
2973 return BLUETOOTH_ERROR_INTERNAL;
2976 return BLUETOOTH_ERROR_NONE;
2979 void _bt_opp_client_event_deinit(void)
2981 if (opc_obexd_conn) {
2982 _bt_unregister_service_event(opc_obexd_conn,
2983 BT_OPP_CLIENT_EVENT);
2984 g_object_unref(opc_obexd_conn);
2985 opc_obexd_conn = NULL;
2989 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2995 static int subs_interface_added_id = -1;
2996 static int subs_interface_removed_id = -1;
2997 static int subs_name_owner_id = -1;
2998 static int subs_property_id = -1;
2999 static int subs_adapter_id = -1;
3000 static int subs_gatt_id = -1;
3003 if (subs_interface_added_id == -1) {
3004 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3005 NULL, BT_MANAGER_INTERFACE,
3006 BT_INTERFACES_ADDED, NULL, NULL, 0,
3007 __bt_manager_event_filter,
3010 if (subs_interface_removed_id == -1) {
3011 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3012 NULL, BT_MANAGER_INTERFACE,
3013 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3014 __bt_manager_event_filter,
3017 if (subs_name_owner_id == -1) {
3018 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3019 NULL, BT_FREEDESKTOP_INTERFACE,
3020 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3021 __bt_manager_event_filter,
3024 if (subs_property_id == -1) {
3025 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3026 NULL, BT_PROPERTIES_INTERFACE,
3027 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3028 __bt_manager_event_filter,
3031 if (subs_adapter_id == -1) {
3032 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3033 NULL, BT_ADAPTER_INTERFACE,
3034 NULL, NULL, NULL, 0,
3035 __bt_manager_event_filter,
3038 if (subs_gatt_id == -1) {
3039 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3040 NULL, BT_GATT_CHAR_INTERFACE,
3041 NULL, NULL, NULL, 0,
3042 __bt_manager_event_filter,
3046 if (subs_interface_added_id != -1) {
3047 g_dbus_connection_signal_unsubscribe(conn,
3048 subs_interface_added_id);
3049 subs_interface_added_id = -1;
3051 if (subs_interface_removed_id != -1) {
3052 g_dbus_connection_signal_unsubscribe(conn,
3053 subs_interface_removed_id);
3054 subs_interface_removed_id = -1;
3056 if (subs_name_owner_id != -1) {
3057 g_dbus_connection_signal_unsubscribe(conn,
3058 subs_name_owner_id);
3059 subs_name_owner_id = -1;
3061 if (subs_property_id != -1) {
3062 g_dbus_connection_signal_unsubscribe(conn,
3064 subs_property_id = -1;
3066 if (subs_adapter_id != -1) {
3067 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3068 subs_adapter_id = -1;
3070 if (subs_gatt_id != -1) {
3071 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3078 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3084 static int subs_device_id = -1;
3087 if (subs_device_id == -1) {
3088 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3089 NULL, BT_DEVICE_INTERFACE,
3090 NULL, NULL, NULL, 0,
3091 __bt_manager_event_filter,
3095 if (subs_device_id != -1) {
3096 g_dbus_connection_signal_unsubscribe(conn,
3098 subs_device_id = -1;
3104 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3110 static int subs_input_id = -1;
3113 if (subs_input_id == -1) {
3114 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3115 NULL, BT_INPUT_INTERFACE,
3116 NULL, NULL, NULL, 0,
3117 __bt_manager_event_filter,
3121 if (subs_input_id != -1) {
3122 g_dbus_connection_signal_unsubscribe(conn,
3130 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3136 static int subs_serv_id = -1;
3137 static int subs_client_id = -1;
3140 if (subs_serv_id == -1) {
3141 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3142 NULL, BT_NETWORK_SERVER_INTERFACE,
3143 NULL, NULL, NULL, 0,
3144 __bt_manager_event_filter,
3147 if (subs_client_id == -1) {
3148 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3149 NULL, BT_NETWORK_CLIENT_INTERFACE,
3150 NULL, NULL, NULL, 0,
3151 __bt_manager_event_filter,
3155 if (subs_serv_id != -1) {
3156 g_dbus_connection_signal_unsubscribe(conn,
3160 if (subs_client_id != -1) {
3161 g_dbus_connection_signal_unsubscribe(conn,
3163 subs_client_id = -1;
3169 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3175 static int subs_headset_id = -1;
3176 static int subs_sink_id = -1;
3179 if (subs_headset_id == -1) {
3180 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3181 NULL, BT_HEADSET_INTERFACE,
3182 NULL, NULL, NULL, 0,
3183 __bt_manager_event_filter,
3186 if (subs_sink_id == -1) {
3187 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3188 NULL, BT_SINK_INTERFACE,
3189 NULL, NULL, NULL, 0,
3190 __bt_manager_event_filter,
3194 if (subs_headset_id != -1) {
3195 g_dbus_connection_signal_unsubscribe(conn,
3197 subs_headset_id = -1;
3199 if (subs_sink_id != -1) {
3200 g_dbus_connection_signal_unsubscribe(conn,
3208 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3214 static int subs_opp_server_interface_added_id = -1;
3215 static int subs_opp_server_interface_removed_id = -1;
3216 static int subs_opp_server_property_id = -1;
3220 if (subs_opp_server_interface_added_id == -1) {
3221 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3222 NULL, BT_MANAGER_INTERFACE,
3223 BT_INTERFACES_ADDED, NULL, NULL, 0,
3224 __bt_obexd_event_filter,
3227 if (subs_opp_server_interface_removed_id == -1) {
3228 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3229 NULL, BT_MANAGER_INTERFACE,
3230 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3231 __bt_obexd_event_filter,
3234 if (subs_opp_server_property_id == -1) {
3235 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3236 NULL, BT_PROPERTIES_INTERFACE,
3237 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3238 __bt_obexd_event_filter,
3242 if (subs_opp_server_interface_added_id != -1) {
3243 g_dbus_connection_signal_unsubscribe(conn,
3244 subs_opp_server_interface_added_id);
3245 subs_opp_server_interface_added_id = -1;
3247 if (subs_opp_server_interface_removed_id != -1) {
3248 g_dbus_connection_signal_unsubscribe(conn,
3249 subs_opp_server_interface_removed_id);
3250 subs_opp_server_interface_removed_id = -1;
3252 if (subs_opp_server_property_id != -1) {
3253 g_dbus_connection_signal_unsubscribe(conn,
3254 subs_opp_server_property_id);
3255 subs_opp_server_property_id = -1;
3261 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3267 static int subs_opp_client_interface_added_id = -1;
3268 static int subs_opp_client_interface_removed_id = -1;
3269 static int subs_opp_client_property_id = -1;
3273 if (subs_opp_client_interface_added_id == -1) {
3274 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3275 NULL, BT_MANAGER_INTERFACE,
3276 BT_INTERFACES_ADDED, NULL, NULL, 0,
3277 __bt_opc_event_filter,
3280 if (subs_opp_client_interface_removed_id == -1) {
3281 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3282 NULL, BT_MANAGER_INTERFACE,
3283 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3284 __bt_opc_event_filter,
3287 if (subs_opp_client_property_id == -1) {
3288 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3289 NULL, BT_PROPERTIES_INTERFACE,
3290 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3291 __bt_opc_event_filter,
3295 if (subs_opp_client_interface_added_id != -1) {
3296 g_dbus_connection_signal_unsubscribe(conn,
3297 subs_opp_client_interface_added_id);
3298 subs_opp_client_interface_added_id = -1;
3300 if (subs_opp_client_interface_removed_id != -1) {
3301 g_dbus_connection_signal_unsubscribe(conn,
3302 subs_opp_client_interface_removed_id);
3303 subs_opp_client_interface_removed_id = -1;
3305 if (subs_opp_client_property_id != -1) {
3306 g_dbus_connection_signal_unsubscribe(conn,
3307 subs_opp_client_property_id);
3308 subs_opp_client_property_id = -1;
3314 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3320 static int subs_a2dp_source_id = -1;
3321 static int subs_a2dp_sink_id = -1;
3324 if (subs_a2dp_source_id == -1) {
3325 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3326 NULL, BT_A2DP_SOURCE_INTERFACE,
3327 NULL, NULL, NULL, 0,
3328 __bt_opc_event_filter,
3331 if (subs_a2dp_sink_id == -1) {
3332 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3333 NULL, BT_SINK_INTERFACE,
3334 NULL, NULL, NULL, 0,
3335 __bt_opc_event_filter,
3339 if (subs_a2dp_source_id != -1) {
3340 g_dbus_connection_signal_unsubscribe(conn,
3341 subs_a2dp_source_id);
3342 subs_a2dp_source_id = -1;
3344 if (subs_a2dp_sink_id != -1) {
3345 g_dbus_connection_signal_unsubscribe(conn,
3347 subs_a2dp_sink_id = -1;
3353 static void __bt_dump_event_filter(GDBusConnection *connection,
3354 const gchar *sender_name,
3355 const gchar *object_path,
3356 const gchar *interface_name,
3357 const gchar *signal_name,
3358 GVariant *parameters,
3364 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3370 static int subs_source_id = -1;
3373 if (subs_source_id == -1) {
3374 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3375 NULL, BT_DUMP_SERVICE_INTERFACE,
3376 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3377 __bt_dump_event_filter,
3381 if (subs_source_id != -1) {
3382 g_dbus_connection_signal_unsubscribe(conn,
3384 subs_source_id = -1;
3390 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3394 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3396 switch (event_type) {
3397 case BT_MANAGER_EVENT:
3398 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3400 case BT_DEVICE_EVENT:
3401 _bt_register_device_subscribe_signal(g_conn, TRUE);
3404 _bt_register_input_subscribe_signal(g_conn, TRUE);
3406 case BT_NETWORK_EVENT:
3407 _bt_register_network_subscribe_signal(g_conn, TRUE);
3409 case BT_HEADSET_EVENT:
3410 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3413 case BT_OPP_SERVER_EVENT:
3414 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3415 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3417 case BT_OPP_CLIENT_EVENT:
3418 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3419 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3421 case BT_A2DP_SOURCE_EVENT:
3422 BT_INFO("A2dp Source event");
3423 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3426 BT_ERR("Unknown event");
3427 return BLUETOOTH_ERROR_INTERNAL;
3430 return BLUETOOTH_ERROR_NONE;
3433 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3437 ret_if(g_conn == NULL);
3439 switch (event_type) {
3440 case BT_MANAGER_EVENT:
3441 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3442 _bt_register_device_subscribe_signal(g_conn, FALSE);
3443 _bt_register_input_subscribe_signal(g_conn, FALSE);
3444 _bt_register_network_subscribe_signal(g_conn, FALSE);
3445 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3447 case BT_OPP_SERVER_EVENT:
3448 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3450 case BT_OPP_CLIENT_EVENT:
3451 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3454 BT_ERR("Unknown event");
3461 static int __bt_init_manager_receiver(void)
3465 GError *error = NULL;
3467 if (manager_conn == NULL) {
3468 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3469 if (error != NULL) {
3470 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3471 g_clear_error(&error);
3473 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3476 if (_bt_register_service_event(manager_conn,
3477 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3479 if (_bt_register_service_event(manager_conn,
3480 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3483 if (_bt_register_service_event(manager_conn,
3484 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3487 if (_bt_register_service_event(manager_conn,
3488 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3491 if (_bt_register_service_event(manager_conn,
3492 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3495 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3496 return BLUETOOTH_ERROR_NONE;
3499 g_object_unref(manager_conn);
3500 manager_conn = NULL;
3505 return BLUETOOTH_ERROR_INTERNAL;
3508 static int __bt_init_obexd_receiver(void)
3511 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3512 GError *error = NULL;
3514 if (obexd_conn == NULL) {
3515 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3516 if (error != NULL) {
3517 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3518 g_clear_error(&error);
3520 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3523 if (_bt_register_service_event(obexd_conn,
3524 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3525 BT_ERR("Error while registering service event");
3526 g_object_unref(obexd_conn);
3528 return BLUETOOTH_ERROR_INTERNAL;
3533 return BLUETOOTH_ERROR_NONE;
3536 /* To receive the event from bluez */
3537 int _bt_init_service_event_receiver(void)
3543 result = __bt_init_manager_receiver();
3544 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3546 result = __bt_init_obexd_receiver();
3547 if (result != BLUETOOTH_ERROR_NONE)
3548 BT_ERR("Fail to init obexd receiver");
3552 return BLUETOOTH_ERROR_NONE;
3555 void _bt_deinit_service_event_receiver(void)
3559 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3561 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3563 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3566 g_object_unref(manager_conn);
3567 manager_conn = NULL;
3571 g_object_unref(obexd_conn);
3576 g_source_remove(event_id);