4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
28 #include <vconf-internal-bt-keys.h>
30 #include <journal/device.h>
33 #include "bluetooth-api.h"
34 #include "bt-internal-types.h"
36 #include "bt-service-common.h"
37 #include "bt-service-event.h"
38 #include "bt-service-main.h"
39 #include "bt-service-adapter.h"
40 #include "bt-service-adapter-le.h"
41 #include "bt-service-device.h"
42 #include "bt-service-avrcp.h"
43 #include "bt-service-obex-server.h"
44 #include "bt-service-rfcomm-server.h"
45 #include "bt-service-audio.h"
46 #include "bt-service-agent.h"
47 #include "bt-service-pbap.h"
48 #include "bt-service-headset-connection.h"
49 #include "bt-service-avrcp-controller.h"
51 #include "bt-service-opp-client.h"
53 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
54 static GDBusConnection *manager_conn;
55 static GDBusConnection *obexd_conn;
56 static GDBusConnection *opc_obexd_conn;
58 static GList *p_cache_list = NULL;
60 static guint event_id;
61 guint nap_connected_device_count = 0;
62 static guint hid_connected_device_count = 0;
63 static GList *p_adv_ind_list;
66 bt_remote_dev_info_t *dev_info;
70 * obexd connection type
78 OBEX_PCSUITE = (1 << 6),
79 OBEX_SYNCEVOLUTION = (1 << 7),
81 } bluetooth_obex_connection_type_t;
83 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
84 void _bt_opc_property_changed_event(GVariant *msg, char *path);
85 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
86 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
87 void _bt_opp_client_event_deinit(void);
88 void _bt_handle_network_client_event(GVariant *msg_iter,
90 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
93 static void __bt_free_bt_le_adv_info_t(bt_le_adv_info_t *adv_info)
95 g_free(adv_info->addr);
96 g_free(adv_info->data);
100 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
102 retv_if(!addr, NULL);
103 bt_le_adv_info_t *adv_info = NULL;
104 GList *current = g_list_first((GList *)p_adv_ind_list);
105 while(current && current->data) {
106 adv_info = (bt_le_adv_info_t *)current->data;
107 retv_if(adv_info && !g_strcmp0(adv_info->addr, addr), adv_info);
108 current = g_list_next(current);
113 static void __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
116 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
117 BT_ERR("adv_info is already added");
118 __bt_free_bt_le_adv_info_t(adv_info);
121 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
124 static void __bt_del_adv_ind_info(char *addr)
127 ret_if(!p_adv_ind_list);
128 bt_le_adv_info_t *adv_info = NULL;
129 GList *current = g_list_first((GList *)p_adv_ind_list);
130 while(current && current->data) {
131 adv_info = (bt_le_adv_info_t *)current->data;
132 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
133 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
134 __bt_free_bt_le_adv_info_t(adv_info);
137 current = g_list_next(current);
141 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
143 ret_if(cache_info == NULL);
144 _bt_free_device_info(cache_info->dev_info);
148 static gboolean __bt_parse_device_properties(GVariant *item,
149 bt_remote_dev_info_t *dev_info)
158 g_variant_iter_init(&iter, item);
159 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
160 if (strcasecmp(key, "Address") == 0) {
161 dev_info->address = g_variant_dup_string(val, &len);
162 } else if (strcasecmp(key, "Class") == 0) {
163 dev_info->class = g_variant_get_uint32(val);
164 } else if (strcasecmp(key, "name") == 0) {
165 if (dev_info->name == NULL)
166 dev_info->name = g_variant_dup_string(val, &len);
167 } else if (strcasecmp(key, "Connected") == 0) {
168 dev_info->connected = g_variant_get_uint32(val);
169 } else if (strcasecmp(key, "paired") == 0) {
170 dev_info->paired = g_variant_get_boolean(val);
171 } else if (strcasecmp(key, "Trusted") == 0) {
172 dev_info->trust = g_variant_get_boolean(val);
173 } else if (strcasecmp(key, "RSSI") == 0) {
174 dev_info->rssi = g_variant_get_int16(val);
175 } else if (strcasecmp(key, "LastAddrType") == 0) {
176 dev_info->addr_type = g_variant_get_byte(val);
177 } else if (strcasecmp(key, "UUIDs") == 0) {
181 size = g_variant_get_size(val);
184 uuid_value = (char **)g_variant_get_strv(val, &size);
185 if (dev_info->uuids == NULL)
186 dev_info->uuids = g_malloc0(sizeof(char *) * size);
188 for (i = 0; uuid_value[i] != NULL; i++) {
189 dev_info->uuid_count++;
190 dev_info->uuids[i] = g_strdup(uuid_value[i]);
194 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
195 g_variant_get(val, "(i)", &dev_info->manufacturer_data_len);
196 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
197 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
198 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
201 if (dev_info->manufacturer_data_len == 0)
202 dev_info->manufacturer_data = g_strdup("");
203 } else if (strcasecmp(key, "ManufacturerData") == 0) {
205 GVariant *manufacturer_var;
206 g_variant_get(val, "@ay", &manufacturer_var);
207 len = g_variant_get_size(manufacturer_var);
209 char *manufacturer_data = (char *)g_variant_get_data(manufacturer_var);
210 dev_info->manufacturer_data = g_malloc0(len);
211 memcpy(dev_info->manufacturer_data, manufacturer_data,
214 g_variant_unref(manufacturer_var);
222 static gboolean __bt_parse_interface(GVariant *msg,
223 bt_remote_dev_info_t *dev_info)
226 GVariant *optional_param;
229 char *interface_name= NULL;
230 GVariant *inner_iter = NULL;
231 g_variant_get(msg, "(&o@a{sa{sv}})",
232 &path, &optional_param);
233 g_variant_iter_init(&iter, optional_param);
235 while ((child = g_variant_iter_next_value(&iter))) {
236 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
237 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
238 BT_DBG("Found a device: %s", path);
239 if (__bt_parse_device_properties(inner_iter,
240 dev_info) == FALSE) {
241 g_variant_unref(inner_iter);
242 g_variant_unref(child);
243 g_variant_unref(optional_param);
244 BT_ERR("Fail to parse the properies");
247 g_variant_unref(inner_iter);
248 g_variant_unref(child);
249 g_variant_unref(optional_param);
253 g_variant_unref(inner_iter);
254 g_variant_unref(child);
257 g_variant_unref(optional_param);
262 static int __bt_get_owner_info(GVariant *msg, char **name,
263 char **previous, char **current)
265 g_variant_get(msg, "(sss)", name, previous, current);
266 return BLUETOOTH_ERROR_NONE;
269 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
270 char **name, char **uuid)
272 g_variant_get(msg, "(sss)", address, name, uuid);
273 return BLUETOOTH_ERROR_NONE;
276 void __bt_set_device_values(gboolean connected, int state)
278 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
280 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) {
281 BT_ERR("vconf_get_int failed");
284 if (connected == TRUE)
285 bt_device_state |= state;
286 else if (bt_device_state & state)
287 bt_device_state ^= state;
289 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) {
290 BT_ERR("vconf_set_int failed");
294 gboolean _bt_discovery_finished_cb(gpointer user_data)
296 int result = BLUETOOTH_ERROR_NONE;
298 GVariant *param = NULL;
299 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
300 if (_bt_get_cancel_by_user() == TRUE) {
301 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
304 _bt_set_cancel_by_user(FALSE);
305 _bt_disable_all_scanner_status();
306 _bt_set_discovery_status(FALSE);
307 param = g_variant_new("(i)", result);
308 _bt_send_event(BT_ADAPTER_EVENT,
309 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
316 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
318 int result = BLUETOOTH_ERROR_NONE;
320 GVariant *param = NULL;
321 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
322 if (_bt_get_cancel_by_user() == TRUE) {
323 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
326 _bt_set_cancel_by_user(FALSE);
327 _bt_set_le_scan_status(FALSE);
328 param = g_variant_new("(i)", result);
329 _bt_send_event(BT_LE_ADAPTER_EVENT,
330 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
337 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
341 ret_if(address == NULL);
344 bt_cache_info_t *cache_info;
345 bt_remote_dev_info_t *dev_info;
347 node = g_list_first(p_cache_list);
349 while (node != NULL){
350 cache_info = (bt_cache_info_t *)node->data;
352 if (cache_info == NULL) {
353 node = g_list_next(node);
357 dev_info = cache_info->dev_info;
358 if (strcasecmp(dev_info->address,
360 BT_DBG("Device Found");
361 if (paired_status == TRUE)
362 cache_info->dev_info->paired = TRUE;
364 cache_info->dev_info->paired = FALSE;
367 node = g_list_next(node);
372 static void __bt_device_remote_connected_properties(
373 bt_remote_dev_info_t *remote_dev_info,
374 char *address, gboolean connected)
376 int result = BLUETOOTH_ERROR_NONE;
378 GVariant *param = NULL;
381 if (remote_dev_info->uuid_count > 0 ) {
382 for (i = 0; i<remote_dev_info->uuid_count; i++) {
383 char *uuid = remote_dev_info->uuids[i];
384 if (strcasecmp(uuid, HID_UUID) == 0){
385 int event = BLUETOOTH_EVENT_NONE;
387 event = (connected == TRUE) ?
388 BLUETOOTH_HID_CONNECTED :
389 BLUETOOTH_HID_DISCONNECTED;
390 param = g_variant_new("(is)", result,
392 _bt_send_event(BT_HID_EVENT, event,
402 void _bt_handle_adapter_event(GVariant *msg, const char *member)
406 int result = BLUETOOTH_ERROR_NONE;
407 GVariant *param = NULL;
408 ret_if(member == NULL);
410 if (strcasecmp(member, "DeviceCreated") == 0) {
411 char *object_path = NULL;
413 bt_remote_dev_info_t *remote_dev_info;
415 ret_if(_bt_is_device_creating() == FALSE);
417 /* Bonding from remote device */
418 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
420 g_variant_get(msg, "(&o)", &object_path);
421 _bt_convert_device_path_to_address((const char*)object_path, address);
423 remote_dev_info = _bt_get_remote_device_info(address);
424 if (remote_dev_info == NULL) {
429 _bt_free_device_info(remote_dev_info);
431 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
432 char *object_path = NULL;
434 bt_cache_info_t *cache_info;
435 bt_remote_dev_info_t *dev_info;
438 /* Bonding from remote device */
439 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
440 g_variant_get(msg, "(&o)", &object_path);
442 /* Fix : NULL_RETURNS */
446 _bt_convert_device_path_to_address((const char *)object_path, address);
448 node = g_list_first(p_cache_list);
450 while (node != NULL){
451 cache_info = (bt_cache_info_t *)node->data;
453 if (cache_info == NULL) {
454 node = g_list_next(node);
458 dev_info = cache_info->dev_info;
459 if (strcasecmp(dev_info->address,
461 p_cache_list = g_list_remove(p_cache_list,
463 __bt_free_cache_info(cache_info);
466 node = g_list_next(node);
469 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
470 BT_DBG("Advertising Enabled");
475 gboolean status = FALSE;
477 g_variant_get(msg, "(ib)", &slot_id, &status);
479 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
481 /* Send event to application */
482 _bt_set_advertising_status(slot_id, status);
484 sender = _bt_get_adv_slot_owner(slot_id);
485 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
488 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
490 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
491 param = g_variant_new("(ii)", result,
493 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
497 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
498 __bt_unregister_adv_slot_owner(slot_id);
499 } else if (strcasecmp(member, "RssiEnabled") == 0) {
500 BT_DBG("RSSI Enabled");
501 gboolean status = FALSE;
502 char *address = NULL;
504 g_variant_get(msg,"(sib)", &address, &link_type, &status);
506 BT_DBG("RSSI Enabled [%s %d]", address, status);
507 param = g_variant_new("(isib)", result,
508 address, link_type, status);
509 _bt_send_event(BT_DEVICE_EVENT,
510 BLUETOOTH_EVENT_RSSI_ENABLED,
513 } else if (strcasecmp(member, "RssiAlert") == 0) {
514 BT_DBG("RSSI Alert");
518 char *address = NULL;
519 g_variant_get(msg,"(siii)", &address, &link_type, &alert_type, &rssi_dbm);
521 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
522 address, alert_type, rssi_dbm);
523 param = g_variant_new("(isiii)", result,
524 address, link_type, alert_type, rssi_dbm);
525 _bt_send_event(BT_DEVICE_EVENT,
526 BLUETOOTH_EVENT_RSSI_ALERT,
529 } else if (strcasecmp(member, "RawRssi") == 0) {
533 char *address = NULL;
534 g_variant_get(msg,"(sii)", &address, &link_type, &rssi_dbm);
536 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
537 address, link_type, rssi_dbm);
538 param = g_variant_new("(isii)", result,
539 address, link_type, rssi_dbm);
540 _bt_send_event(BT_DEVICE_EVENT,
541 BLUETOOTH_EVENT_RAW_RSSI,
544 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
545 BT_ERR_C("Hardware error received from BLUEZ");
546 _bt_recover_adapter();
547 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
548 BT_ERR_C("Tx timeout error received from BLUEZ");
549 _bt_recover_adapter();
554 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
556 GDBusProxy *adapter_proxy;
558 int result = BLUETOOTH_ERROR_NONE;
559 GVariantIter value_iter;
560 GVariant *val = NULL;
562 char *property = NULL;
563 GVariant *param = NULL;
564 g_variant_iter_init (&value_iter, msg);
565 while ((g_variant_iter_loop (&value_iter,"{sv}", &property, &val))) {
566 BT_INFO("Property %s", property);
568 if (strcasecmp(property, "Discovering") == 0) {
569 gboolean discovering = FALSE;
570 g_variant_get(val, "b", &discovering);
571 /* Send event to application */
572 BT_DBG("Discovering %d", discovering);
573 if (discovering == TRUE) {
574 _bt_set_discovery_status(TRUE);
575 param = g_variant_new("(i)", result);
576 _bt_send_event(BT_ADAPTER_EVENT,
577 BLUETOOTH_EVENT_DISCOVERY_STARTED,
580 ret_if(event_id > 0);
582 adapter_proxy = _bt_get_adapter_proxy();
583 ret_if(adapter_proxy == NULL);
585 /* Need to stop searching */
586 g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
588 G_DBUS_CALL_FLAGS_NONE,
592 BT_ERR("Dbus Error : %s", err->message);
596 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
597 (GSourceFunc)_bt_discovery_finished_cb, NULL);
599 } else if (strcasecmp(property, "LEDiscovering") == 0) {
600 gboolean le_discovering = FALSE;
602 g_variant_get(val, "b", &le_discovering);
603 /* Send event to application */
604 if (le_discovering == TRUE) {
605 _bt_set_le_scan_status(TRUE);
606 param = g_variant_new("(i)", result);
607 _bt_send_event(BT_LE_ADAPTER_EVENT,
608 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
611 ret_if(event_id > 0);
613 adapter_proxy = _bt_get_adapter_proxy();
614 ret_if(adapter_proxy == NULL);
616 /* Need to stop searching */
617 g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
619 G_DBUS_CALL_FLAGS_NONE,
623 BT_ERR("Dbus Error %s", err->message);
627 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
628 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
630 } else if (strcasecmp(property, "Name") == 0) {
632 g_variant_get(val, "s", &name);
633 param = g_variant_new("(is)", result, name);
634 /* Send event to application */
635 _bt_send_event(BT_ADAPTER_EVENT,
636 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
639 } else if (strcasecmp(property, "Alias") == 0) {
641 g_variant_get(val, "s", &alias);
642 param = g_variant_new("(is)", result, alias);
643 /* Send event to application */
644 _bt_send_event(BT_ADAPTER_EVENT,
645 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
648 } else if (strcasecmp(property, "Discoverable") == 0) {
649 gboolean discoverable = FALSE;
651 g_variant_get(val, "b", &discoverable);
652 BT_DBG("discoverable %d", discoverable);
654 if (discoverable == FALSE) {
655 if (_bt_get_discoverable_timeout_property() > 0) {
657 adapter_proxy = _bt_get_adapter_properties_proxy();
658 ret_if(adapter_proxy == NULL);
659 g_dbus_proxy_call_sync(adapter_proxy, "Set",
660 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
661 "DiscoverableTimeout",
662 g_variant_new("i", time)),
663 G_DBUS_CALL_FLAGS_NONE,
668 BT_ERR("StopLEDiscovery Failed: %s", err->message);
673 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
675 /* Send event to application */
676 BT_INFO("[Connectable]");
677 param = g_variant_new("(in)", result, mode);
678 _bt_send_event(BT_ADAPTER_EVENT,
679 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
682 _bt_get_discoverable_mode(&mode);
684 /* Event will be sent by "DiscoverableTimeout" signal */
685 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
687 g_variant_unref(val);
691 /* Send event to application */
692 BT_INFO("[General Discoverable]");
693 param = g_variant_new("(in)", result, mode);
694 _bt_send_event(BT_ADAPTER_EVENT,
695 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
698 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
699 _bt_get_discoverable_mode(&mode);
701 /* Event was already sent by "Discoverable" signal */
702 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
703 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
705 g_variant_unref(val);
709 /* Send event to application */
710 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
711 _bt_get_discoverable_timeout_property());
712 param = g_variant_new("(in)", result, mode);
713 _bt_send_event(BT_ADAPTER_EVENT,
714 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
716 } else if (strcasecmp(property, "Powered") == 0) {
717 /* TODO: Need to check this operation!! */
718 gboolean powered = FALSE;
721 g_variant_get(val, "b" ,&powered);
722 BT_DBG("Powered = %d", powered);
723 if (powered == FALSE) {
725 _bt_handle_adapter_removed();
727 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
728 bt_state != VCONFKEY_BT_STATUS_OFF) {
729 _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);
740 _bt_handle_adapter_added();
743 } else if (strcasecmp(property, "Connectable") == 0) {
744 gboolean connectable = FALSE;
746 g_variant_get(val, "b", &connectable);
748 BT_DBG("Connectable property is changed : %d", connectable);
749 param = g_variant_new("(b)", connectable);
750 _bt_send_event(BT_ADAPTER_EVENT,
751 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
753 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
754 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
756 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
757 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
760 GVariantIter *iter = NULL;
761 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");
770 g_variant_iter_free(iter);
772 BT_DBG("property : [%s]", property);
777 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
781 GVariantIter value_iter;
782 GVariant *child = NULL, *val = NULL;
783 char *property = NULL;
784 g_variant_iter_init (&value_iter, msg);
785 while ((child = g_variant_iter_next_value (&value_iter))) {
786 g_variant_get(child, "{sv}", &property, &val);
788 ret_if(property == NULL);
790 BT_DBG("property :%s", property);
792 if (strcasecmp(property, "Status") == 0) {
794 g_variant_get(val, "s", &status);
796 if (strcasecmp(status, "active") == 0){
797 _bt_obex_transfer_started(path);
798 } else if (strcasecmp(status, "complete") == 0) {
799 _bt_obex_transfer_completed(path, TRUE);
800 _bt_pbap_obex_transfer_completed(path, TRUE);
801 } else if (strcasecmp(status, "error") == 0){
802 _bt_obex_transfer_completed(path, FALSE);
803 _bt_pbap_obex_transfer_completed(path, FALSE);
806 } else if (strcasecmp(property, "Transferred") == 0) {
807 static int transferred = 0;
808 g_variant_get(val, "t", &transferred);
810 _bt_obex_transfer_progress(path,transferred);
813 g_variant_unref(val);
814 g_variant_unref(child);
819 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
824 int result = BLUETOOTH_ERROR_NONE;
825 GVariantIter value_iter;
827 char *property = NULL;
829 GVariant *param = NULL;
830 bt_remote_dev_info_t *remote_dev_info;
831 g_variant_iter_init (&value_iter, msg);
832 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
833 BT_DBG("Property %s", property);
834 if (strcasecmp(property, "Connected") == 0) {
837 g_variant_get(val, "i", &connected);
839 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
840 BLUETOOTH_EVENT_DEVICE_CONNECTED :
841 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
843 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
845 _bt_convert_device_path_to_address(path, address);
847 BT_DBG("connected: %d", connected);
848 BT_DBG("address: %s", address);
850 remote_dev_info = _bt_get_remote_device_info(address);
852 if (remote_dev_info != NULL) {
853 __bt_device_remote_connected_properties(
854 remote_dev_info, address,
855 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
857 _bt_free_device_info(remote_dev_info);
859 param = g_variant_new("(is)", result, address);
860 /* Send event to application */
861 _bt_send_event(BT_DEVICE_EVENT,
865 } else if (strcasecmp(property, "RSSI") == 0) {
866 bt_remote_dev_info_t *remote_dev_info;
868 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
870 _bt_convert_device_path_to_address(path, address);
871 BT_DBG("address: %s", address);
873 remote_dev_info = _bt_get_remote_device_info(address);
874 if (remote_dev_info == NULL) {
876 g_variant_unref(val);
880 BT_DBG("Address type %d", remote_dev_info->addr_type);
882 if (remote_dev_info && remote_dev_info->addr_type == 0) {
883 BT_DBG("Name %s", remote_dev_info->name);
885 GVariant *uuids = NULL;
886 GVariantBuilder *builder = NULL;
888 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
889 for (i=0; i < remote_dev_info->uuid_count; i++) {
890 g_variant_builder_add(builder, "s",
891 remote_dev_info->uuids[i]);
893 uuids = g_variant_new("as", builder);
894 g_variant_builder_unref(builder);
895 GVariant *manufacturer_data = NULL;
896 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
897 remote_dev_info->manufacturer_data,
898 remote_dev_info->manufacturer_data_len,
901 param = g_variant_new("(isunsbub@asn@ay)", result,
902 remote_dev_info->address,
903 remote_dev_info->class,
904 remote_dev_info->rssi,
905 remote_dev_info->name,
906 remote_dev_info->paired,
907 remote_dev_info->connected,
908 remote_dev_info->trust,
910 remote_dev_info->manufacturer_data_len,
913 _bt_send_event(BT_ADAPTER_EVENT,
914 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
918 _bt_free_device_info(remote_dev_info);
919 } else if (strcasecmp(property, "GattConnected") == 0) {
920 gboolean gatt_connected = FALSE;
922 g_variant_get(val, "b", &gatt_connected);
924 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
925 BLUETOOTH_EVENT_GATT_DISCONNECTED;
927 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
929 _bt_convert_device_path_to_address(path, address);
931 BT_DBG("gatt_connected: %d", gatt_connected);
932 BT_DBG("address: %s", address);
933 param = g_variant_new("(is)", result, address);
934 /* Send event to application */
935 _bt_send_event(BT_DEVICE_EVENT,
939 } else if (strcasecmp(property, "Paired") == 0) {
940 gboolean paired = FALSE;
941 bt_remote_dev_info_t *remote_dev_info;
942 g_variant_get(val, "b", &paired);
943 _bt_agent_set_canceled(FALSE);
944 /* BlueZ sends paired signal for each paired device */
945 /* during activation, We should ignore this, otherwise*/
946 /* application thinks that a new device got paired */
947 if (_bt_adapter_get_status() != BT_ACTIVATED) {
948 BT_DBG("BT is not activated, so ignore this");
950 g_variant_unref(val);
954 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
956 _bt_convert_device_path_to_address(path, address);
958 remote_dev_info = _bt_get_remote_device_info(address);
959 if (remote_dev_info == NULL) {
961 g_variant_unref(val);
966 if(paired == FALSE) {
967 BT_INFO("Unpaired: %s", address);
968 __bt_update_remote_cache_devinfo(address, FALSE);
969 param = g_variant_new("(is)", result, address);
970 _bt_send_event(BT_ADAPTER_EVENT,
971 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
974 BT_INFO("Paired: %s", address);
975 __bt_update_remote_cache_devinfo(address, TRUE);
977 if (_bt_is_device_creating() == TRUE) {
978 BT_DBG("Try to Pair by me");
979 _bt_free_device_info(remote_dev_info);
982 g_variant_unref(val);
985 GVariant *uuids = NULL;
986 GVariantBuilder *builder = NULL;
988 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
989 for (i=0; i < remote_dev_info->uuid_count; i++) {
990 g_variant_builder_add(builder, "s",
991 remote_dev_info->uuids[i]);
993 uuids = g_variant_new("as", builder);
994 g_variant_builder_unref(builder);
995 GVariant *manufacturer_data = NULL;
996 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
997 remote_dev_info->manufacturer_data,
998 remote_dev_info->manufacturer_data_len,
1002 param = g_variant_new("(isunsbub@asn@ay)", result,
1003 address, remote_dev_info->class,
1004 remote_dev_info->rssi,
1005 remote_dev_info->name,
1006 remote_dev_info->paired,
1007 remote_dev_info->connected,
1008 remote_dev_info->trust,
1010 remote_dev_info->manufacturer_data_len,
1012 _bt_send_event(BT_ADAPTER_EVENT,
1013 BLUETOOTH_EVENT_BONDING_FINISHED,
1016 _bt_free_device_info(remote_dev_info);
1018 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1019 gboolean paired = FALSE;
1020 bt_remote_dev_info_t *remote_dev_info;
1022 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1023 BT_DBG("BT is not activated, so ignore this");
1025 g_variant_unref(val);
1029 g_variant_get(val, "b", &paired);
1030 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1031 BT_DBG("LegacyPaired: %d", paired);
1032 _bt_convert_device_path_to_address(path, address);
1034 remote_dev_info = _bt_get_remote_device_info(address);
1035 if (remote_dev_info == NULL) {
1038 g_variant_unref(val);
1042 BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
1043 remote_dev_info->name);
1044 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1045 remote_dev_info->name, NULL, NULL, NULL);
1047 _bt_free_device_info(remote_dev_info);
1049 } else if (strcasecmp(property, "Trusted") == 0) {
1050 gboolean trusted = FALSE;
1052 g_variant_get(val, "b", &trusted);
1054 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1055 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1057 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1059 _bt_convert_device_path_to_address(path, address);
1061 BT_DBG("trusted: %d", trusted);
1062 BT_DBG("address: %s", address);
1063 param = g_variant_new("(is)", result, address);
1064 /* Send event to application */
1065 _bt_send_event(BT_DEVICE_EVENT,
1074 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1077 int result = BLUETOOTH_ERROR_NONE;
1078 GVariantIter value_iter;
1079 char *property = NULL;
1081 GVariant *val = NULL;
1082 GVariant *child = NULL;
1083 bt_remote_dev_info_t *remote_dev_info;
1084 GVariant *param = NULL;
1085 g_variant_iter_init (&value_iter, msg);
1086 while ((child = g_variant_iter_next_value (&value_iter))) {
1087 g_variant_get(child, "{sv}", &property, &val);
1088 BT_INFO("Property %s", property);
1089 if (strcasecmp(property, "Connected") == 0) {
1090 gboolean connected = FALSE;
1092 g_variant_get(val, "b", &connected);
1094 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1095 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1097 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1099 _bt_convert_device_path_to_address(path, address);
1101 BT_DBG("connected: %d", connected);
1102 BT_DBG("address: %s", address);
1104 remote_dev_info = _bt_get_remote_device_info(address);
1106 if (remote_dev_info != NULL) {
1107 __bt_device_remote_connected_properties(
1108 remote_dev_info, address, connected);
1109 _bt_free_device_info(remote_dev_info);
1111 param = g_variant_new("(is)", result, address);
1112 /* Send event to application */
1113 _bt_send_event(BT_AVRCP_EVENT,
1119 g_variant_unref(child);
1120 g_variant_unref(val);
1125 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1127 char *interface_name = NULL;
1128 GVariant *val = NULL;
1130 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val,NULL);
1132 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1133 __bt_adapter_property_changed_event(val,
1135 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1136 __bt_device_property_changed_event(val,object_path);
1137 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1138 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1139 __bt_obex_property_changed_event(val,
1141 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1142 __bt_media_control_changed_event(val,
1144 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1145 _bt_handle_avrcp_control_event(val,
1147 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1148 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1149 _bt_handle_network_client_event(val,
1151 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1152 __bt_gatt_char_property_changed_event(val,
1155 g_variant_unref(val);
1158 void __bt_opc_property_changed_event(GVariant *msg,
1161 GVariantIter value_iter;
1162 char *property = NULL;
1163 GVariant *val = NULL;
1164 GVariant *child = NULL;
1166 g_variant_iter_init (&value_iter, msg);
1167 while ((child = g_variant_iter_next_value (&value_iter))) {
1168 g_variant_get(child, "{sv}", &property, &val);
1169 ret_if(property == NULL);
1171 if (strcasecmp(property, "Status") == 0) {
1172 char *status = NULL;
1173 g_variant_get(val, "s", &status);
1174 BT_DBG("Status is %s", status);
1176 if(strcasecmp(status, "active") == 0){
1177 _bt_obex_client_started(path);
1178 }else if (strcasecmp(status, "complete") == 0) {
1179 _bt_obex_client_completed(path, TRUE);
1180 }else if (strcasecmp(status, "error") == 0){
1181 _bt_obex_client_completed(path, FALSE);
1184 } else if (strcasecmp(property, "Transferred") == 0) {
1185 static int transferred = 0;
1186 g_variant_get(val, "t", &transferred);
1188 _bt_obex_client_progress(path, transferred);
1190 BT_DBG("property : [%s]", property);
1193 g_variant_unref(child);
1194 g_variant_unref(val);
1198 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1200 char *interface_name = NULL;
1201 GVariant *value = NULL;
1202 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1203 BT_INFO("interface_name = %s", interface_name);
1204 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1205 __bt_opc_property_changed_event(value,
1208 BT_DBG("interface_name : [%s]", interface_name);
1210 g_variant_unref(value);
1214 void _bt_handle_input_event(GVariant *msg, const char *path)
1216 int result = BLUETOOTH_ERROR_NONE;
1217 gboolean property_flag = FALSE;
1218 GVariantIter value_iter;
1219 char *property = NULL;
1220 GVariant *child = NULL, *val = NULL;
1221 bt_remote_dev_info_t *remote_dev_info;
1222 GVariant *param = NULL;
1223 g_variant_iter_init (&value_iter, msg);
1224 while ((child = g_variant_iter_next_value (&value_iter))) {
1225 g_variant_get(child, "{sv}", &property, &val);
1227 ret_if(property == NULL);
1229 if (strcasecmp(property, "Connected") == 0) {
1230 int event = BLUETOOTH_EVENT_NONE;
1232 g_variant_get(val, "b", &property_flag);
1234 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1236 _bt_convert_device_path_to_address(path, address);
1238 event = (property_flag == TRUE) ?
1239 BLUETOOTH_HID_CONNECTED :
1240 BLUETOOTH_HID_DISCONNECTED;
1241 param = g_variant_new("(is)", result, address);
1242 _bt_send_event(BT_HID_EVENT, event,
1244 /* Check HID connection type (Keyboard or Mouse) and update the status */
1245 remote_dev_info = _bt_get_remote_device_info(address);
1247 if (property_flag == TRUE) {
1248 hid_connected_device_count++;
1249 __bt_set_device_values(TRUE,
1250 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1252 hid_connected_device_count--;
1253 if (hid_connected_device_count == 0)
1254 __bt_set_device_values(FALSE,
1255 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1258 if (remote_dev_info != NULL) {
1259 BT_DBG("HID device class [%x]", remote_dev_info->class);
1260 if (remote_dev_info->class &
1261 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1262 #ifdef ENABLE_TIZEN_2_4
1263 __bt_set_device_values(property_flag,
1264 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1269 if (remote_dev_info->class &
1270 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1271 #ifdef ENABLE_TIZEN_2_4
1272 __bt_set_device_values(property_flag,
1273 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1276 _bt_free_device_info(remote_dev_info);
1281 g_variant_unref(val);
1282 g_variant_unref(child);
1286 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1288 int result = BLUETOOTH_ERROR_NONE;
1289 char *address = NULL;
1290 char *device = NULL;
1291 GVariant *param = NULL;
1292 ret_if(member == NULL);
1293 if (strcasecmp(member, "PeerConnected") == 0) {
1294 g_variant_get(msg, "(ss)", &device, &address);
1296 __bt_set_device_values(TRUE,
1297 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1298 param = g_variant_new("(iss)", result, device, address);
1299 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1303 nap_connected_device_count++;
1304 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1305 g_variant_get(msg, "(ss)", &device, &address);
1306 nap_connected_device_count--;
1307 if (nap_connected_device_count == 0)
1308 __bt_set_device_values(FALSE,
1309 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1310 param = g_variant_new("(iss)", result, device, address);
1311 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1318 void _bt_handle_network_client_event(GVariant *msg,
1323 int result = BLUETOOTH_ERROR_NONE;
1324 gboolean property_flag = FALSE;
1325 char *property = NULL;
1326 GVariant *val = NULL;
1327 GVariantIter value_iter;
1328 GVariant *param = NULL;
1329 g_variant_iter_init (&value_iter, msg);
1330 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1331 if (strcasecmp(property, "Connected") == 0) {
1332 int event = BLUETOOTH_EVENT_NONE;
1335 g_variant_get(val, "b", &property_flag);
1336 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1338 _bt_convert_device_path_to_address(path, address);
1340 BT_DBG("property_flag %d", property_flag);
1341 if (property_flag == TRUE) {
1342 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1343 nap_connected_device_count++;
1344 __bt_set_device_values(TRUE,
1345 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1347 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1348 nap_connected_device_count--;
1349 if (nap_connected_device_count == 0)
1350 __bt_set_device_values(FALSE,
1351 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1353 param = g_variant_new("(is)", result, address);
1354 _bt_send_event(BT_NETWORK_EVENT, event,
1363 void __bt_gatt_char_property_changed_event(GVariant *msg,
1366 GVariantIter value_iter;
1367 char *property = NULL;
1368 char * char_handle = NULL;
1369 GVariant *val = NULL;
1370 int result = BLUETOOTH_ERROR_NONE;
1371 GVariant *param = NULL;
1372 g_variant_iter_init (&value_iter, msg);
1373 char_handle = g_strdup(path);
1374 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1375 BT_INFO("Property %s", property);
1377 ret_if(property == NULL);
1379 if (strcasecmp(property, "Notifying") == 0) {
1380 gboolean property_flag = FALSE;
1381 g_variant_get(val, "b", &property_flag);
1382 if (property_flag == TRUE)
1383 BT_DBG("notifying is enabled");
1385 BT_DBG("notifying is disabled");
1386 } else if (strcasecmp(property, "ChangedValue") == 0) {
1388 GByteArray *gp_byte_array = NULL;
1389 BT_INFO("Type '%s'\n", g_variant_get_type_string (val));
1392 gp_byte_array = g_byte_array_new();
1393 len = g_variant_get_size(val);
1394 BT_DBG("Len = %d", len);
1395 g_byte_array_append (gp_byte_array,
1396 (const guint8 *) g_variant_get_data(val), len);
1397 if (gp_byte_array->len != 0) {
1398 GVariant *byte_array = NULL;
1399 byte_array = g_variant_new_from_data(
1400 G_VARIANT_TYPE_BYTESTRING,
1401 gp_byte_array->data,
1404 param = g_variant_new("(is@ay)", result, char_handle,
1406 _bt_send_event(BT_DEVICE_EVENT,
1407 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
1410 g_byte_array_free(gp_byte_array, TRUE);
1414 g_free(char_handle);
1416 void _bt_handle_device_event(GVariant *msg, const char *member,const char *path)
1419 int result = BLUETOOTH_ERROR_NONE;
1422 const char *property = NULL;
1423 GVariant *param = NULL;
1424 ret_if(path == NULL);
1426 if (strcasecmp(member, "PropertyChanged") == 0) {
1428 g_variant_get(msg, "(s)", &property);
1430 ret_if(property == NULL);
1432 if (strcasecmp(property, "GattConnected") == 0) {
1433 gboolean connected = FALSE;
1435 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1436 _bt_convert_device_path_to_address(path, address);
1437 g_variant_get(msg, "(b)", &connected);
1439 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1440 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1441 param = g_variant_new("(is)", result, address);
1442 _bt_send_event(BT_DEVICE_EVENT,
1446 } else if (strcasecmp(property, "Paired") == 0) {
1447 gboolean paired = FALSE;
1448 bt_remote_dev_info_t *remote_dev_info;
1449 g_variant_get(msg, "(b)", &paired);
1451 ret_if(paired == FALSE);
1453 /* BlueZ sends paired signal for each paired device */
1454 /* during activation, We should ignore this, otherwise*/
1455 /* application thinks that a new device got paired */
1456 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1457 BT_DBG("BT is not activated, so ignore this");
1461 if (_bt_is_device_creating() == TRUE) {
1462 BT_DBG("Try to Pair by me");
1466 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1468 _bt_convert_device_path_to_address(path, address);
1470 remote_dev_info = _bt_get_remote_device_info(address);
1471 if (remote_dev_info == NULL) {
1475 GVariant *uuids = NULL;
1476 GVariantBuilder *builder = NULL;
1478 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1479 for (i=0; i < remote_dev_info->uuid_count; i++) {
1480 g_variant_builder_add(builder, "s",
1481 remote_dev_info->uuids[i]);
1483 uuids = g_variant_new("as", builder);
1484 g_variant_builder_unref(builder);
1485 GVariant *manufacturer_data = NULL;
1486 manufacturer_data = g_variant_new_from_data(
1487 G_VARIANT_TYPE_BYTESTRING,
1488 remote_dev_info->manufacturer_data,
1489 remote_dev_info->manufacturer_data_len,
1491 param = g_variant_new("(isunsbub@asn@ay)", result,
1493 remote_dev_info->class,
1494 remote_dev_info->rssi,
1495 remote_dev_info->name,
1496 remote_dev_info->paired,
1497 remote_dev_info->connected,
1498 remote_dev_info->trust,
1500 remote_dev_info->manufacturer_data_len,
1502 _bt_send_event(BT_ADAPTER_EVENT,
1503 BLUETOOTH_EVENT_BONDING_FINISHED,
1505 _bt_free_device_info(remote_dev_info);
1508 } else if (strcasecmp(property, "UUIDs") == 0) {
1509 /* Once we get the updated uuid information after
1510 * reverse service search, update it to application */
1512 bt_remote_dev_info_t *remote_dev_info;
1514 ret_if(_bt_is_device_creating() == TRUE);
1516 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1518 _bt_convert_device_path_to_address(path, address);
1520 remote_dev_info = _bt_get_remote_device_info(address);
1521 if (remote_dev_info == NULL) {
1526 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1527 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1528 GVariant *uuids = NULL;
1529 GVariantBuilder *builder = NULL;
1531 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1532 for (i=0; i < remote_dev_info->uuid_count; i++) {
1533 g_variant_builder_add(builder, "s",
1534 remote_dev_info->uuids[i]);
1536 uuids = g_variant_new("as", builder);
1537 g_variant_builder_unref(builder);
1538 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1539 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1542 param = g_variant_new("(isunsbub@asn@ay)", result,
1543 address, remote_dev_info->class,
1544 remote_dev_info->rssi,
1545 remote_dev_info->name,
1546 remote_dev_info->paired,
1547 remote_dev_info->connected,
1548 remote_dev_info->trust,
1550 remote_dev_info->manufacturer_data_len,
1552 _bt_send_event(BT_ADAPTER_EVENT,
1553 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1557 _bt_free_device_info(remote_dev_info);
1560 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1561 unsigned char addr_type = 0;
1563 g_variant_get(msg, "(y)", &addr_type);
1565 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1567 _bt_convert_device_path_to_address(path, address);
1568 dev_name = _bt_get_bonded_device_name(address);
1570 BT_INFO("Address : %s Type : %d", address, addr_type);
1571 BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1572 !addr_type ? dev_name : address);
1575 _bt_logging_connection(TRUE, addr_type);
1576 #ifdef ENABLE_TIZEN_2_4
1577 journal_bt_connected();
1579 param = g_variant_new("(isy)", result, address, addr_type);
1580 /*Send event to application*/
1581 _bt_send_event(BT_DEVICE_EVENT,
1582 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1585 } else if (strcasecmp(member, "Disconnected") == 0) {
1586 unsigned char disc_reason = 0;
1587 unsigned char addr_type = 0;
1588 gboolean sending = FALSE;
1590 g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
1592 result = disc_reason;
1594 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1596 _bt_convert_device_path_to_address(path, address);
1597 dev_name = _bt_get_bonded_device_name(address);
1598 #ifdef ENABLE_TIZEN_2_4
1599 journal_bt_disconnected();
1602 /* 0x00 BDADDR_BRDER
1603 0x01 BDADDR_LE_PUBLIC
1604 0x02 BDADDR_LE_RANDOM */
1605 BT_INFO("Address : %s Type : %d", address, addr_type);
1606 BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1607 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1608 !addr_type ? dev_name : address);
1611 _bt_headset_set_local_connection(FALSE);
1612 _bt_logging_connection(FALSE, addr_type);
1614 /*Check for any OPP transfer on the device and cancel
1617 _bt_obex_check_pending_transfer(address);
1618 _bt_opp_client_is_sending(&sending);
1620 _bt_opp_client_check_pending_transfer(address);
1621 param = g_variant_new("(isy)", result, address, addr_type);
1622 _bt_send_event(BT_DEVICE_EVENT,
1623 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1626 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1628 char *profile_uuid = NULL;
1629 bt_headset_wait_t *wait_list;
1631 g_variant_get(msg, "(si)", &profile_uuid, &state);
1633 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1635 _bt_convert_device_path_to_address(path, address);
1637 BT_DBG("Address: %s", address);
1638 BT_DBG("Profile UUID: %s", profile_uuid);
1639 BT_DBG("State: %d", state);
1641 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1642 (state == BT_PROFILE_STATE_CONNECTED)) {
1644 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1645 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1646 bluetooth_device_address_t device_address;
1648 bt_headset_wait_t *wait_list;
1650 __bt_set_device_values(TRUE,
1651 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1653 __bt_connection_manager_set_state(address, event);
1655 if (_bt_headset_get_local_connection() == FALSE)
1656 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1658 /* Connection Started from local device therefore no need to
1659 * intiate connection for pending profile */
1660 _bt_headset_set_local_connection(FALSE);
1662 param = g_variant_new("(is)", result, address);
1663 _bt_send_event(BT_HEADSET_EVENT, event,
1665 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1668 if (g_strcmp0(connected_address, address) != 0) {
1669 _bt_convert_addr_string_to_type(
1670 device_address.addr,
1672 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1673 &device_address, NULL);
1677 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1678 BT_STATE_CONNECTED, address);
1680 wait_list = _bt_get_audio_wait_data();
1681 if (wait_list != NULL &&
1682 (g_strcmp0(wait_list->address, address) == 0))
1683 _bt_rel_wait_data();
1685 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1686 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1688 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1690 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1692 g_free(profile_uuid);
1696 __bt_set_device_values(FALSE,
1697 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1699 __bt_connection_manager_set_state(address, event);
1700 param = g_variant_new("(is)", result, address);
1701 _bt_send_event(BT_HEADSET_EVENT, event,
1703 /* Remove data from the connected list */
1704 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1705 wait_list = _bt_get_audio_wait_data();
1707 if (wait_list == NULL) {
1709 g_free(profile_uuid);
1713 if (((wait_list->type == BT_AUDIO_ALL) &&
1714 (wait_list->ag_flag == TRUE)) ||
1715 (wait_list->type == BT_AUDIO_A2DP) ||
1716 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1717 bluetooth_device_address_t device_address;
1718 _bt_convert_addr_string_to_type(
1719 device_address.addr,
1720 wait_list->address);
1722 _bt_audio_connect(wait_list->req_id,
1725 wait_list->out_param1);
1727 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1729 if (state == BT_PROFILE_STATE_CONNECTED) {
1730 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1731 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1732 bluetooth_device_address_t device_address;
1734 param = g_variant_new("(is)", result, address);
1735 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1737 connected = _bt_is_headset_type_connected(
1741 if (g_strcmp0(connected_address,
1743 _bt_convert_addr_string_to_type(
1744 device_address.addr,
1746 _bt_audio_disconnect(0,
1748 &device_address, NULL);
1751 BT_DBG("device Path: %s", path);
1752 _bt_add_headset_to_list(BT_AVRCP,
1753 BT_STATE_CONNECTED, address);
1754 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1755 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1756 param = g_variant_new("(is)", result, address);
1757 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1759 /* Remove data from the connected list */
1760 _bt_remove_headset_from_list(BT_AVRCP, address);
1762 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1763 if (state == BT_PROFILE_STATE_CONNECTED) {
1764 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1765 BT_INFO("A2DP Source is connected");
1766 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1767 g_variant_new("(is)", result, address));
1768 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1769 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
1770 BT_INFO("A2DP Source Disconnected");
1771 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1772 g_variant_new("(is)", result, address));
1774 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
1775 ((state == BT_PROFILE_STATE_CONNECTED) ||
1776 (state == BT_PROFILE_STATE_DISCONNECTED))) {
1778 if (state == BT_PROFILE_STATE_CONNECTED)
1779 event = BLUETOOTH_HID_CONNECTED;
1781 event = BLUETOOTH_HID_DISCONNECTED;
1782 param = g_variant_new("(is)", result, address);
1783 _bt_send_event(BT_HID_EVENT, event,
1786 if (state == BT_PROFILE_STATE_CONNECTED)
1787 __bt_set_device_values(TRUE,
1788 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1790 __bt_set_device_values(FALSE,
1791 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1794 g_free(profile_uuid);
1795 } else if (strcasecmp(member, "AdvReport") == 0) {
1797 bt_remote_le_dev_info_t *le_dev_info = NULL;
1798 char *buffer = NULL;
1800 bt_le_adv_info_t *adv_info = NULL;
1801 GVariant *value = NULL;
1802 ret_if(_bt_is_le_scanning() == FALSE);
1804 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
1806 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
1807 &le_dev_info->addr_type,
1808 &le_dev_info->adv_type,
1810 &le_dev_info->adv_data_len,
1812 buffer_len = g_variant_get_size(value);
1814 buffer = (char *)g_variant_get_data(value);
1816 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
1818 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1819 _bt_send_scan_result_event(le_dev_info, NULL);
1820 _bt_free_le_device_info(le_dev_info);
1821 g_variant_unref(value);
1825 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
1826 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
1827 adv_info->addr = g_strdup(le_dev_info->address);
1828 adv_info->data_len = le_dev_info->adv_data_len;
1829 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
1830 memcpy(adv_info->data, le_dev_info->adv_data,
1831 le_dev_info->adv_data_len);
1833 __bt_add_adv_ind_info(adv_info);
1835 } else { /* SCAN_RSP */
1836 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
1838 _bt_send_scan_result_event(le_dev_info, adv_info);
1839 __bt_del_adv_ind_info(le_dev_info->address);
1842 _bt_free_le_device_info(le_dev_info);
1843 g_variant_unref(value);
1848 void __bt_set_audio_values(gboolean connected, char *address)
1851 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1853 /* Set the headset name */
1854 if (connected == TRUE) {
1855 name = _bt_get_bonded_device_name(address);
1857 name = g_strdup("");
1860 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
1862 BT_ERR("vconf_set_str failed");
1867 /* Set the headset state */
1868 if (vconf_get_int(VCONFKEY_BT_DEVICE,
1869 &bt_device_state) != 0) {
1870 BT_ERR("vconf_get_str failed");
1873 #ifdef TIZEN_SUPPORT_DUAL_HF
1874 if ((connected == TRUE) &&
1875 (FALSE == __bt_is_companion_device(address))) {
1876 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1877 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
1878 (FALSE == __bt_is_companion_device(address))) {
1879 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1882 if (connected == TRUE) {
1883 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1884 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
1885 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1889 if (vconf_set_int(VCONFKEY_BT_DEVICE,
1890 bt_device_state) != 0) {
1891 BT_ERR("vconf_set_int failed");
1895 void _bt_handle_headset_event(GVariant *msg, const char *path)
1897 int result = BLUETOOTH_ERROR_NONE;
1898 gboolean property_flag = FALSE;
1899 char *property = NULL;
1900 GVariant *value = NULL;
1901 GVariant *param = NULL;
1902 g_variant_get(msg, "(sv)", &property, &value);
1904 ret_if(property == NULL);
1906 BT_DBG("Property = %s \n", property);
1907 /* We allow only 1 headset connection (HSP or HFP)*/
1908 if (strcasecmp(property, "Connected") == 0) {
1909 int event = BLUETOOTH_EVENT_NONE;
1910 bt_headset_wait_t *wait_list;
1912 g_variant_get(value, "b", &property_flag);
1914 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1916 /* Fix : NULL_RETURNS */
1917 if (address == NULL)
1920 _bt_convert_device_path_to_address(path, address);
1922 if (property_flag == TRUE) {
1923 event = BLUETOOTH_EVENT_AG_CONNECTED;
1924 if (_bt_headset_get_local_connection() == FALSE)
1925 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
1927 _bt_headset_set_local_connection(FALSE);
1931 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
1933 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
1934 if (previous_state == BT_STATE_DISCONNECTING)
1935 _bt_send_hf_local_term_event(address);
1937 /* Set the State machine here */
1938 __bt_connection_manager_set_state(address, event);
1939 __bt_set_audio_values(property_flag, address);
1940 param = g_variant_new("(is)", result, address);
1941 _bt_send_event(BT_HEADSET_EVENT, event,
1944 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
1945 /* Remove data from the connected list */
1946 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
1948 wait_list = _bt_get_audio_wait_data();
1949 if (wait_list == NULL) {
1954 bluetooth_device_address_t device_address;
1956 _bt_set_audio_wait_data_flag(TRUE);
1958 _bt_convert_addr_string_to_type(device_address.addr,
1959 wait_list->address);
1960 _bt_audio_connect(wait_list->req_id, wait_list->type,
1961 &device_address, wait_list->out_param1);
1962 _bt_rel_wait_data();
1963 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
1964 /* Add data to the connected list */
1965 _bt_add_headset_to_list(BT_AUDIO_HSP,
1966 BT_STATE_CONNECTED, address);
1968 wait_list = _bt_get_audio_wait_data();
1969 if (wait_list != NULL &&
1970 (g_strcmp0(wait_list->address, address) == 0))
1971 _bt_rel_wait_data();
1973 BT_INFO("Check A2DP pending connect");
1974 _bt_audio_check_pending_connect();
1977 } else if (strcasecmp(property, "State") == 0) {
1980 g_variant_get(value, "s", &state);
1982 /* This code assumes we support only 1 headset connection */
1983 /* Need to use the headset list, if we support multi-headsets */
1984 if (strcasecmp(state, "Playing") == 0) {
1985 BT_DBG("Playing: Sco Connected");
1986 } else if (strcasecmp(state, "connected") == 0 ||
1987 strcasecmp(state, "disconnected") == 0) {
1988 BT_DBG("connected/disconnected: Sco Disconnected");
1990 BT_ERR("Not handled state - %s", state);
1995 } else if (strcasecmp(property, "SpeakerGain") == 0) {
1999 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2001 _bt_convert_device_path_to_address(path, address);
2003 g_variant_get(value, "i", &spkr_gain);
2004 param = g_variant_new("(isq)", result, address, spkr_gain);
2005 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2009 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2013 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2015 _bt_convert_device_path_to_address(path, address);
2017 g_variant_get(value, "i", &mic_gain);
2018 param = g_variant_new("(isq)", result, address, mic_gain);
2019 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2026 g_variant_unref(value);
2029 void _bt_handle_sink_event(GVariant *msg, const char *path)
2031 GVariantIter value_iter;
2032 char *property = NULL;
2034 bt_headset_wait_t *wait_list;
2036 GVariant *child = NULL;
2037 GVariant *val = NULL;
2038 GVariant *param = NULL;
2039 g_variant_iter_init (&value_iter, msg);
2040 while ((child = g_variant_iter_next_value (&value_iter))) {
2042 g_variant_get(child, "{sv}", &property, &val);
2044 ret_if(property == NULL);
2046 BT_DBG("Property = %s \n", property);
2049 if (strcasecmp(property, "State") == 0) {
2050 int result = BLUETOOTH_ERROR_NONE;
2053 g_variant_get(val, "s", &value);
2054 BT_DBG("value: %s", value);
2056 if (g_strcmp0(value, "disconnected") == 0) {
2059 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2061 _bt_convert_device_path_to_address(path, address);
2063 __bt_set_device_values(FALSE,
2064 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2065 param = g_variant_new("(is)", result, address);
2066 _bt_send_event(BT_HEADSET_EVENT,
2067 BLUETOOTH_EVENT_AV_DISCONNECTED,
2070 /* Remove data from the connected list */
2071 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2072 wait_list = _bt_get_audio_wait_data();
2073 if (wait_list == NULL) {
2076 g_variant_unref(val);
2077 g_variant_unref(child);
2082 if (((wait_list->type == BT_AUDIO_ALL) &&
2083 (wait_list->ag_flag == TRUE)) ||
2084 (wait_list->type == BT_AUDIO_A2DP) ||
2085 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2086 bluetooth_device_address_t device_address;
2087 _bt_convert_addr_string_to_type(
2088 device_address.addr,
2089 wait_list->address);
2091 _bt_audio_connect(wait_list->req_id,
2094 wait_list->out_param1);
2097 }else if (strcasecmp(value, "Connected") == 0) {
2099 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2100 bluetooth_device_address_t device_address;
2103 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2105 _bt_convert_device_path_to_address(path, address);
2107 __bt_set_device_values(TRUE,
2108 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2109 param = g_variant_new("(is)", result, address);
2110 _bt_send_event(BT_HEADSET_EVENT,
2111 BLUETOOTH_EVENT_AV_CONNECTED,
2113 /* Check for existing Media device to disconnect */
2114 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2117 /* Match connected device address */
2118 if (g_strcmp0(connected_address, address) != 0) {
2119 /* Convert BD adress from string type */
2120 _bt_convert_addr_string_to_type(
2121 device_address.addr,
2123 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2124 &device_address, NULL);
2128 /* Add data to the connected list */
2129 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2130 BT_STATE_CONNECTED, address);
2137 g_variant_unref(val);
2138 g_variant_unref(child);
2142 void _bt_handle_agent_event(GVariant *msg, const char *member)
2144 int result = BLUETOOTH_ERROR_NONE;
2145 char *address = NULL;
2148 GVariant *param = NULL;
2149 ret_if(member == NULL);
2151 if (strcasecmp(member, "ObexAuthorize") == 0) {
2152 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2153 param = g_variant_new("(iss)", result, address, name);
2154 _bt_send_event(BT_OPP_SERVER_EVENT,
2155 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2159 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2160 bt_rfcomm_server_info_t *server_info;
2162 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2164 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2165 ret_if(server_info == NULL);
2166 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2167 param = g_variant_new("(isssn)", result, address, uuid, name,
2168 server_info->control_fd);
2169 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2170 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2178 static int __bt_get_object_path(GVariant *msg, char **path)
2180 g_variant_get(msg, "(o*)", path, NULL);
2182 return BLUETOOTH_ERROR_INTERNAL;
2184 return BLUETOOTH_ERROR_NONE;
2187 static void __bt_devices_list_free(void)
2189 bt_cache_info_t *cache_info;
2192 node = g_list_first(p_cache_list);
2194 while (node != NULL){
2195 cache_info = (bt_cache_info_t *)node->data;
2196 p_cache_list = g_list_remove(p_cache_list, cache_info);
2197 __bt_free_cache_info(cache_info);
2199 node = g_list_next(node);
2203 static int __bt_parse_event(GVariant *msg)
2207 char *interface_name= NULL;
2208 GVariant *inner_iter = NULL;
2210 g_variant_iter_init(&iter, msg);
2212 while ((child = g_variant_iter_next_value(&iter))) {
2213 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
2214 if (g_strcmp0(interface_name,
2215 BT_DEVICE_INTERFACE) == 0) {
2216 g_variant_unref(inner_iter);
2217 g_variant_unref(child);
2218 return BT_DEVICE_EVENT;
2219 } else if (g_strcmp0(interface_name,
2220 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2221 g_variant_unref(inner_iter);
2222 g_variant_unref(child);
2223 return BT_MEDIA_TRANSFER_EVENT;
2224 } else if (g_strcmp0(interface_name,
2225 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2226 g_variant_unref(inner_iter);
2227 g_variant_unref(child);
2228 return BT_AVRCP_CONTROL_EVENT;
2230 g_variant_unref(inner_iter);
2231 g_variant_unref(child);
2237 static void __bt_manager_event_filter(GDBusConnection *connection,
2238 const gchar *sender_name,
2239 const gchar *object_path,
2240 const gchar *interface_name,
2241 const gchar *signal_name,
2242 GVariant *parameters,
2245 bt_event_type_t bt_event = 0x00;
2246 int result = BLUETOOTH_ERROR_NONE;
2248 char *obj_path = NULL;
2249 GVariant *param = NULL;
2250 if (signal_name == NULL)
2252 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2253 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2255 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0){
2256 #ifdef USB_BLUETOOTH
2257 BT_DBG("Enable Adapter");
2258 _bt_enable_adapter();
2260 _bt_handle_adapter_added();
2264 bt_event = __bt_parse_event(value);
2265 if (bt_event == BT_DEVICE_EVENT) {
2266 bt_cache_info_t *cache_info;
2267 bt_remote_dev_info_t *dev_info;
2269 ret_if(_bt_is_discovering() == FALSE &&
2270 _bt_is_le_scanning() == FALSE);
2272 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2273 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2274 cache_info->dev_info = dev_info;
2276 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2277 BT_ERR("Fail to parse the properies");
2278 __bt_free_cache_info(cache_info);
2279 g_variant_unref(value);
2283 if (dev_info->addr_type != BDADDR_BREDR) {
2284 /* Whenever emit the property changed from bluez,
2285 some property doesn't reach to bt-service.
2286 So LE device is handled as AdvReport signal */
2287 __bt_free_cache_info(cache_info);
2288 g_variant_unref(value);
2292 if (dev_info->name == NULL)
2293 /* If Remote device name is NULL or still RNR is not done
2294 * then display address as name.
2296 dev_info->name = g_strdup(dev_info->address);
2298 GVariant *uuids = NULL;
2299 GVariantBuilder *builder = NULL;
2301 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2302 for (i=0; i < dev_info->uuid_count; i++) {
2303 g_variant_builder_add(builder, "s",
2304 dev_info->uuids[i]);
2306 uuids = g_variant_new("as", builder);
2307 g_variant_builder_unref(builder);
2308 GVariant *manufacturer_data = NULL;
2309 manufacturer_data = g_variant_new_from_data(
2310 G_VARIANT_TYPE_BYTESTRING,
2311 dev_info->manufacturer_data,
2312 dev_info->manufacturer_data_len,
2314 param = g_variant_new("(isunsbub@asn@ay)", result,
2320 dev_info->connected,
2323 dev_info->manufacturer_data_len,
2325 _bt_send_event(BT_ADAPTER_EVENT,
2326 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2328 p_cache_list = g_list_append(p_cache_list, cache_info);
2329 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2330 BT_DBG("Device path : %s ", obj_path);
2331 _bt_set_control_device_path(obj_path);
2334 g_variant_unref(value);
2335 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2336 #ifdef USB_BLUETOOTH
2337 BT_DBG("InterfacesRemoved");
2338 _bt_handle_adapter_removed();
2341 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2342 bt_event = BT_MEDIA_TRANSFER_EVENT;
2343 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2344 bt_event = BT_DEVICE_EVENT;
2345 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2346 bt_event = BT_AVRCP_CONTROL_EVENT;
2348 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2349 _bt_handle_adapter_event(parameters, signal_name);
2350 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2351 BT_INFO("Object Path %s", obj_path);
2352 _bt_remove_control_device_path(obj_path);
2355 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2358 char *previous = NULL;
2359 char *current = NULL;
2361 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2362 BT_ERR("Fail to get the owner info");
2366 if (*current != '\0') {
2376 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2377 BT_DBG("Bluetoothd is terminated");
2378 if (_bt_adapter_get_status() != BT_DEACTIVATING) {
2381 _bt_handle_adapter_removed();
2382 __bt_devices_list_free();
2385 _bt_obex_server_check_allocation(&value);
2387 if (value == TRUE) {
2388 /* Check if the obex server was terminated abnormally */
2389 _bt_obex_server_check_termination(name);
2392 _bt_rfcomm_server_check_existence(&value);
2394 if (value == TRUE) {
2395 /* The obex server was terminated abnormally */
2396 _bt_rfcomm_server_check_termination(name);
2399 /* Stop advertising started by terminated process */
2400 _bt_stop_advertising_by_terminated_process(name);
2402 _bt_stop_le_scan(name);
2406 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2407 const char *path = object_path;
2409 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2410 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2413 _bt_handle_property_changed_event(parameters, object_path);
2414 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2415 _bt_handle_adapter_event(parameters, signal_name);
2416 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2417 _bt_handle_input_event(parameters, object_path);
2418 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2419 _bt_handle_network_server_event(parameters, signal_name);
2420 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2421 _bt_handle_headset_event(parameters, object_path);
2422 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2423 _bt_handle_sink_event(parameters, object_path);
2424 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2425 _bt_handle_agent_event(parameters, signal_name);
2426 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2427 _bt_handle_device_event(parameters, signal_name, object_path);
2433 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2436 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2437 char *interface_name = NULL;
2439 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2440 retv_if(interface_name == NULL, FALSE);
2442 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2443 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2451 static void __bt_obexd_event_filter(GDBusConnection *connection,
2452 const gchar *sender_name,
2453 const gchar *object_path,
2454 const gchar *interface_name,
2455 const gchar *signal_name,
2456 GVariant *parameters,
2459 const char *member = signal_name;
2460 char *obj_path = NULL;
2461 ret_if(member == NULL);
2463 if (strcasecmp(member, "InterfacesAdded") == 0) {
2464 if (__bt_get_object_path(parameters, &obj_path)) {
2465 BT_ERR("Fail to get the path");
2468 BT_INFO("object_path = [%s]", object_path);
2470 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2471 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2472 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2477 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2478 BT_DBG("Obex_Server_Session_Transfer connected");
2479 _bt_obex_transfer_connected();
2482 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2483 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2484 if (__bt_get_object_path(parameters, &obj_path)) {
2485 BT_ERR("Fail to get the path");
2488 BT_INFO("object_path = [%s]", object_path);
2490 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2491 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2492 BT_DBG("Call PBAP Disconnected");
2493 _bt_obex_pbap_client_disconnect(obj_path);
2496 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2497 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2502 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2503 BT_DBG("Obex_Server_Session_Transfer disconnected");
2504 _bt_obex_transfer_disconnected();
2507 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2508 const char *path = object_path;
2510 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2511 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2512 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2513 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2514 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2518 _bt_handle_property_changed_event(parameters, path);
2524 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2528 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2529 char *interface_name = NULL;
2531 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2533 retv_if(interface_name == NULL, FALSE);
2535 if (strcasecmp(interface_name,
2536 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2547 static void __bt_opc_event_filter(GDBusConnection *connection,
2548 const gchar *sender_name,
2549 const gchar *object_path,
2550 const gchar *interface_name,
2551 const gchar *signal_name,
2552 GVariant *parameters,
2555 const char *member = signal_name;
2556 char *obj_path = NULL;
2557 if (strcasecmp(member, "InterfacesAdded") == 0) {
2558 BT_DBG("InterfacesAdded");
2559 }else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2561 if (__bt_get_object_path(parameters, &obj_path)) {
2562 BT_ERR("Fail to get the path");
2566 BT_DBG("object_path =%s",obj_path);
2568 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2569 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2570 || strstr(obj_path, "transfer") == NULL) {
2574 else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2575 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2576 BT_DBG("Going to call opc disconnected");
2577 _bt_opc_disconnected(obj_path);
2580 _bt_sending_files();
2582 }else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE){
2583 char *path = (char *)object_path;
2584 BT_INFO("object_path %s", path);
2585 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2586 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2587 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2591 _bt_opc_property_changed_event(parameters, path);
2597 int _bt_opp_client_event_init(void)
2599 GError *error = NULL;
2601 if (opc_obexd_conn == NULL) {
2602 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2604 if (!opc_obexd_conn) {
2606 BT_ERR("Unable to connect to dbus: %s", error->message);
2607 g_clear_error(&error);
2609 return BLUETOOTH_ERROR_INTERNAL;
2613 if (_bt_register_service_event(opc_obexd_conn,
2614 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2615 g_object_unref(opc_obexd_conn);
2616 opc_obexd_conn = NULL;
2617 return BLUETOOTH_ERROR_INTERNAL;
2620 return BLUETOOTH_ERROR_NONE;
2623 void _bt_opp_client_event_deinit(void)
2625 if (opc_obexd_conn) {
2626 _bt_unregister_service_event(opc_obexd_conn,
2627 BT_OPP_CLIENT_EVENT);
2628 g_object_unref(opc_obexd_conn);
2629 opc_obexd_conn = NULL;
2633 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2639 static int subs_interface_added_id = -1;
2640 static int subs_interface_removed_id = -1;
2641 static int subs_name_owner_id = -1;
2642 static int subs_property_id = -1;
2643 static int subs_adapter_id = -1;
2646 if (subs_interface_added_id == -1) {
2647 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2648 NULL, BT_MANAGER_INTERFACE,
2649 BT_INTERFACES_ADDED, NULL, NULL, 0,
2650 __bt_manager_event_filter,
2653 if (subs_interface_removed_id == -1) {
2654 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2655 NULL, BT_MANAGER_INTERFACE,
2656 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2657 __bt_manager_event_filter,
2660 if (subs_name_owner_id == -1) {
2661 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
2662 NULL, BT_FREEDESKTOP_INTERFACE,
2663 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
2664 __bt_manager_event_filter,
2667 if (subs_property_id == -1) {
2668 subs_property_id = g_dbus_connection_signal_subscribe(conn,
2669 NULL, BT_PROPERTIES_INTERFACE,
2670 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2671 __bt_manager_event_filter,
2674 if (subs_adapter_id == -1) {
2675 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
2676 NULL, BT_ADAPTER_INTERFACE,
2677 NULL, NULL, NULL, 0,
2678 __bt_manager_event_filter,
2682 if (subs_interface_added_id != -1) {
2683 g_dbus_connection_signal_unsubscribe(conn,
2684 subs_interface_added_id);
2685 subs_interface_added_id = -1;
2687 if (subs_interface_removed_id != -1) {
2688 g_dbus_connection_signal_unsubscribe(conn,
2689 subs_interface_removed_id);
2690 subs_interface_removed_id = -1;
2692 if (subs_name_owner_id != -1) {
2693 g_dbus_connection_signal_unsubscribe(conn,
2694 subs_name_owner_id);
2695 subs_name_owner_id = -1;
2697 if (subs_property_id != -1) {
2698 g_dbus_connection_signal_unsubscribe(conn,
2700 subs_property_id = -1;
2702 if (subs_adapter_id == -1) {
2703 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
2704 subs_adapter_id = -1;
2710 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
2716 static int subs_device_id = -1;
2719 if (subs_device_id == -1) {
2720 subs_device_id = g_dbus_connection_signal_subscribe(conn,
2721 NULL, BT_DEVICE_INTERFACE,
2722 NULL, NULL, NULL, 0,
2723 __bt_manager_event_filter,
2727 if (subs_device_id != -1) {
2728 g_dbus_connection_signal_unsubscribe(conn,
2730 subs_device_id = -1;
2736 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
2742 static int subs_input_id = -1;
2745 if (subs_input_id == -1) {
2746 subs_input_id = g_dbus_connection_signal_subscribe(conn,
2747 NULL, BT_INPUT_INTERFACE,
2748 NULL, NULL, NULL, 0,
2749 __bt_manager_event_filter,
2753 if (subs_input_id != -1) {
2754 g_dbus_connection_signal_unsubscribe(conn,
2762 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
2768 static int subs_serv_id = -1;
2769 static int subs_client_id = -1;
2772 if (subs_serv_id == -1) {
2773 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
2774 NULL, BT_NETWORK_SERVER_INTERFACE,
2775 NULL, NULL, NULL, 0,
2776 __bt_manager_event_filter,
2779 if (subs_client_id == -1) {
2780 subs_client_id = g_dbus_connection_signal_subscribe(conn,
2781 NULL, BT_NETWORK_CLIENT_INTERFACE,
2782 NULL, NULL, NULL, 0,
2783 __bt_manager_event_filter,
2787 if (subs_serv_id != -1) {
2788 g_dbus_connection_signal_unsubscribe(conn,
2792 if (subs_client_id != -1) {
2793 g_dbus_connection_signal_unsubscribe(conn,
2795 subs_client_id = -1;
2801 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
2807 static int subs_headset_id = -1;
2808 static int subs_sink_id = -1;
2811 if (subs_headset_id == -1) {
2812 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
2813 NULL, BT_HEADSET_INTERFACE,
2814 NULL, NULL, NULL, 0,
2815 __bt_manager_event_filter,
2818 if (subs_sink_id == -1) {
2819 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
2820 NULL, BT_SINK_INTERFACE,
2821 NULL, NULL, NULL, 0,
2822 __bt_manager_event_filter,
2826 if (subs_headset_id != -1) {
2827 g_dbus_connection_signal_unsubscribe(conn,
2829 subs_headset_id = -1;
2831 if (subs_sink_id != -1) {
2832 g_dbus_connection_signal_unsubscribe(conn,
2840 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
2846 static int subs_opp_server_interface_added_id = -1;
2847 static int subs_opp_server_interface_removed_id = -1;
2848 static int subs_opp_server_property_id = -1;
2852 if (subs_opp_server_interface_added_id == -1) {
2853 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2854 NULL, BT_MANAGER_INTERFACE,
2855 BT_INTERFACES_ADDED, NULL, NULL, 0,
2856 __bt_obexd_event_filter,
2859 if (subs_opp_server_interface_removed_id == -1) {
2860 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2861 NULL, BT_MANAGER_INTERFACE,
2862 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2863 __bt_obexd_event_filter,
2866 if (subs_opp_server_property_id == -1) {
2867 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
2868 NULL, BT_PROPERTIES_INTERFACE,
2869 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2870 __bt_obexd_event_filter,
2874 if (subs_opp_server_interface_added_id != -1) {
2875 g_dbus_connection_signal_unsubscribe(conn,
2876 subs_opp_server_interface_added_id);
2877 subs_opp_server_interface_added_id = -1;
2879 if (subs_opp_server_interface_removed_id != -1) {
2880 g_dbus_connection_signal_unsubscribe(conn,
2881 subs_opp_server_interface_removed_id);
2882 subs_opp_server_interface_removed_id = -1;
2884 if (subs_opp_server_property_id != -1) {
2885 g_dbus_connection_signal_unsubscribe(conn,
2886 subs_opp_server_property_id);
2887 subs_opp_server_property_id = -1;
2893 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
2899 static int subs_opp_client_interface_added_id = -1;
2900 static int subs_opp_client_interface_removed_id = -1;
2901 static int subs_opp_client_property_id = -1;
2905 if (subs_opp_client_interface_added_id == -1) {
2906 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2907 NULL, BT_MANAGER_INTERFACE,
2908 BT_INTERFACES_ADDED, NULL, NULL, 0,
2909 __bt_opc_event_filter,
2912 if (subs_opp_client_interface_removed_id == -1) {
2913 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2914 NULL, BT_MANAGER_INTERFACE,
2915 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2916 __bt_opc_event_filter,
2919 if (subs_opp_client_property_id == -1) {
2920 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
2921 NULL, BT_PROPERTIES_INTERFACE,
2922 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2923 __bt_opc_event_filter,
2927 if (subs_opp_client_interface_added_id != -1) {
2928 g_dbus_connection_signal_unsubscribe(conn,
2929 subs_opp_client_interface_added_id);
2930 subs_opp_client_interface_added_id = -1;
2932 if (subs_opp_client_interface_removed_id != -1) {
2933 g_dbus_connection_signal_unsubscribe(conn,
2934 subs_opp_client_interface_removed_id);
2935 subs_opp_client_interface_removed_id = -1;
2937 if (subs_opp_client_property_id != -1) {
2938 g_dbus_connection_signal_unsubscribe(conn,
2939 subs_opp_client_property_id);
2940 subs_opp_client_property_id = -1;
2946 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
2952 static int subs_a2dp_source_id = -1;
2953 static int subs_a2dp_sink_id = -1;
2956 if (subs_a2dp_source_id == -1) {
2957 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
2958 NULL, BT_A2DP_SOURCE_INTERFACE,
2959 NULL, NULL, NULL, 0,
2960 __bt_opc_event_filter,
2963 if (subs_a2dp_sink_id == -1) {
2964 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
2965 NULL, BT_SINK_INTERFACE,
2966 NULL, NULL, NULL, 0,
2967 __bt_opc_event_filter,
2971 if (subs_a2dp_source_id != -1) {
2972 g_dbus_connection_signal_unsubscribe(conn,
2973 subs_a2dp_source_id);
2974 subs_a2dp_source_id = -1;
2976 if (subs_a2dp_sink_id != -1) {
2977 g_dbus_connection_signal_unsubscribe(conn,
2979 subs_a2dp_sink_id = -1;
2985 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
2989 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2991 switch (event_type) {
2992 case BT_MANAGER_EVENT:
2993 _bt_register_manager_subscribe_signal(g_conn, TRUE);
2995 case BT_DEVICE_EVENT:
2996 _bt_register_device_subscribe_signal(g_conn, TRUE);
2999 _bt_register_input_subscribe_signal(g_conn, TRUE);
3001 case BT_NETWORK_EVENT:
3002 _bt_register_network_subscribe_signal(g_conn, TRUE);
3004 case BT_HEADSET_EVENT:
3005 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3008 case BT_OPP_SERVER_EVENT:
3009 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3010 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3012 case BT_OPP_CLIENT_EVENT:
3013 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3014 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3016 case BT_A2DP_SOURCE_EVENT:
3017 BT_INFO("A2dp Source event");
3018 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3021 BT_ERR("Unknown event");
3022 return BLUETOOTH_ERROR_INTERNAL;
3025 return BLUETOOTH_ERROR_NONE;
3028 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3032 ret_if(g_conn == NULL);
3034 switch (event_type) {
3035 case BT_MANAGER_EVENT:
3036 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3037 _bt_register_device_subscribe_signal(g_conn, FALSE);
3038 _bt_register_input_subscribe_signal(g_conn, FALSE);
3039 _bt_register_network_subscribe_signal(g_conn, FALSE);
3040 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3042 case BT_OPP_SERVER_EVENT:
3043 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3045 case BT_OPP_CLIENT_EVENT:
3046 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3049 BT_ERR("Unknown event");
3056 static int __bt_init_manager_receiver(void)
3060 GError *error = NULL;
3062 if (manager_conn == NULL) {
3063 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3064 if (error != NULL) {
3065 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3066 g_clear_error(&error);
3068 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3071 if (_bt_register_service_event(manager_conn,
3072 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3074 if (_bt_register_service_event(manager_conn,
3075 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3078 if (_bt_register_service_event(manager_conn,
3079 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3082 if (_bt_register_service_event(manager_conn,
3083 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3086 if (_bt_register_service_event(manager_conn,
3087 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3089 return BLUETOOTH_ERROR_NONE;
3092 g_object_unref(manager_conn);
3093 manager_conn = NULL;
3098 return BLUETOOTH_ERROR_INTERNAL;
3101 static int __bt_init_obexd_receiver(void)
3104 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3105 GError *error = NULL;
3107 if (obexd_conn == NULL) {
3108 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3109 if (error != NULL) {
3110 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3111 g_clear_error(&error);
3113 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3116 if (_bt_register_service_event(obexd_conn,
3117 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3118 BT_ERR("Error while registering service event");
3119 g_object_unref(obexd_conn);
3121 return BLUETOOTH_ERROR_INTERNAL;
3126 return BLUETOOTH_ERROR_NONE;
3129 /* To receive the event from bluez */
3130 int _bt_init_service_event_receiver(void)
3136 result = __bt_init_manager_receiver();
3137 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3139 result = __bt_init_obexd_receiver();
3140 if (result != BLUETOOTH_ERROR_NONE)
3141 BT_ERR("Fail to init obexd receiver");
3145 return BLUETOOTH_ERROR_NONE;
3148 void _bt_deinit_service_event_receiver(void)
3152 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3154 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3157 g_object_unref(manager_conn);
3158 manager_conn = NULL;
3162 g_object_unref(obexd_conn);
3167 g_source_remove(event_id);