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"
42 #include "bt-service-opp-client.h"
44 #ifdef TIZEN_DPM_ENABLE
45 #include "bt-service-dpm.h"
48 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
49 static GDBusConnection *manager_conn;
50 static GDBusConnection *obexd_conn;
51 static GDBusConnection *opc_obexd_conn;
53 static GList *p_cache_list = NULL;
55 static guint event_id;
56 guint nap_connected_device_count = 0;
57 static guint hid_connected_device_count = 0;
58 static GList *p_adv_ind_list;
61 bt_remote_dev_info_t *dev_info;
65 * obexd connection type
73 OBEX_PCSUITE = (1 << 6),
74 OBEX_SYNCEVOLUTION = (1 << 7),
76 } bluetooth_obex_connection_type_t;
78 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
79 void _bt_opc_property_changed_event(GVariant *msg, char *path);
80 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
81 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
82 void _bt_opp_client_event_deinit(void);
83 void _bt_handle_network_client_event(GVariant *msg_iter,
85 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
88 static void __bt_free_bt_le_adv_info_t(bt_le_adv_info_t *adv_info)
90 g_free(adv_info->addr);
91 g_free(adv_info->data);
95 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
98 bt_le_adv_info_t *adv_info = NULL;
99 GList *current = g_list_first((GList *)p_adv_ind_list);
100 while (current && current->data) {
101 adv_info = (bt_le_adv_info_t *)current->data;
102 retv_if(adv_info && !g_strcmp0(adv_info->addr, addr), adv_info);
103 current = g_list_next(current);
108 static void __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
111 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
112 BT_ERR("adv_info is already added");
113 __bt_free_bt_le_adv_info_t(adv_info);
116 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
119 static void __bt_del_adv_ind_info(char *addr)
122 ret_if(!p_adv_ind_list);
123 bt_le_adv_info_t *adv_info = NULL;
124 GList *current = g_list_first((GList *)p_adv_ind_list);
125 while (current && current->data) {
126 adv_info = (bt_le_adv_info_t *)current->data;
127 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
128 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
129 __bt_free_bt_le_adv_info_t(adv_info);
132 current = g_list_next(current);
136 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
138 ret_if(cache_info == NULL);
139 _bt_free_device_info(cache_info->dev_info);
143 static gboolean __bt_parse_device_properties(GVariant *item,
144 bt_remote_dev_info_t *dev_info)
153 g_variant_iter_init(&iter, item);
154 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
155 if (strcasecmp(key, "Address") == 0) {
156 dev_info->address = g_variant_dup_string(val, &len);
157 } else if (strcasecmp(key, "Class") == 0) {
158 dev_info->class = g_variant_get_uint32(val);
159 } else if (strcasecmp(key, "name") == 0) {
160 if (dev_info->name == NULL)
161 dev_info->name = g_variant_dup_string(val, &len);
162 } else if (strcasecmp(key, "Connected") == 0) {
163 dev_info->connected = g_variant_get_uint32(val);
164 } else if (strcasecmp(key, "paired") == 0) {
165 dev_info->paired = g_variant_get_boolean(val);
166 } else if (strcasecmp(key, "Trusted") == 0) {
167 dev_info->trust = g_variant_get_boolean(val);
168 } else if (strcasecmp(key, "RSSI") == 0) {
169 dev_info->rssi = g_variant_get_int16(val);
170 } else if (strcasecmp(key, "LastAddrType") == 0) {
171 dev_info->addr_type = g_variant_get_byte(val);
172 } else if (strcasecmp(key, "UUIDs") == 0) {
176 size = g_variant_get_size(val);
179 uuid_value = (char **)g_variant_get_strv(val, &size);
180 if (dev_info->uuids == NULL)
181 dev_info->uuids = g_malloc0(sizeof(char *) * size);
183 for (i = 0; uuid_value[i] != NULL; i++) {
184 dev_info->uuid_count++;
185 dev_info->uuids[i] = g_strdup(uuid_value[i]);
189 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
190 g_variant_get(val, "(i)", &dev_info->manufacturer_data_len);
191 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
192 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
193 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
196 if (dev_info->manufacturer_data_len == 0)
197 dev_info->manufacturer_data = g_strdup("");
198 } else if (strcasecmp(key, "ManufacturerData") == 0) {
200 GVariant *manufacturer_var;
201 g_variant_get(val, "@ay", &manufacturer_var);
202 len = g_variant_get_size(manufacturer_var);
204 char *manufacturer_data = (char *)g_variant_get_data(manufacturer_var);
205 dev_info->manufacturer_data = g_malloc0(len);
206 if (dev_info->manufacturer_data)
207 memcpy(dev_info->manufacturer_data, manufacturer_data,
210 g_variant_unref(manufacturer_var);
218 static gboolean __bt_parse_interface(GVariant *msg,
219 bt_remote_dev_info_t *dev_info)
222 GVariant *optional_param;
225 char *interface_name = NULL;
226 GVariant *inner_iter = NULL;
227 g_variant_get(msg, "(&o@a{sa{sv}})",
228 &path, &optional_param);
229 g_variant_iter_init(&iter, optional_param);
231 while ((child = g_variant_iter_next_value(&iter))) {
232 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
233 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
234 BT_DBG("Found a device: %s", path);
235 if (__bt_parse_device_properties(inner_iter,
236 dev_info) == FALSE) {
237 g_variant_unref(inner_iter);
238 g_variant_unref(child);
239 g_variant_unref(optional_param);
240 BT_ERR("Fail to parse the properies");
243 g_variant_unref(inner_iter);
244 g_variant_unref(child);
245 g_variant_unref(optional_param);
249 g_variant_unref(inner_iter);
250 g_variant_unref(child);
253 g_variant_unref(optional_param);
258 static int __bt_get_owner_info(GVariant *msg, char **name,
259 char **previous, char **current)
261 g_variant_get(msg, "(sss)", name, previous, current);
262 return BLUETOOTH_ERROR_NONE;
265 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
266 char **name, char **uuid)
268 g_variant_get(msg, "(sss)", address, name, uuid);
269 return BLUETOOTH_ERROR_NONE;
272 void __bt_set_device_values(gboolean connected, int state)
274 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
276 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) {
277 BT_ERR("vconf_get_int failed");
280 if (connected == TRUE)
281 bt_device_state |= state;
282 else if (bt_device_state & state)
283 bt_device_state ^= state;
285 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) {
286 BT_ERR("vconf_set_int failed");
290 gboolean _bt_discovery_finished_cb(gpointer user_data)
292 int result = BLUETOOTH_ERROR_NONE;
294 GVariant *param = NULL;
295 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
296 if (_bt_get_cancel_by_user() == TRUE) {
297 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
300 _bt_set_cancel_by_user(FALSE);
301 _bt_set_discovery_status(FALSE);
302 param = g_variant_new("(i)", result);
303 _bt_send_event(BT_ADAPTER_EVENT,
304 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
311 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
313 int result = BLUETOOTH_ERROR_NONE;
315 GVariant *param = NULL;
316 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
317 if (_bt_get_cancel_by_user() == TRUE) {
318 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
321 _bt_set_cancel_by_user(FALSE);
322 _bt_disable_all_scanner_status();
323 _bt_set_le_scan_status(FALSE);
324 param = g_variant_new("(i)", result);
325 _bt_send_event(BT_LE_ADAPTER_EVENT,
326 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
333 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
337 ret_if(address == NULL);
340 bt_cache_info_t *cache_info;
341 bt_remote_dev_info_t *dev_info;
343 node = g_list_first(p_cache_list);
345 while (node != NULL) {
346 cache_info = (bt_cache_info_t *)node->data;
348 if (cache_info == NULL) {
349 node = g_list_next(node);
353 dev_info = cache_info->dev_info;
354 if (strcasecmp(dev_info->address,
356 BT_DBG("Device Found");
357 if (paired_status == TRUE)
358 cache_info->dev_info->paired = TRUE;
360 cache_info->dev_info->paired = FALSE;
363 node = g_list_next(node);
368 static void __bt_device_remote_connected_properties(
369 bt_remote_dev_info_t *remote_dev_info,
370 char *address, gboolean connected)
372 int result = BLUETOOTH_ERROR_NONE;
374 GVariant *param = NULL;
377 if (remote_dev_info->uuid_count > 0) {
378 for (i = 0; i < remote_dev_info->uuid_count; i++) {
379 char *uuid = remote_dev_info->uuids[i];
380 if (strcasecmp(uuid, HID_UUID) == 0) {
381 int event = BLUETOOTH_EVENT_NONE;
383 event = (connected == TRUE) ?
384 BLUETOOTH_HID_CONNECTED :
385 BLUETOOTH_HID_DISCONNECTED;
386 param = g_variant_new("(is)", result,
388 _bt_send_event(BT_HID_EVENT, event,
398 void _bt_handle_adapter_event(GVariant *msg, const char *member)
402 int result = BLUETOOTH_ERROR_NONE;
403 GVariant *param = NULL;
404 ret_if(member == NULL);
406 if (strcasecmp(member, "DeviceCreated") == 0) {
407 char *object_path = NULL;
409 bt_remote_dev_info_t *remote_dev_info;
411 ret_if(_bt_is_device_creating() == FALSE);
413 /* Bonding from remote device */
414 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
416 g_variant_get(msg, "(&o)", &object_path);
417 _bt_convert_device_path_to_address((const char*)object_path, address);
419 remote_dev_info = _bt_get_remote_device_info(address);
420 if (remote_dev_info == NULL) {
425 _bt_free_device_info(remote_dev_info);
427 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
428 char *object_path = NULL;
430 bt_cache_info_t *cache_info;
431 bt_remote_dev_info_t *dev_info;
434 /* Bonding from remote device */
435 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
436 g_variant_get(msg, "(&o)", &object_path);
438 /* Fix : NULL_RETURNS */
442 _bt_convert_device_path_to_address((const char *)object_path, address);
444 node = g_list_first(p_cache_list);
446 while (node != NULL) {
447 cache_info = (bt_cache_info_t *)node->data;
449 if (cache_info == NULL) {
450 node = g_list_next(node);
454 dev_info = cache_info->dev_info;
455 if (strcasecmp(dev_info->address,
457 p_cache_list = g_list_remove(p_cache_list,
459 __bt_free_cache_info(cache_info);
462 node = g_list_next(node);
465 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
466 BT_DBG("Advertising Enabled");
470 gboolean status = FALSE;
472 g_variant_get(msg, "(ib)", &slot_id, &status);
474 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
476 /* Send event to application */
477 _bt_set_advertising_status(slot_id, status);
479 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
482 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
484 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
485 param = g_variant_new("(ii)", result,
490 sender = _bt_get_adv_slot_owner(slot_id);
491 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
495 _bt_send_event(BT_ADAPTER_EVENT, event, param);
498 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
499 _bt_unregister_adv_slot_owner(slot_id);
500 } else if (strcasecmp(member, "RssiEnabled") == 0) {
501 BT_DBG("RSSI Enabled");
502 gboolean status = FALSE;
503 char *address = NULL;
505 g_variant_get(msg, "(sib)", &address, &link_type, &status);
507 BT_DBG("RSSI Enabled [%s %d]", address, status);
508 param = g_variant_new("(isib)", result,
509 address, link_type, status);
510 _bt_send_event(BT_DEVICE_EVENT,
511 BLUETOOTH_EVENT_RSSI_ENABLED,
514 } else if (strcasecmp(member, "RssiAlert") == 0) {
515 BT_DBG("RSSI Alert");
519 char *address = NULL;
520 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
522 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
523 address, alert_type, rssi_dbm);
524 param = g_variant_new("(isiii)", result,
525 address, link_type, alert_type, rssi_dbm);
526 _bt_send_event(BT_DEVICE_EVENT,
527 BLUETOOTH_EVENT_RSSI_ALERT,
530 } else if (strcasecmp(member, "RawRssi") == 0) {
534 char *address = NULL;
535 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
537 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
538 address, link_type, rssi_dbm);
539 param = g_variant_new("(isii)", result,
540 address, link_type, rssi_dbm);
541 _bt_send_event(BT_DEVICE_EVENT,
542 BLUETOOTH_EVENT_RAW_RSSI,
545 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
546 BT_ERR_C("Hardware error received from BLUEZ");
547 _bt_recover_adapter();
548 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
549 BT_ERR_C("Tx timeout error received from BLUEZ");
550 _bt_recover_adapter();
555 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
557 GDBusProxy *adapter_proxy;
559 int result = BLUETOOTH_ERROR_NONE;
560 GVariantIter value_iter;
561 GVariant *val = NULL;
563 char *property = NULL;
564 GVariant *param = NULL;
565 g_variant_iter_init(&value_iter, msg);
566 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
567 BT_INFO("Property %s", property);
569 if (strcasecmp(property, "Discovering") == 0) {
570 gboolean discovering = FALSE;
571 g_variant_get(val, "b", &discovering);
572 /* Send event to application */
573 BT_DBG("Discovering %d", discovering);
574 if (discovering == TRUE) {
575 _bt_set_discovery_status(TRUE);
576 param = g_variant_new("(i)", result);
577 _bt_send_event(BT_ADAPTER_EVENT,
578 BLUETOOTH_EVENT_DISCOVERY_STARTED,
581 ret_if(event_id > 0);
583 adapter_proxy = _bt_get_adapter_proxy();
584 ret_if(adapter_proxy == NULL);
586 /* Need to stop searching */
587 g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
589 G_DBUS_CALL_FLAGS_NONE,
593 BT_ERR("Dbus Error : %s", err->message);
597 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
598 (GSourceFunc)_bt_discovery_finished_cb, NULL);
600 } else if (strcasecmp(property, "LEDiscovering") == 0) {
601 gboolean le_discovering = FALSE;
603 g_variant_get(val, "b", &le_discovering);
604 /* Send event to application */
605 if (le_discovering == TRUE) {
606 _bt_set_le_scan_status(TRUE);
607 param = g_variant_new("(i)", result);
608 _bt_send_event(BT_LE_ADAPTER_EVENT,
609 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
612 ret_if(event_id > 0);
614 adapter_proxy = _bt_get_adapter_proxy();
615 ret_if(adapter_proxy == NULL);
617 /* Need to stop searching */
618 g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
620 G_DBUS_CALL_FLAGS_NONE,
624 BT_ERR("Dbus Error %s", err->message);
628 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
629 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
631 } else if (strcasecmp(property, "Name") == 0) {
633 g_variant_get(val, "s", &name);
634 param = g_variant_new("(is)", result, name);
635 /* Send event to application */
636 _bt_send_event(BT_ADAPTER_EVENT,
637 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
640 } else if (strcasecmp(property, "Alias") == 0) {
642 g_variant_get(val, "s", &alias);
643 param = g_variant_new("(is)", result, alias);
644 /* Send event to application */
645 _bt_send_event(BT_ADAPTER_EVENT,
646 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
649 } else if (strcasecmp(property, "Discoverable") == 0) {
650 gboolean discoverable = FALSE;
652 g_variant_get(val, "b", &discoverable);
653 BT_DBG("discoverable %d", discoverable);
655 if (discoverable == FALSE) {
656 if (_bt_get_discoverable_timeout_property() > 0) {
658 adapter_proxy = _bt_get_adapter_properties_proxy();
659 ret_if(adapter_proxy == NULL);
660 g_dbus_proxy_call_sync(adapter_proxy, "Set",
661 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
662 "DiscoverableTimeout",
663 g_variant_new("i", time)),
664 G_DBUS_CALL_FLAGS_NONE,
669 BT_ERR("StopLEDiscovery Failed: %s", err->message);
674 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
676 /* Send event to application */
677 BT_INFO("[Connectable]");
678 param = g_variant_new("(in)", result, mode);
679 _bt_send_event(BT_ADAPTER_EVENT,
680 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
683 _bt_get_discoverable_mode(&mode);
685 /* Event will be sent by "DiscoverableTimeout" signal */
686 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
688 g_variant_unref(val);
692 /* Send event to application */
693 BT_INFO("[General Discoverable]");
694 param = g_variant_new("(in)", result, mode);
695 _bt_send_event(BT_ADAPTER_EVENT,
696 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
699 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
700 _bt_get_discoverable_mode(&mode);
702 /* Event was already sent by "Discoverable" signal */
703 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
704 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
706 g_variant_unref(val);
710 /* Send event to application */
711 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
712 _bt_get_discoverable_timeout_property());
713 param = g_variant_new("(in)", result, mode);
714 _bt_send_event(BT_ADAPTER_EVENT,
715 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
717 } else if (strcasecmp(property, "Powered") == 0) {
718 /* TODO: Need to check this operation!! */
719 gboolean powered = FALSE;
722 g_variant_get(val, "b", &powered);
723 BT_DBG("Powered = %d", powered);
724 if (powered == FALSE) {
726 _bt_handle_adapter_removed();
728 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
729 bt_state != VCONFKEY_BT_STATUS_OFF) {
730 _bt_disable_adapter();
733 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
734 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
735 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
739 _bt_handle_adapter_added();
742 } else if (strcasecmp(property, "Connectable") == 0) {
743 gboolean connectable = FALSE;
745 g_variant_get(val, "b", &connectable);
747 BT_DBG("Connectable property is changed : %d", connectable);
748 param = g_variant_new("(b)", connectable);
749 _bt_send_event(BT_ADAPTER_EVENT,
750 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
752 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
753 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
755 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
756 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
759 GVariantIter *iter = NULL;
760 g_variant_get(val, "as", &iter);
762 while (g_variant_iter_loop(iter, "s", &name)) {
763 BT_DBG("name = %s", name);
764 g_variant_iter_loop(iter, "s", &value);
765 BT_DBG("Value = %s", value);
766 if (FALSE == _bt_update_le_feature_support(name, value))
767 BT_INFO("Fail to update LE feature info");
769 g_variant_iter_free(iter);
771 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
772 gboolean ipsp_initialized = FALSE;
774 g_variant_get(val, "b", &ipsp_initialized);
775 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
776 param = g_variant_new("(b)", ipsp_initialized);
778 /* Send event to application */
779 _bt_send_event(BT_ADAPTER_EVENT,
780 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
786 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
790 GVariantIter value_iter;
791 GVariant *child = NULL, *val = NULL;
792 char *property = NULL;
793 g_variant_iter_init(&value_iter, msg);
794 while ((child = g_variant_iter_next_value(&value_iter))) {
795 g_variant_get(child, "{sv}", &property, &val);
797 ret_if(property == NULL);
799 BT_DBG("property :%s", property);
801 if (strcasecmp(property, "Status") == 0) {
803 g_variant_get(val, "s", &status);
805 if (strcasecmp(status, "active") == 0) {
806 _bt_obex_transfer_started(path);
807 } else if (strcasecmp(status, "complete") == 0) {
808 _bt_obex_transfer_completed(path, TRUE);
809 _bt_pbap_obex_transfer_completed(path, TRUE);
810 } else if (strcasecmp(status, "error") == 0) {
811 _bt_obex_transfer_completed(path, FALSE);
812 _bt_pbap_obex_transfer_completed(path, FALSE);
815 } else if (strcasecmp(property, "Transferred") == 0) {
816 static int transferred = 0;
817 g_variant_get(val, "t", &transferred);
819 _bt_obex_transfer_progress(path, transferred);
822 g_variant_unref(val);
823 g_variant_unref(child);
828 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
833 int result = BLUETOOTH_ERROR_NONE;
834 GVariantIter value_iter;
836 char *property = NULL;
838 GVariant *param = NULL;
839 bt_remote_dev_info_t *remote_dev_info;
840 g_variant_iter_init(&value_iter, msg);
841 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
842 BT_DBG("Property %s", property);
843 if (strcasecmp(property, "Connected") == 0) {
846 g_variant_get(val, "i", &connected);
848 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
849 BLUETOOTH_EVENT_DEVICE_CONNECTED :
850 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
852 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
854 _bt_convert_device_path_to_address(path, address);
856 BT_DBG("connected: %d", connected);
857 BT_DBG("address: %s", address);
859 remote_dev_info = _bt_get_remote_device_info(address);
861 if (remote_dev_info != NULL) {
862 __bt_device_remote_connected_properties(
863 remote_dev_info, address,
864 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
866 _bt_free_device_info(remote_dev_info);
868 param = g_variant_new("(is)", result, address);
869 /* Send event to application */
870 _bt_send_event(BT_DEVICE_EVENT,
874 } else if (strcasecmp(property, "RSSI") == 0) {
875 bt_remote_dev_info_t *remote_dev_info;
877 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
879 _bt_convert_device_path_to_address(path, address);
880 BT_DBG("address: %s", address);
882 remote_dev_info = _bt_get_remote_device_info(address);
883 if (remote_dev_info == NULL) {
885 g_variant_unref(val);
889 BT_DBG("Address type %d", remote_dev_info->addr_type);
891 if (remote_dev_info->addr_type == 0) {
892 BT_DBG("Name %s", remote_dev_info->name);
894 #ifdef TIZEN_DPM_ENABLE
895 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
897 bluetooth_device_class_t device_class;
898 _bt_divide_device_class(&device_class, remote_dev_info->class);
900 if (device_class.major_class ==
901 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
902 _bt_free_device_info(remote_dev_info);
904 g_variant_unref(val);
911 GVariant *uuids = NULL;
912 GVariantBuilder *builder = NULL;
914 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
915 for (i = 0; i < remote_dev_info->uuid_count; i++) {
916 g_variant_builder_add(builder, "s",
917 remote_dev_info->uuids[i]);
919 uuids = g_variant_new("as", builder);
920 g_variant_builder_unref(builder);
921 GVariant *manufacturer_data = NULL;
922 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
923 remote_dev_info->manufacturer_data,
924 remote_dev_info->manufacturer_data_len,
927 param = g_variant_new("(isunsbub@asn@ay)", result,
928 remote_dev_info->address,
929 remote_dev_info->class,
930 remote_dev_info->rssi,
931 remote_dev_info->name,
932 remote_dev_info->paired,
933 remote_dev_info->connected,
934 remote_dev_info->trust,
936 remote_dev_info->manufacturer_data_len,
939 _bt_send_event(BT_ADAPTER_EVENT,
940 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
944 _bt_free_device_info(remote_dev_info);
945 } else if (strcasecmp(property, "GattConnected") == 0) {
946 gboolean gatt_connected = FALSE;
948 g_variant_get(val, "b", &gatt_connected);
950 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
951 BLUETOOTH_EVENT_GATT_DISCONNECTED;
953 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
955 _bt_convert_device_path_to_address(path, address);
957 BT_DBG("gatt_connected: %d", gatt_connected);
958 BT_DBG("address: %s", address);
959 param = g_variant_new("(is)", result, address);
960 /* Send event to application */
961 _bt_send_event(BT_DEVICE_EVENT,
965 } else if (strcasecmp(property, "Paired") == 0) {
966 gboolean paired = FALSE;
967 bt_remote_dev_info_t *remote_dev_info;
968 g_variant_get(val, "b", &paired);
969 _bt_agent_set_canceled(FALSE);
970 /* BlueZ sends paired signal for each paired device */
971 /* during activation, We should ignore this, otherwise*/
972 /* application thinks that a new device got paired */
973 if (_bt_adapter_get_status() != BT_ACTIVATED) {
974 BT_DBG("BT is not activated, so ignore this");
976 g_variant_unref(val);
980 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
982 _bt_convert_device_path_to_address(path, address);
984 remote_dev_info = _bt_get_remote_device_info(address);
985 if (remote_dev_info == NULL) {
987 g_variant_unref(val);
992 if (paired == FALSE) {
993 BT_INFO("Unpaired: %s", address);
994 __bt_update_remote_cache_devinfo(address, FALSE);
995 param = g_variant_new("(is)", result, address);
996 _bt_send_event(BT_ADAPTER_EVENT,
997 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1000 BT_INFO("Paired: %s", address);
1001 __bt_update_remote_cache_devinfo(address, TRUE);
1003 if (_bt_is_device_creating() == TRUE) {
1004 BT_DBG("Try to Pair by me");
1005 _bt_free_device_info(remote_dev_info);
1008 g_variant_unref(val);
1011 GVariant *uuids = NULL;
1012 GVariantBuilder *builder = NULL;
1014 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1015 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1016 g_variant_builder_add(builder, "s",
1017 remote_dev_info->uuids[i]);
1019 uuids = g_variant_new("as", builder);
1020 g_variant_builder_unref(builder);
1021 GVariant *manufacturer_data = NULL;
1022 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1023 remote_dev_info->manufacturer_data,
1024 remote_dev_info->manufacturer_data_len,
1028 param = g_variant_new("(isunsbub@asn@ay)", result,
1029 address, remote_dev_info->class,
1030 remote_dev_info->rssi,
1031 remote_dev_info->name,
1032 remote_dev_info->paired,
1033 remote_dev_info->connected,
1034 remote_dev_info->trust,
1036 remote_dev_info->manufacturer_data_len,
1038 _bt_send_event(BT_ADAPTER_EVENT,
1039 BLUETOOTH_EVENT_BONDING_FINISHED,
1042 _bt_free_device_info(remote_dev_info);
1044 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1045 gboolean paired = FALSE;
1046 bt_remote_dev_info_t *remote_dev_info;
1048 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1049 BT_DBG("BT is not activated, so ignore this");
1051 g_variant_unref(val);
1055 g_variant_get(val, "b", &paired);
1056 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1057 BT_DBG("LegacyPaired: %d", paired);
1058 _bt_convert_device_path_to_address(path, address);
1060 remote_dev_info = _bt_get_remote_device_info(address);
1061 if (remote_dev_info == NULL) {
1064 g_variant_unref(val);
1068 BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
1069 remote_dev_info->name);
1070 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1071 remote_dev_info->name, NULL, NULL, NULL);
1073 _bt_free_device_info(remote_dev_info);
1075 } else if (strcasecmp(property, "Trusted") == 0) {
1076 gboolean trusted = FALSE;
1078 g_variant_get(val, "b", &trusted);
1080 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1081 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1083 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1085 _bt_convert_device_path_to_address(path, address);
1087 BT_DBG("trusted: %d", trusted);
1088 BT_DBG("address: %s", address);
1089 param = g_variant_new("(is)", result, address);
1090 /* Send event to application */
1091 _bt_send_event(BT_DEVICE_EVENT,
1095 } else if (strcasecmp(property, "IpspConnected") == 0) {
1096 gboolean connected = FALSE;
1098 g_variant_get(val, "b", &connected);
1101 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1102 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1104 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1106 _bt_convert_device_path_to_address(path, address);
1108 BT_DBG("Ipspconnected: %d", connected);
1109 BT_DBG("address: %s", address);
1110 param = g_variant_new("(is)", result, address);
1112 /* Send event to application */
1113 _bt_send_event(BT_DEVICE_EVENT,
1122 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1125 int result = BLUETOOTH_ERROR_NONE;
1126 GVariantIter value_iter;
1127 char *property = NULL;
1129 GVariant *val = NULL;
1130 GVariant *child = NULL;
1131 bt_remote_dev_info_t *remote_dev_info;
1132 GVariant *param = NULL;
1133 g_variant_iter_init(&value_iter, msg);
1134 while ((child = g_variant_iter_next_value(&value_iter))) {
1135 g_variant_get(child, "{sv}", &property, &val);
1136 BT_INFO("Property %s", property);
1137 if (strcasecmp(property, "Connected") == 0) {
1138 gboolean connected = FALSE;
1140 g_variant_get(val, "b", &connected);
1142 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1143 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1145 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1147 _bt_convert_device_path_to_address(path, address);
1149 BT_DBG("connected: %d", connected);
1150 BT_DBG("address: %s", address);
1152 remote_dev_info = _bt_get_remote_device_info(address);
1154 if (remote_dev_info != NULL) {
1155 __bt_device_remote_connected_properties(
1156 remote_dev_info, address, connected);
1157 _bt_free_device_info(remote_dev_info);
1159 param = g_variant_new("(is)", result, address);
1160 /* Send event to application */
1161 _bt_send_event(BT_AVRCP_EVENT,
1167 g_variant_unref(child);
1168 g_variant_unref(val);
1173 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1175 char *interface_name = NULL;
1176 GVariant *val = NULL;
1178 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1180 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1181 __bt_adapter_property_changed_event(val,
1183 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1184 __bt_device_property_changed_event(val, object_path);
1185 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1186 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1187 __bt_obex_property_changed_event(val,
1189 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1190 __bt_media_control_changed_event(val,
1192 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1193 _bt_handle_avrcp_control_event(val,
1195 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1196 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1197 _bt_handle_network_client_event(val,
1199 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1200 __bt_gatt_char_property_changed_event(val,
1203 g_variant_unref(val);
1206 void __bt_opc_property_changed_event(GVariant *msg,
1209 GVariantIter value_iter;
1210 char *property = NULL;
1211 GVariant *val = NULL;
1212 GVariant *child = NULL;
1214 g_variant_iter_init(&value_iter, msg);
1215 while ((child = g_variant_iter_next_value(&value_iter))) {
1216 g_variant_get(child, "{sv}", &property, &val);
1217 ret_if(property == NULL);
1219 if (strcasecmp(property, "Status") == 0) {
1220 char *status = NULL;
1221 g_variant_get(val, "s", &status);
1222 BT_DBG("Status is %s", status);
1224 if (strcasecmp(status, "active") == 0) {
1225 _bt_obex_client_started(path);
1226 } else if (strcasecmp(status, "complete") == 0) {
1227 _bt_obex_client_completed(path, TRUE);
1228 } else if (strcasecmp(status, "error") == 0) {
1229 _bt_obex_client_completed(path, FALSE);
1232 } else if (strcasecmp(property, "Transferred") == 0) {
1233 static int transferred = 0;
1234 g_variant_get(val, "t", &transferred);
1236 _bt_obex_client_progress(path, transferred);
1238 BT_DBG("property : [%s]", property);
1241 g_variant_unref(child);
1242 g_variant_unref(val);
1246 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1248 char *interface_name = NULL;
1249 GVariant *value = NULL;
1250 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1251 BT_INFO("interface_name = %s", interface_name);
1252 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1253 __bt_opc_property_changed_event(value,
1256 BT_DBG("interface_name : [%s]", interface_name);
1258 g_variant_unref(value);
1262 void _bt_handle_input_event(GVariant *msg, const char *path)
1264 int result = BLUETOOTH_ERROR_NONE;
1265 gboolean property_flag = FALSE;
1266 GVariantIter value_iter;
1267 char *property = NULL;
1268 GVariant *child = NULL, *val = NULL;
1269 bt_remote_dev_info_t *remote_dev_info;
1270 GVariant *param = NULL;
1271 g_variant_iter_init(&value_iter, msg);
1272 while ((child = g_variant_iter_next_value(&value_iter))) {
1273 g_variant_get(child, "{sv}", &property, &val);
1275 ret_if(property == NULL);
1277 if (strcasecmp(property, "Connected") == 0) {
1278 int event = BLUETOOTH_EVENT_NONE;
1280 g_variant_get(val, "b", &property_flag);
1282 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1284 _bt_convert_device_path_to_address(path, address);
1286 event = (property_flag == TRUE) ?
1287 BLUETOOTH_HID_CONNECTED :
1288 BLUETOOTH_HID_DISCONNECTED;
1289 param = g_variant_new("(is)", result, address);
1290 _bt_send_event(BT_HID_EVENT, event,
1292 /* Check HID connection type (Keyboard or Mouse) and update the status */
1293 remote_dev_info = _bt_get_remote_device_info(address);
1295 if (property_flag == TRUE) {
1296 hid_connected_device_count++;
1297 __bt_set_device_values(TRUE,
1298 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1300 hid_connected_device_count--;
1301 if (hid_connected_device_count == 0)
1302 __bt_set_device_values(FALSE,
1303 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1306 if (remote_dev_info != NULL) {
1307 BT_DBG("HID device class [%x]", remote_dev_info->class);
1308 if (remote_dev_info->class &
1309 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1310 #ifdef ENABLE_TIZEN_2_4
1311 __bt_set_device_values(property_flag,
1312 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1317 if (remote_dev_info->class &
1318 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1319 #ifdef ENABLE_TIZEN_2_4
1320 __bt_set_device_values(property_flag,
1321 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1324 _bt_free_device_info(remote_dev_info);
1329 g_variant_unref(val);
1330 g_variant_unref(child);
1334 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1336 int result = BLUETOOTH_ERROR_NONE;
1337 char *address = NULL;
1338 char *device = NULL;
1339 GVariant *param = NULL;
1340 ret_if(member == NULL);
1341 if (strcasecmp(member, "PeerConnected") == 0) {
1342 g_variant_get(msg, "(ss)", &device, &address);
1344 __bt_set_device_values(TRUE,
1345 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1346 param = g_variant_new("(iss)", result, device, address);
1347 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1351 nap_connected_device_count++;
1352 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1353 g_variant_get(msg, "(ss)", &device, &address);
1354 nap_connected_device_count--;
1355 if (nap_connected_device_count == 0)
1356 __bt_set_device_values(FALSE,
1357 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1358 param = g_variant_new("(iss)", result, device, address);
1359 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1366 void _bt_handle_network_client_event(GVariant *msg,
1371 int result = BLUETOOTH_ERROR_NONE;
1372 gboolean property_flag = FALSE;
1373 char *property = NULL;
1374 GVariant *val = NULL;
1375 GVariantIter value_iter;
1376 GVariant *param = NULL;
1377 g_variant_iter_init(&value_iter, msg);
1378 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1379 if (strcasecmp(property, "Connected") == 0) {
1380 int event = BLUETOOTH_EVENT_NONE;
1383 g_variant_get(val, "b", &property_flag);
1384 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1386 _bt_convert_device_path_to_address(path, address);
1388 BT_DBG("property_flag %d", property_flag);
1389 if (property_flag == TRUE) {
1390 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1391 nap_connected_device_count++;
1392 __bt_set_device_values(TRUE,
1393 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1395 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1396 nap_connected_device_count--;
1397 if (nap_connected_device_count == 0)
1398 __bt_set_device_values(FALSE,
1399 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1401 param = g_variant_new("(is)", result, address);
1402 _bt_send_event(BT_NETWORK_EVENT, event,
1411 void __bt_gatt_char_property_changed_event(GVariant *msg,
1414 GVariantIter value_iter;
1415 char *property = NULL;
1416 char * char_handle = NULL;
1417 GVariant *val = NULL;
1418 int result = BLUETOOTH_ERROR_NONE;
1419 GVariant *param = NULL;
1420 g_variant_iter_init(&value_iter, msg);
1421 char_handle = g_strdup(path);
1422 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1423 BT_INFO("Property %s", property);
1425 ret_if(property == NULL);
1427 if (strcasecmp(property, "Notifying") == 0) {
1428 gboolean property_flag = FALSE;
1429 g_variant_get(val, "b", &property_flag);
1430 if (property_flag == TRUE)
1431 BT_DBG("notifying is enabled");
1433 BT_DBG("notifying is disabled");
1434 } else if (strcasecmp(property, "ChangedValue") == 0) {
1436 GByteArray *gp_byte_array = NULL;
1437 BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
1440 gp_byte_array = g_byte_array_new();
1441 len = g_variant_get_size(val);
1442 BT_DBG("Len = %d", len);
1443 g_byte_array_append(gp_byte_array,
1444 (const guint8 *) g_variant_get_data(val), len);
1445 if (gp_byte_array->len != 0) {
1446 GVariant *byte_array = NULL;
1447 byte_array = g_variant_new_from_data(
1448 G_VARIANT_TYPE_BYTESTRING,
1449 gp_byte_array->data,
1452 param = g_variant_new("(is@ay)", result, char_handle,
1455 /* Send event only registered client */
1456 _bt_send_char_value_changed_event(param);
1458 g_byte_array_free(gp_byte_array, TRUE);
1462 g_free(char_handle);
1465 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1467 ret_if(path == NULL);
1469 if (strcasecmp(member, "GattValueChanged") == 0) {
1472 /*** Debug only ***/
1473 GVariant *value = NULL;
1475 char *buffer = NULL;
1477 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1478 value_len = g_variant_get_size(value);
1479 if (value_len > 0) {
1480 char buf[8 * 5 + 1] = { 0 };
1483 buffer = (char *)g_variant_get_data(value);
1484 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1486 for (i = 0; i < to; i++)
1487 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1489 BT_DBG("GATT Val[%d] %s", value_len, buf);
1491 g_variant_unref(value);
1495 /* Send event only registered client */
1496 _bt_send_char_value_changed_event(msg);
1501 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1504 int result = BLUETOOTH_ERROR_NONE;
1507 const char *property = NULL;
1508 GVariant *param = NULL;
1509 ret_if(path == NULL);
1511 if (strcasecmp(member, "PropertyChanged") == 0) {
1513 g_variant_get(msg, "(s)", &property);
1515 ret_if(property == NULL);
1517 if (strcasecmp(property, "GattConnected") == 0) {
1518 gboolean connected = FALSE;
1520 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1521 ret_if(address == NULL);
1523 _bt_convert_device_path_to_address(path, address);
1524 g_variant_get(msg, "(b)", &connected);
1526 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1527 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1528 param = g_variant_new("(is)", result, address);
1529 _bt_send_event(BT_DEVICE_EVENT,
1533 } else if (strcasecmp(property, "Paired") == 0) {
1534 gboolean paired = FALSE;
1535 bt_remote_dev_info_t *remote_dev_info;
1536 g_variant_get(msg, "(b)", &paired);
1538 ret_if(paired == FALSE);
1540 /* BlueZ sends paired signal for each paired device */
1541 /* during activation, We should ignore this, otherwise*/
1542 /* application thinks that a new device got paired */
1543 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1544 BT_DBG("BT is not activated, so ignore this");
1548 if (_bt_is_device_creating() == TRUE) {
1549 BT_DBG("Try to Pair by me");
1553 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1554 ret_if(address == NULL);
1556 _bt_convert_device_path_to_address(path, address);
1558 remote_dev_info = _bt_get_remote_device_info(address);
1559 if (remote_dev_info == NULL) {
1563 GVariant *uuids = NULL;
1564 GVariantBuilder *builder = NULL;
1566 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1567 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1568 g_variant_builder_add(builder, "s",
1569 remote_dev_info->uuids[i]);
1571 uuids = g_variant_new("as", builder);
1572 g_variant_builder_unref(builder);
1573 GVariant *manufacturer_data = NULL;
1574 manufacturer_data = g_variant_new_from_data(
1575 G_VARIANT_TYPE_BYTESTRING,
1576 remote_dev_info->manufacturer_data,
1577 remote_dev_info->manufacturer_data_len,
1579 param = g_variant_new("(isunsbub@asn@ay)", result,
1581 remote_dev_info->class,
1582 remote_dev_info->rssi,
1583 remote_dev_info->name,
1584 remote_dev_info->paired,
1585 remote_dev_info->connected,
1586 remote_dev_info->trust,
1588 remote_dev_info->manufacturer_data_len,
1590 _bt_send_event(BT_ADAPTER_EVENT,
1591 BLUETOOTH_EVENT_BONDING_FINISHED,
1593 _bt_free_device_info(remote_dev_info);
1596 } else if (strcasecmp(property, "UUIDs") == 0) {
1597 /* Once we get the updated uuid information after
1598 * reverse service search, update it to application */
1600 bt_remote_dev_info_t *remote_dev_info;
1602 ret_if(_bt_is_device_creating() == TRUE);
1604 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1605 ret_if(address == NULL);
1607 _bt_convert_device_path_to_address(path, address);
1609 remote_dev_info = _bt_get_remote_device_info(address);
1610 if (remote_dev_info == NULL) {
1615 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1616 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1617 GVariant *uuids = NULL;
1618 GVariantBuilder *builder = NULL;
1620 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1621 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1622 g_variant_builder_add(builder, "s",
1623 remote_dev_info->uuids[i]);
1625 uuids = g_variant_new("as", builder);
1626 g_variant_builder_unref(builder);
1627 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1628 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1631 param = g_variant_new("(isunsbub@asn@ay)", result,
1632 address, remote_dev_info->class,
1633 remote_dev_info->rssi,
1634 remote_dev_info->name,
1635 remote_dev_info->paired,
1636 remote_dev_info->connected,
1637 remote_dev_info->trust,
1639 remote_dev_info->manufacturer_data_len,
1641 _bt_send_event(BT_ADAPTER_EVENT,
1642 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1646 _bt_free_device_info(remote_dev_info);
1649 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1650 unsigned char addr_type = 0;
1652 g_variant_get(msg, "(y)", &addr_type);
1654 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1655 ret_if(address == NULL);
1657 _bt_convert_device_path_to_address(path, address);
1658 dev_name = _bt_get_bonded_device_name(address);
1660 BT_INFO("Address : %s Type : %d", address, addr_type);
1661 BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1662 !addr_type ? dev_name : address);
1665 _bt_logging_connection(TRUE, addr_type);
1666 #ifdef ENABLE_TIZEN_2_4
1667 journal_bt_connected();
1669 param = g_variant_new("(isy)", result, address, addr_type);
1670 /*Send event to application*/
1671 _bt_send_event(BT_DEVICE_EVENT,
1672 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1675 } else if (strcasecmp(member, "Disconnected") == 0) {
1676 unsigned char disc_reason = 0;
1677 unsigned char addr_type = 0;
1678 gboolean sending = FALSE;
1680 g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
1682 result = disc_reason;
1684 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1685 ret_if(address == NULL);
1687 _bt_convert_device_path_to_address(path, address);
1688 dev_name = _bt_get_bonded_device_name(address);
1689 #ifdef ENABLE_TIZEN_2_4
1690 journal_bt_disconnected();
1693 /* 0x00 BDADDR_BRDER
1694 0x01 BDADDR_LE_PUBLIC
1695 0x02 BDADDR_LE_RANDOM */
1696 BT_INFO("Address : %s Type : %d", address, addr_type);
1697 BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1698 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1699 !addr_type ? dev_name : address);
1702 _bt_headset_set_local_connection(FALSE);
1703 _bt_logging_connection(FALSE, addr_type);
1705 /*Check for any OPP transfer on the device and cancel
1708 _bt_obex_check_pending_transfer(address);
1709 _bt_opp_client_is_sending(&sending);
1710 if (sending == TRUE)
1711 _bt_opp_client_check_pending_transfer(address);
1712 param = g_variant_new("(isy)", result, address, addr_type);
1713 _bt_send_event(BT_DEVICE_EVENT,
1714 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1717 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1719 char *profile_uuid = NULL;
1720 bt_headset_wait_t *wait_list;
1722 g_variant_get(msg, "(si)", &profile_uuid, &state);
1724 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1725 ret_if(address == NULL);
1727 _bt_convert_device_path_to_address(path, address);
1729 BT_DBG("Address: %s", address);
1730 BT_DBG("Profile UUID: %s", profile_uuid);
1731 BT_DBG("State: %d", state);
1733 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1734 (state == BT_PROFILE_STATE_CONNECTED)) {
1736 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1737 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1738 bluetooth_device_address_t device_address;
1740 bt_headset_wait_t *wait_list;
1742 __bt_set_device_values(TRUE,
1743 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1745 __bt_connection_manager_set_state(address, event);
1747 if (_bt_headset_get_local_connection() == FALSE)
1748 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1750 /* Connection Started from local device therefore no need to
1751 * intiate connection for pending profile */
1752 _bt_headset_set_local_connection(FALSE);
1754 param = g_variant_new("(is)", result, address);
1755 _bt_send_event(BT_HEADSET_EVENT, event,
1757 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1760 if (g_strcmp0(connected_address, address) != 0) {
1761 _bt_convert_addr_string_to_type(
1762 device_address.addr,
1764 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1765 &device_address, NULL);
1769 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1770 BT_STATE_CONNECTED, address);
1772 wait_list = _bt_get_audio_wait_data();
1773 if (wait_list != NULL &&
1774 (g_strcmp0(wait_list->address, address) == 0))
1775 _bt_rel_wait_data();
1777 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1778 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1780 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1782 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1784 g_free(profile_uuid);
1788 __bt_set_device_values(FALSE,
1789 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1791 __bt_connection_manager_set_state(address, event);
1792 param = g_variant_new("(is)", result, address);
1793 _bt_send_event(BT_HEADSET_EVENT, event,
1795 /* Remove data from the connected list */
1796 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1797 wait_list = _bt_get_audio_wait_data();
1799 if (wait_list == NULL) {
1801 g_free(profile_uuid);
1805 if (((wait_list->type == BT_AUDIO_ALL) &&
1806 (wait_list->ag_flag == TRUE)) ||
1807 (wait_list->type == BT_AUDIO_A2DP) ||
1808 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1809 bluetooth_device_address_t device_address;
1810 _bt_convert_addr_string_to_type(
1811 device_address.addr,
1812 wait_list->address);
1814 _bt_audio_connect(wait_list->req_id,
1817 wait_list->out_param1);
1819 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1821 if (state == BT_PROFILE_STATE_CONNECTED) {
1822 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1823 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1824 bluetooth_device_address_t device_address;
1826 param = g_variant_new("(is)", result, address);
1827 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1829 connected = _bt_is_headset_type_connected(
1833 if (g_strcmp0(connected_address,
1835 _bt_convert_addr_string_to_type(
1836 device_address.addr,
1838 _bt_audio_disconnect(0,
1840 &device_address, NULL);
1843 BT_DBG("device Path: %s", path);
1844 _bt_add_headset_to_list(BT_AVRCP,
1845 BT_STATE_CONNECTED, address);
1846 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1847 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1848 param = g_variant_new("(is)", result, address);
1849 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1851 /* Remove data from the connected list */
1852 _bt_remove_headset_from_list(BT_AVRCP, address);
1854 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1855 if (state == BT_PROFILE_STATE_CONNECTED) {
1856 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1857 BT_INFO("A2DP Source is connected");
1858 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1859 g_variant_new("(is)", result, address));
1860 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1861 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
1862 BT_INFO("A2DP Source Disconnected");
1863 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1864 g_variant_new("(is)", result, address));
1866 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
1867 ((state == BT_PROFILE_STATE_CONNECTED) ||
1868 (state == BT_PROFILE_STATE_DISCONNECTED))) {
1870 if (state == BT_PROFILE_STATE_CONNECTED)
1871 event = BLUETOOTH_HID_CONNECTED;
1873 event = BLUETOOTH_HID_DISCONNECTED;
1874 param = g_variant_new("(is)", result, address);
1875 _bt_send_event(BT_HID_EVENT, event,
1878 if (state == BT_PROFILE_STATE_CONNECTED)
1879 __bt_set_device_values(TRUE,
1880 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1882 __bt_set_device_values(FALSE,
1883 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1886 g_free(profile_uuid);
1887 } else if (strcasecmp(member, "AdvReport") == 0) {
1889 bt_remote_le_dev_info_t *le_dev_info = NULL;
1890 char *buffer = NULL;
1892 bt_le_adv_info_t *adv_info = NULL;
1893 GVariant *value = NULL;
1894 ret_if(_bt_is_le_scanning() == FALSE);
1896 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
1897 if (le_dev_info == NULL)
1900 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
1901 &le_dev_info->addr_type,
1902 &le_dev_info->adv_type,
1904 &le_dev_info->adv_data_len,
1906 buffer_len = g_variant_get_size(value);
1908 buffer = (char *)g_variant_get_data(value);
1910 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
1911 if (le_dev_info->adv_data == NULL &&
1912 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
1913 _bt_free_le_device_info(le_dev_info);
1914 g_variant_unref(value);
1918 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1919 _bt_send_scan_result_event(le_dev_info, NULL);
1920 _bt_free_le_device_info(le_dev_info);
1921 g_variant_unref(value);
1925 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
1926 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
1927 if (adv_info == NULL) {
1928 _bt_free_le_device_info(le_dev_info);
1929 g_variant_unref(value);
1933 adv_info->addr = g_strdup(le_dev_info->address);
1934 adv_info->data_len = le_dev_info->adv_data_len;
1935 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
1936 if (adv_info->data) {
1937 memcpy(adv_info->data, le_dev_info->adv_data,
1938 le_dev_info->adv_data_len);
1940 __bt_add_adv_ind_info(adv_info);
1943 } else { /* SCAN_RSP */
1944 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
1946 _bt_send_scan_result_event(le_dev_info, adv_info);
1947 __bt_del_adv_ind_info(le_dev_info->address);
1950 _bt_free_le_device_info(le_dev_info);
1951 g_variant_unref(value);
1952 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
1958 g_variant_get(msg, "(qqqq)",
1959 tx_octets, tx_time, rx_octets, rx_time);
1961 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1962 _bt_convert_device_path_to_address(path, address);
1964 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
1965 rx_octets, rx_time);
1966 /* Send event to application */
1967 _bt_send_event(BT_DEVICE_EVENT, event, param);
1973 void __bt_set_audio_values(gboolean connected, char *address)
1976 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1978 /* Set the headset name */
1979 if (connected == TRUE) {
1980 name = _bt_get_bonded_device_name(address);
1982 name = g_strdup("");
1985 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
1987 BT_ERR("vconf_set_str failed");
1992 /* Set the headset state */
1993 if (vconf_get_int(VCONFKEY_BT_DEVICE,
1994 &bt_device_state) != 0) {
1995 BT_ERR("vconf_get_str failed");
1998 #ifdef TIZEN_SUPPORT_DUAL_HF
1999 if ((connected == TRUE) &&
2000 (FALSE == __bt_is_companion_device(address))) {
2001 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2002 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2003 (FALSE == __bt_is_companion_device(address))) {
2004 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2007 if (connected == TRUE) {
2008 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2009 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
2010 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2014 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2015 bt_device_state) != 0) {
2016 BT_ERR("vconf_set_int failed");
2020 void _bt_handle_headset_event(GVariant *msg, const char *path)
2022 int result = BLUETOOTH_ERROR_NONE;
2023 gboolean property_flag = FALSE;
2024 char *property = NULL;
2025 GVariant *value = NULL;
2026 GVariant *param = NULL;
2027 g_variant_get(msg, "(sv)", &property, &value);
2029 ret_if(property == NULL);
2031 BT_DBG("Property = %s \n", property);
2032 /* We allow only 1 headset connection (HSP or HFP)*/
2033 if (strcasecmp(property, "Connected") == 0) {
2034 int event = BLUETOOTH_EVENT_NONE;
2035 bt_headset_wait_t *wait_list;
2037 g_variant_get(value, "b", &property_flag);
2039 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2041 /* Fix : NULL_RETURNS */
2042 if (address == NULL)
2045 _bt_convert_device_path_to_address(path, address);
2047 if (property_flag == TRUE) {
2048 event = BLUETOOTH_EVENT_AG_CONNECTED;
2049 if (_bt_headset_get_local_connection() == FALSE)
2050 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2052 _bt_headset_set_local_connection(FALSE);
2056 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2058 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2059 if (previous_state == BT_STATE_DISCONNECTING)
2060 _bt_send_hf_local_term_event(address);
2062 /* Set the State machine here */
2063 __bt_connection_manager_set_state(address, event);
2064 __bt_set_audio_values(property_flag, address);
2065 param = g_variant_new("(is)", result, address);
2066 _bt_send_event(BT_HEADSET_EVENT, event,
2069 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2070 /* Remove data from the connected list */
2071 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2073 wait_list = _bt_get_audio_wait_data();
2074 if (wait_list == NULL) {
2079 bluetooth_device_address_t device_address;
2081 _bt_set_audio_wait_data_flag(TRUE);
2083 _bt_convert_addr_string_to_type(device_address.addr,
2084 wait_list->address);
2085 _bt_audio_connect(wait_list->req_id, wait_list->type,
2086 &device_address, wait_list->out_param1);
2087 _bt_rel_wait_data();
2088 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2089 /* Add data to the connected list */
2090 _bt_add_headset_to_list(BT_AUDIO_HSP,
2091 BT_STATE_CONNECTED, address);
2093 wait_list = _bt_get_audio_wait_data();
2094 if (wait_list != NULL &&
2095 (g_strcmp0(wait_list->address, address) == 0))
2096 _bt_rel_wait_data();
2098 BT_INFO("Check A2DP pending connect");
2099 _bt_audio_check_pending_connect();
2102 } else if (strcasecmp(property, "State") == 0) {
2105 g_variant_get(value, "s", &state);
2107 /* This code assumes we support only 1 headset connection */
2108 /* Need to use the headset list, if we support multi-headsets */
2109 if (strcasecmp(state, "Playing") == 0) {
2110 BT_DBG("Playing: Sco Connected");
2111 } else if (strcasecmp(state, "connected") == 0 ||
2112 strcasecmp(state, "disconnected") == 0) {
2113 BT_DBG("connected/disconnected: Sco Disconnected");
2115 BT_ERR("Not handled state - %s", state);
2120 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2124 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2126 _bt_convert_device_path_to_address(path, address);
2128 g_variant_get(value, "i", &spkr_gain);
2129 param = g_variant_new("(isq)", result, address, spkr_gain);
2130 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2134 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2138 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2140 _bt_convert_device_path_to_address(path, address);
2142 g_variant_get(value, "i", &mic_gain);
2143 param = g_variant_new("(isq)", result, address, mic_gain);
2144 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2151 g_variant_unref(value);
2154 void _bt_handle_sink_event(GVariant *msg, const char *path)
2156 GVariantIter value_iter;
2157 char *property = NULL;
2159 bt_headset_wait_t *wait_list;
2161 GVariant *child = NULL;
2162 GVariant *val = NULL;
2163 GVariant *param = NULL;
2164 g_variant_iter_init(&value_iter, msg);
2165 while ((child = g_variant_iter_next_value(&value_iter))) {
2167 g_variant_get(child, "{sv}", &property, &val);
2169 ret_if(property == NULL);
2171 BT_DBG("Property = %s \n", property);
2174 if (strcasecmp(property, "State") == 0) {
2175 int result = BLUETOOTH_ERROR_NONE;
2178 g_variant_get(val, "s", &value);
2179 BT_DBG("value: %s", value);
2181 if (g_strcmp0(value, "disconnected") == 0) {
2184 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2186 _bt_convert_device_path_to_address(path, address);
2188 __bt_set_device_values(FALSE,
2189 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2190 param = g_variant_new("(is)", result, address);
2191 _bt_send_event(BT_HEADSET_EVENT,
2192 BLUETOOTH_EVENT_AV_DISCONNECTED,
2195 /* Remove data from the connected list */
2196 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2197 wait_list = _bt_get_audio_wait_data();
2198 if (wait_list == NULL) {
2201 g_variant_unref(val);
2202 g_variant_unref(child);
2207 if (((wait_list->type == BT_AUDIO_ALL) &&
2208 (wait_list->ag_flag == TRUE)) ||
2209 (wait_list->type == BT_AUDIO_A2DP) ||
2210 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2211 bluetooth_device_address_t device_address;
2212 _bt_convert_addr_string_to_type(
2213 device_address.addr,
2214 wait_list->address);
2216 _bt_audio_connect(wait_list->req_id,
2219 wait_list->out_param1);
2222 } else if (strcasecmp(value, "Connected") == 0) {
2224 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2225 bluetooth_device_address_t device_address;
2228 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2230 _bt_convert_device_path_to_address(path, address);
2232 __bt_set_device_values(TRUE,
2233 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2234 param = g_variant_new("(is)", result, address);
2235 _bt_send_event(BT_HEADSET_EVENT,
2236 BLUETOOTH_EVENT_AV_CONNECTED,
2238 /* Check for existing Media device to disconnect */
2239 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2242 /* Match connected device address */
2243 if (g_strcmp0(connected_address, address) != 0) {
2244 /* Convert BD adress from string type */
2245 _bt_convert_addr_string_to_type(
2246 device_address.addr,
2248 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2249 &device_address, NULL);
2253 /* Add data to the connected list */
2254 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2255 BT_STATE_CONNECTED, address);
2262 g_variant_unref(val);
2263 g_variant_unref(child);
2267 void _bt_handle_agent_event(GVariant *msg, const char *member)
2269 int result = BLUETOOTH_ERROR_NONE;
2270 char *address = NULL;
2273 GVariant *param = NULL;
2274 ret_if(member == NULL);
2276 if (strcasecmp(member, "ObexAuthorize") == 0) {
2277 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2278 param = g_variant_new("(iss)", result, address, name);
2279 _bt_send_event(BT_OPP_SERVER_EVENT,
2280 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2284 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2285 bt_rfcomm_server_info_t *server_info;
2287 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2289 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2290 ret_if(server_info == NULL);
2291 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2292 param = g_variant_new("(isssn)", result, address, uuid, name,
2293 server_info->control_fd);
2294 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2295 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2303 static int __bt_get_object_path(GVariant *msg, char **path)
2305 g_variant_get(msg, "(o*)", path, NULL);
2307 return BLUETOOTH_ERROR_INTERNAL;
2309 return BLUETOOTH_ERROR_NONE;
2312 static void __bt_devices_list_free(void)
2314 bt_cache_info_t *cache_info;
2317 node = g_list_first(p_cache_list);
2319 while (node != NULL) {
2320 cache_info = (bt_cache_info_t *)node->data;
2321 p_cache_list = g_list_remove(p_cache_list, cache_info);
2322 __bt_free_cache_info(cache_info);
2324 node = g_list_next(node);
2328 static int __bt_parse_event(GVariant *msg)
2332 char *interface_name = NULL;
2333 GVariant *inner_iter = NULL;
2335 g_variant_iter_init(&iter, msg);
2337 while ((child = g_variant_iter_next_value(&iter))) {
2338 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2339 if (g_strcmp0(interface_name,
2340 BT_DEVICE_INTERFACE) == 0) {
2341 g_variant_unref(inner_iter);
2342 g_variant_unref(child);
2343 return BT_DEVICE_EVENT;
2344 } else if (g_strcmp0(interface_name,
2345 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2346 g_variant_unref(inner_iter);
2347 g_variant_unref(child);
2348 return BT_MEDIA_TRANSFER_EVENT;
2349 } else if (g_strcmp0(interface_name,
2350 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2351 g_variant_unref(inner_iter);
2352 g_variant_unref(child);
2353 return BT_AVRCP_CONTROL_EVENT;
2355 g_variant_unref(inner_iter);
2356 g_variant_unref(child);
2362 static void __bt_manager_event_filter(GDBusConnection *connection,
2363 const gchar *sender_name,
2364 const gchar *object_path,
2365 const gchar *interface_name,
2366 const gchar *signal_name,
2367 GVariant *parameters,
2370 bt_event_type_t bt_event = 0x00;
2371 int result = BLUETOOTH_ERROR_NONE;
2373 char *obj_path = NULL;
2374 GVariant *param = NULL;
2375 if (signal_name == NULL)
2377 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2378 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2380 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2381 #ifdef USB_BLUETOOTH
2382 BT_DBG("Enable Adapter");
2383 _bt_enable_adapter();
2385 _bt_handle_adapter_added();
2388 bt_event = __bt_parse_event(value);
2389 if (bt_event == BT_DEVICE_EVENT) {
2390 bt_cache_info_t *cache_info;
2391 bt_remote_dev_info_t *dev_info;
2393 ret_if(_bt_is_discovering() == FALSE &&
2394 _bt_is_le_scanning() == FALSE);
2396 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2397 ret_if(cache_info == NULL);
2399 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2400 if (dev_info == NULL) {
2401 __bt_free_cache_info(cache_info);
2405 cache_info->dev_info = dev_info;
2407 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2408 BT_ERR("Fail to parse the properies");
2409 __bt_free_cache_info(cache_info);
2410 g_variant_unref(value);
2414 if (dev_info->addr_type != BDADDR_BREDR) {
2415 /* Whenever emit the property changed from bluez,
2416 some property doesn't reach to bt-service.
2417 So LE device is handled as AdvReport signal */
2418 __bt_free_cache_info(cache_info);
2419 g_variant_unref(value);
2423 if (dev_info->name == NULL)
2424 /* If Remote device name is NULL or still RNR is not done
2425 * then display address as name.
2427 dev_info->name = g_strdup(dev_info->address);
2429 #ifdef TIZEN_DPM_ENABLE
2430 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
2432 bluetooth_device_class_t device_class;
2433 _bt_divide_device_class(&device_class, dev_info->class);
2434 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2436 if (device_class.major_class ==
2437 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2438 __bt_free_cache_info(cache_info);
2439 g_variant_unref(value);
2445 GVariant *uuids = NULL;
2446 GVariantBuilder *builder = NULL;
2448 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2449 for (i = 0; i < dev_info->uuid_count; i++) {
2450 g_variant_builder_add(builder, "s",
2451 dev_info->uuids[i]);
2453 uuids = g_variant_new("as", builder);
2454 g_variant_builder_unref(builder);
2455 GVariant *manufacturer_data = NULL;
2456 manufacturer_data = g_variant_new_from_data(
2457 G_VARIANT_TYPE_BYTESTRING,
2458 dev_info->manufacturer_data,
2459 dev_info->manufacturer_data_len,
2461 param = g_variant_new("(isunsbub@asn@ay)", result,
2467 dev_info->connected,
2470 dev_info->manufacturer_data_len,
2472 _bt_send_event(BT_ADAPTER_EVENT,
2473 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2475 p_cache_list = g_list_append(p_cache_list, cache_info);
2476 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2477 BT_DBG("Device path : %s ", obj_path);
2478 _bt_set_control_device_path(obj_path);
2481 g_variant_unref(value);
2482 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2483 #ifdef USB_BLUETOOTH
2484 BT_DBG("InterfacesRemoved");
2485 _bt_handle_adapter_removed();
2487 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2488 bt_event = BT_MEDIA_TRANSFER_EVENT;
2489 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2490 bt_event = BT_DEVICE_EVENT;
2491 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2492 bt_event = BT_AVRCP_CONTROL_EVENT;
2494 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2495 _bt_handle_adapter_event(parameters, signal_name);
2496 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2497 BT_INFO("Object Path %s", obj_path);
2498 _bt_remove_control_device_path(obj_path);
2501 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2504 char *previous = NULL;
2505 char *current = NULL;
2507 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2508 BT_ERR("Fail to get the owner info");
2512 if (*current != '\0') {
2521 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2522 BT_DBG("Bluetoothd is terminated");
2523 if (_bt_adapter_get_status() == BT_ACTIVATED)
2526 _bt_handle_adapter_removed();
2527 __bt_devices_list_free();
2530 _bt_obex_server_check_allocation(&value);
2532 if (value == TRUE) {
2533 /* Check if the obex server was terminated abnormally */
2534 _bt_obex_server_check_termination(name);
2537 _bt_rfcomm_server_check_existence(&value);
2539 if (value == TRUE) {
2540 /* The obex server was terminated abnormally */
2541 _bt_rfcomm_server_check_termination(name);
2544 /* Stop advertising started by terminated process */
2545 _bt_stop_advertising_by_terminated_process(name);
2547 _bt_stop_le_scan(name);
2551 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2552 const char *path = object_path;
2554 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2555 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2558 _bt_handle_property_changed_event(parameters, object_path);
2559 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2560 _bt_handle_adapter_event(parameters, signal_name);
2561 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2562 _bt_handle_input_event(parameters, object_path);
2563 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2564 _bt_handle_network_server_event(parameters, signal_name);
2565 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2566 _bt_handle_headset_event(parameters, object_path);
2567 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2568 _bt_handle_sink_event(parameters, object_path);
2569 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2570 _bt_handle_agent_event(parameters, signal_name);
2571 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2572 _bt_handle_device_event(parameters, signal_name, object_path);
2573 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2574 _bt_handle_gatt_event(parameters, signal_name, object_path);
2580 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2583 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2584 char *interface_name = NULL;
2586 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2587 retv_if(interface_name == NULL, FALSE);
2589 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2590 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2598 static void __bt_obexd_event_filter(GDBusConnection *connection,
2599 const gchar *sender_name,
2600 const gchar *object_path,
2601 const gchar *interface_name,
2602 const gchar *signal_name,
2603 GVariant *parameters,
2606 const char *member = signal_name;
2607 char *obj_path = NULL;
2608 ret_if(member == NULL);
2610 if (strcasecmp(member, "InterfacesAdded") == 0) {
2611 if (__bt_get_object_path(parameters, &obj_path)) {
2612 BT_ERR("Fail to get the path");
2615 BT_INFO("object_path = [%s]", object_path);
2617 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2618 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2619 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2624 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2625 BT_DBG("Obex_Server_Session_Transfer connected");
2626 _bt_obex_transfer_connected();
2629 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2630 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2631 if (__bt_get_object_path(parameters, &obj_path)) {
2632 BT_ERR("Fail to get the path");
2635 BT_INFO("object_path = [%s]", object_path);
2637 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2638 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2639 BT_DBG("Call PBAP Disconnected");
2640 _bt_obex_pbap_client_disconnect(obj_path);
2643 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2644 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2649 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2650 BT_DBG("Obex_Server_Session_Transfer disconnected");
2651 _bt_obex_transfer_disconnected();
2654 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2655 const char *path = object_path;
2657 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2658 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2659 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2660 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2661 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2665 _bt_handle_property_changed_event(parameters, path);
2671 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2675 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2676 char *interface_name = NULL;
2678 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2680 retv_if(interface_name == NULL, FALSE);
2682 if (strcasecmp(interface_name,
2683 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2694 static void __bt_opc_event_filter(GDBusConnection *connection,
2695 const gchar *sender_name,
2696 const gchar *object_path,
2697 const gchar *interface_name,
2698 const gchar *signal_name,
2699 GVariant *parameters,
2702 const char *member = signal_name;
2703 char *obj_path = NULL;
2704 if (strcasecmp(member, "InterfacesAdded") == 0) {
2705 BT_DBG("InterfacesAdded");
2706 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2708 if (__bt_get_object_path(parameters, &obj_path)) {
2709 BT_ERR("Fail to get the path");
2713 BT_DBG("object_path = %s", obj_path);
2715 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2716 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2717 || strstr(obj_path, "transfer") == NULL) {
2720 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2721 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2722 BT_DBG("Going to call opc disconnected");
2723 _bt_opc_disconnected(obj_path);
2726 _bt_sending_files();
2728 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
2729 char *path = (char *)object_path;
2730 BT_INFO("object_path %s", path);
2731 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2732 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2733 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2737 _bt_opc_property_changed_event(parameters, path);
2743 int _bt_opp_client_event_init(void)
2745 GError *error = NULL;
2747 if (opc_obexd_conn == NULL) {
2748 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2750 if (!opc_obexd_conn) {
2752 BT_ERR("Unable to connect to dbus: %s", error->message);
2753 g_clear_error(&error);
2755 return BLUETOOTH_ERROR_INTERNAL;
2759 if (_bt_register_service_event(opc_obexd_conn,
2760 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2761 g_object_unref(opc_obexd_conn);
2762 opc_obexd_conn = NULL;
2763 return BLUETOOTH_ERROR_INTERNAL;
2766 return BLUETOOTH_ERROR_NONE;
2769 void _bt_opp_client_event_deinit(void)
2771 if (opc_obexd_conn) {
2772 _bt_unregister_service_event(opc_obexd_conn,
2773 BT_OPP_CLIENT_EVENT);
2774 g_object_unref(opc_obexd_conn);
2775 opc_obexd_conn = NULL;
2779 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2785 static int subs_interface_added_id = -1;
2786 static int subs_interface_removed_id = -1;
2787 static int subs_name_owner_id = -1;
2788 static int subs_property_id = -1;
2789 static int subs_adapter_id = -1;
2790 static int subs_gatt_id = -1;
2793 if (subs_interface_added_id == -1) {
2794 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2795 NULL, BT_MANAGER_INTERFACE,
2796 BT_INTERFACES_ADDED, NULL, NULL, 0,
2797 __bt_manager_event_filter,
2800 if (subs_interface_removed_id == -1) {
2801 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2802 NULL, BT_MANAGER_INTERFACE,
2803 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2804 __bt_manager_event_filter,
2807 if (subs_name_owner_id == -1) {
2808 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
2809 NULL, BT_FREEDESKTOP_INTERFACE,
2810 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
2811 __bt_manager_event_filter,
2814 if (subs_property_id == -1) {
2815 subs_property_id = g_dbus_connection_signal_subscribe(conn,
2816 NULL, BT_PROPERTIES_INTERFACE,
2817 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2818 __bt_manager_event_filter,
2821 if (subs_adapter_id == -1) {
2822 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
2823 NULL, BT_ADAPTER_INTERFACE,
2824 NULL, NULL, NULL, 0,
2825 __bt_manager_event_filter,
2828 if (subs_gatt_id == -1) {
2829 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
2830 NULL, BT_GATT_CHAR_INTERFACE,
2831 NULL, NULL, NULL, 0,
2832 __bt_manager_event_filter,
2836 if (subs_interface_added_id != -1) {
2837 g_dbus_connection_signal_unsubscribe(conn,
2838 subs_interface_added_id);
2839 subs_interface_added_id = -1;
2841 if (subs_interface_removed_id != -1) {
2842 g_dbus_connection_signal_unsubscribe(conn,
2843 subs_interface_removed_id);
2844 subs_interface_removed_id = -1;
2846 if (subs_name_owner_id != -1) {
2847 g_dbus_connection_signal_unsubscribe(conn,
2848 subs_name_owner_id);
2849 subs_name_owner_id = -1;
2851 if (subs_property_id != -1) {
2852 g_dbus_connection_signal_unsubscribe(conn,
2854 subs_property_id = -1;
2856 if (subs_adapter_id != -1) {
2857 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
2858 subs_adapter_id = -1;
2860 if (subs_gatt_id != -1) {
2861 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
2868 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
2874 static int subs_device_id = -1;
2877 if (subs_device_id == -1) {
2878 subs_device_id = g_dbus_connection_signal_subscribe(conn,
2879 NULL, BT_DEVICE_INTERFACE,
2880 NULL, NULL, NULL, 0,
2881 __bt_manager_event_filter,
2885 if (subs_device_id != -1) {
2886 g_dbus_connection_signal_unsubscribe(conn,
2888 subs_device_id = -1;
2894 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
2900 static int subs_input_id = -1;
2903 if (subs_input_id == -1) {
2904 subs_input_id = g_dbus_connection_signal_subscribe(conn,
2905 NULL, BT_INPUT_INTERFACE,
2906 NULL, NULL, NULL, 0,
2907 __bt_manager_event_filter,
2911 if (subs_input_id != -1) {
2912 g_dbus_connection_signal_unsubscribe(conn,
2920 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
2926 static int subs_serv_id = -1;
2927 static int subs_client_id = -1;
2930 if (subs_serv_id == -1) {
2931 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
2932 NULL, BT_NETWORK_SERVER_INTERFACE,
2933 NULL, NULL, NULL, 0,
2934 __bt_manager_event_filter,
2937 if (subs_client_id == -1) {
2938 subs_client_id = g_dbus_connection_signal_subscribe(conn,
2939 NULL, BT_NETWORK_CLIENT_INTERFACE,
2940 NULL, NULL, NULL, 0,
2941 __bt_manager_event_filter,
2945 if (subs_serv_id != -1) {
2946 g_dbus_connection_signal_unsubscribe(conn,
2950 if (subs_client_id != -1) {
2951 g_dbus_connection_signal_unsubscribe(conn,
2953 subs_client_id = -1;
2959 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
2965 static int subs_headset_id = -1;
2966 static int subs_sink_id = -1;
2969 if (subs_headset_id == -1) {
2970 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
2971 NULL, BT_HEADSET_INTERFACE,
2972 NULL, NULL, NULL, 0,
2973 __bt_manager_event_filter,
2976 if (subs_sink_id == -1) {
2977 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
2978 NULL, BT_SINK_INTERFACE,
2979 NULL, NULL, NULL, 0,
2980 __bt_manager_event_filter,
2984 if (subs_headset_id != -1) {
2985 g_dbus_connection_signal_unsubscribe(conn,
2987 subs_headset_id = -1;
2989 if (subs_sink_id != -1) {
2990 g_dbus_connection_signal_unsubscribe(conn,
2998 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3004 static int subs_opp_server_interface_added_id = -1;
3005 static int subs_opp_server_interface_removed_id = -1;
3006 static int subs_opp_server_property_id = -1;
3010 if (subs_opp_server_interface_added_id == -1) {
3011 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3012 NULL, BT_MANAGER_INTERFACE,
3013 BT_INTERFACES_ADDED, NULL, NULL, 0,
3014 __bt_obexd_event_filter,
3017 if (subs_opp_server_interface_removed_id == -1) {
3018 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3019 NULL, BT_MANAGER_INTERFACE,
3020 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3021 __bt_obexd_event_filter,
3024 if (subs_opp_server_property_id == -1) {
3025 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3026 NULL, BT_PROPERTIES_INTERFACE,
3027 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3028 __bt_obexd_event_filter,
3032 if (subs_opp_server_interface_added_id != -1) {
3033 g_dbus_connection_signal_unsubscribe(conn,
3034 subs_opp_server_interface_added_id);
3035 subs_opp_server_interface_added_id = -1;
3037 if (subs_opp_server_interface_removed_id != -1) {
3038 g_dbus_connection_signal_unsubscribe(conn,
3039 subs_opp_server_interface_removed_id);
3040 subs_opp_server_interface_removed_id = -1;
3042 if (subs_opp_server_property_id != -1) {
3043 g_dbus_connection_signal_unsubscribe(conn,
3044 subs_opp_server_property_id);
3045 subs_opp_server_property_id = -1;
3051 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3057 static int subs_opp_client_interface_added_id = -1;
3058 static int subs_opp_client_interface_removed_id = -1;
3059 static int subs_opp_client_property_id = -1;
3063 if (subs_opp_client_interface_added_id == -1) {
3064 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3065 NULL, BT_MANAGER_INTERFACE,
3066 BT_INTERFACES_ADDED, NULL, NULL, 0,
3067 __bt_opc_event_filter,
3070 if (subs_opp_client_interface_removed_id == -1) {
3071 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3072 NULL, BT_MANAGER_INTERFACE,
3073 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3074 __bt_opc_event_filter,
3077 if (subs_opp_client_property_id == -1) {
3078 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3079 NULL, BT_PROPERTIES_INTERFACE,
3080 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3081 __bt_opc_event_filter,
3085 if (subs_opp_client_interface_added_id != -1) {
3086 g_dbus_connection_signal_unsubscribe(conn,
3087 subs_opp_client_interface_added_id);
3088 subs_opp_client_interface_added_id = -1;
3090 if (subs_opp_client_interface_removed_id != -1) {
3091 g_dbus_connection_signal_unsubscribe(conn,
3092 subs_opp_client_interface_removed_id);
3093 subs_opp_client_interface_removed_id = -1;
3095 if (subs_opp_client_property_id != -1) {
3096 g_dbus_connection_signal_unsubscribe(conn,
3097 subs_opp_client_property_id);
3098 subs_opp_client_property_id = -1;
3104 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3110 static int subs_a2dp_source_id = -1;
3111 static int subs_a2dp_sink_id = -1;
3114 if (subs_a2dp_source_id == -1) {
3115 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3116 NULL, BT_A2DP_SOURCE_INTERFACE,
3117 NULL, NULL, NULL, 0,
3118 __bt_opc_event_filter,
3121 if (subs_a2dp_sink_id == -1) {
3122 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3123 NULL, BT_SINK_INTERFACE,
3124 NULL, NULL, NULL, 0,
3125 __bt_opc_event_filter,
3129 if (subs_a2dp_source_id != -1) {
3130 g_dbus_connection_signal_unsubscribe(conn,
3131 subs_a2dp_source_id);
3132 subs_a2dp_source_id = -1;
3134 if (subs_a2dp_sink_id != -1) {
3135 g_dbus_connection_signal_unsubscribe(conn,
3137 subs_a2dp_sink_id = -1;
3143 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3147 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3149 switch (event_type) {
3150 case BT_MANAGER_EVENT:
3151 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3153 case BT_DEVICE_EVENT:
3154 _bt_register_device_subscribe_signal(g_conn, TRUE);
3157 _bt_register_input_subscribe_signal(g_conn, TRUE);
3159 case BT_NETWORK_EVENT:
3160 _bt_register_network_subscribe_signal(g_conn, TRUE);
3162 case BT_HEADSET_EVENT:
3163 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3166 case BT_OPP_SERVER_EVENT:
3167 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3168 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3170 case BT_OPP_CLIENT_EVENT:
3171 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3172 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3174 case BT_A2DP_SOURCE_EVENT:
3175 BT_INFO("A2dp Source event");
3176 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3179 BT_ERR("Unknown event");
3180 return BLUETOOTH_ERROR_INTERNAL;
3183 return BLUETOOTH_ERROR_NONE;
3186 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3190 ret_if(g_conn == NULL);
3192 switch (event_type) {
3193 case BT_MANAGER_EVENT:
3194 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3195 _bt_register_device_subscribe_signal(g_conn, FALSE);
3196 _bt_register_input_subscribe_signal(g_conn, FALSE);
3197 _bt_register_network_subscribe_signal(g_conn, FALSE);
3198 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3200 case BT_OPP_SERVER_EVENT:
3201 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3203 case BT_OPP_CLIENT_EVENT:
3204 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3207 BT_ERR("Unknown event");
3214 static int __bt_init_manager_receiver(void)
3218 GError *error = NULL;
3220 if (manager_conn == NULL) {
3221 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3222 if (error != NULL) {
3223 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3224 g_clear_error(&error);
3226 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3229 if (_bt_register_service_event(manager_conn,
3230 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3232 if (_bt_register_service_event(manager_conn,
3233 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3236 if (_bt_register_service_event(manager_conn,
3237 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3240 if (_bt_register_service_event(manager_conn,
3241 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3244 if (_bt_register_service_event(manager_conn,
3245 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3247 return BLUETOOTH_ERROR_NONE;
3250 g_object_unref(manager_conn);
3251 manager_conn = NULL;
3256 return BLUETOOTH_ERROR_INTERNAL;
3259 static int __bt_init_obexd_receiver(void)
3262 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3263 GError *error = NULL;
3265 if (obexd_conn == NULL) {
3266 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3267 if (error != NULL) {
3268 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3269 g_clear_error(&error);
3271 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3274 if (_bt_register_service_event(obexd_conn,
3275 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3276 BT_ERR("Error while registering service event");
3277 g_object_unref(obexd_conn);
3279 return BLUETOOTH_ERROR_INTERNAL;
3284 return BLUETOOTH_ERROR_NONE;
3287 /* To receive the event from bluez */
3288 int _bt_init_service_event_receiver(void)
3294 result = __bt_init_manager_receiver();
3295 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3297 result = __bt_init_obexd_receiver();
3298 if (result != BLUETOOTH_ERROR_NONE)
3299 BT_ERR("Fail to init obexd receiver");
3303 return BLUETOOTH_ERROR_NONE;
3306 void _bt_deinit_service_event_receiver(void)
3310 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3312 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3315 g_object_unref(manager_conn);
3316 manager_conn = NULL;
3320 g_object_unref(obexd_conn);
3325 g_source_remove(event_id);