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 "bluetooth-api.h"
31 #include "bt-internal-types.h"
33 #include "bt-service-common.h"
34 #include "bt-service-event.h"
35 #include "bt-service-main.h"
36 #include "bt-service-adapter.h"
37 #include "bt-service-adapter-le.h"
38 #include "bt-service-device.h"
39 #include "bt-service-avrcp.h"
40 #include "bt-service-obex-server.h"
41 #include "bt-service-rfcomm-server.h"
42 #include "bt-service-audio.h"
43 #include "bt-service-agent.h"
44 #include "bt-service-pbap.h"
45 #include "bt-service-headset-connection.h"
46 #include "bt-service-avrcp-controller.h"
48 #include "bt-service-opp-client.h"
50 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
51 static GDBusConnection *manager_conn;
52 static GDBusConnection *obexd_conn;
53 static GDBusConnection *opc_obexd_conn;
55 static GList *p_cache_list = NULL;
57 static guint event_id;
58 guint nap_connected_device_count = 0;
59 static guint hid_connected_device_count = 0;
60 static GList *p_adv_ind_list;
63 bt_remote_dev_info_t *dev_info;
67 * obexd connection type
75 OBEX_PCSUITE = (1 << 6),
76 OBEX_SYNCEVOLUTION = (1 << 7),
78 } bluetooth_obex_connection_type_t;
80 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
81 void _bt_opc_property_changed_event(GVariant *msg, char *path);
82 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
83 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
84 void _bt_opp_client_event_deinit(void);
85 void _bt_handle_network_client_event(GVariant *msg_iter,
87 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
90 static void __bt_free_bt_le_adv_info_t(bt_le_adv_info_t *adv_info)
92 g_free(adv_info->addr);
93 g_free(adv_info->data);
97 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
100 bt_le_adv_info_t *adv_info = NULL;
101 GList *current = g_list_first((GList *)p_adv_ind_list);
102 while(current && current->data) {
103 adv_info = (bt_le_adv_info_t *)current->data;
104 retv_if(adv_info && !g_strcmp0(adv_info->addr, addr), adv_info);
105 current = g_list_next(current);
110 static void __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
113 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
114 BT_ERR("adv_info is already added");
115 __bt_free_bt_le_adv_info_t(adv_info);
118 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
121 static void __bt_del_adv_ind_info(char *addr)
124 ret_if(!p_adv_ind_list);
125 bt_le_adv_info_t *adv_info = NULL;
126 GList *current = g_list_first((GList *)p_adv_ind_list);
127 while(current && current->data) {
128 adv_info = (bt_le_adv_info_t *)current->data;
129 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
130 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
131 __bt_free_bt_le_adv_info_t(adv_info);
134 current = g_list_next(current);
138 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
140 ret_if(cache_info == NULL);
141 _bt_free_device_info(cache_info->dev_info);
145 static gboolean __bt_parse_device_properties(GVariant *item,
146 bt_remote_dev_info_t *dev_info)
155 g_variant_iter_init(&iter, item);
156 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
157 if (strcasecmp(key, "Address") == 0) {
158 dev_info->address = g_variant_dup_string(val, &len);
159 } else if (strcasecmp(key, "Class") == 0) {
160 dev_info->class = g_variant_get_uint32(val);
161 } else if (strcasecmp(key, "name") == 0) {
162 if (dev_info->name == NULL)
163 dev_info->name = g_variant_dup_string(val, &len);
164 } else if (strcasecmp(key, "Connected") == 0) {
165 dev_info->connected = g_variant_get_uint32(val);
166 } else if (strcasecmp(key, "paired") == 0) {
167 dev_info->paired = g_variant_get_boolean(val);
168 } else if (strcasecmp(key, "Trusted") == 0) {
169 dev_info->trust = g_variant_get_boolean(val);
170 } else if (strcasecmp(key, "RSSI") == 0) {
171 dev_info->rssi = g_variant_get_int16(val);
172 } else if (strcasecmp(key, "LastAddrType") == 0) {
173 dev_info->addr_type = g_variant_get_byte(val);
174 } else if (strcasecmp(key, "UUIDs") == 0) {
178 size = g_variant_get_size(val);
181 uuid_value = (char **)g_variant_get_strv(val, &size);
182 if (dev_info->uuids == NULL)
183 dev_info->uuids = g_malloc0(sizeof(char *) * size);
185 for (i = 0; uuid_value[i] != NULL; i++) {
186 dev_info->uuid_count++;
187 dev_info->uuids[i] = g_strdup(uuid_value[i]);
191 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
192 g_variant_get(val, "(i)", &dev_info->manufacturer_data_len);
193 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
194 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
195 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
198 if (dev_info->manufacturer_data_len == 0)
199 dev_info->manufacturer_data = g_strdup("");
200 } else if (strcasecmp(key, "ManufacturerData") == 0) {
202 GVariant *manufacturer_var;
203 g_variant_get(val, "@ay", &manufacturer_var);
204 len = g_variant_get_size(manufacturer_var);
206 char *manufacturer_data = (char *)g_variant_get_data(manufacturer_var);
207 dev_info->manufacturer_data = g_malloc0(len);
208 memcpy(dev_info->manufacturer_data, manufacturer_data,
211 g_variant_unref(manufacturer_var);
219 static gboolean __bt_parse_interface(GVariant *msg,
220 bt_remote_dev_info_t *dev_info)
223 GVariant *optional_param;
226 char *interface_name= NULL;
227 GVariant *inner_iter = NULL;
228 g_variant_get(msg, "(&o@a{sa{sv}})",
229 &path, &optional_param);
230 g_variant_iter_init(&iter, optional_param);
232 while ((child = g_variant_iter_next_value(&iter))) {
233 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
234 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
235 BT_DBG("Found a device: %s", path);
236 if (__bt_parse_device_properties(inner_iter,
237 dev_info) == FALSE) {
238 g_variant_unref(inner_iter);
239 g_variant_unref(child);
240 g_variant_unref(optional_param);
241 BT_ERR("Fail to parse the properies");
244 g_variant_unref(inner_iter);
245 g_variant_unref(child);
246 g_variant_unref(optional_param);
250 g_variant_unref(inner_iter);
251 g_variant_unref(child);
254 g_variant_unref(optional_param);
259 static int __bt_get_owner_info(GVariant *msg, char **name,
260 char **previous, char **current)
262 g_variant_get(msg, "(sss)", name, previous, current);
263 return BLUETOOTH_ERROR_NONE;
266 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
267 char **name, char **uuid)
269 g_variant_get(msg, "(sss)", address, name, uuid);
270 return BLUETOOTH_ERROR_NONE;
273 void __bt_set_device_values(gboolean connected, int state)
275 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
277 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) {
278 BT_ERR("vconf_get_int failed");
281 if (connected == TRUE)
282 bt_device_state |= state;
283 else if (bt_device_state & state)
284 bt_device_state ^= state;
286 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) {
287 BT_ERR("vconf_set_int failed");
291 gboolean _bt_discovery_finished_cb(gpointer user_data)
293 int result = BLUETOOTH_ERROR_NONE;
295 GVariant *param = NULL;
296 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
297 if (_bt_get_cancel_by_user() == TRUE) {
298 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
301 _bt_set_cancel_by_user(FALSE);
302 _bt_disable_all_scanner_status();
303 _bt_set_discovery_status(FALSE);
304 param = g_variant_new("(i)", result);
305 _bt_send_event(BT_ADAPTER_EVENT,
306 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
313 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
315 int result = BLUETOOTH_ERROR_NONE;
317 GVariant *param = NULL;
318 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
319 if (_bt_get_cancel_by_user() == TRUE) {
320 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
323 _bt_set_cancel_by_user(FALSE);
324 _bt_set_le_scan_status(FALSE);
325 param = g_variant_new("(i)", result);
326 _bt_send_event(BT_LE_ADAPTER_EVENT,
327 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
334 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
338 ret_if(address == NULL);
341 bt_cache_info_t *cache_info;
342 bt_remote_dev_info_t *dev_info;
344 node = g_list_first(p_cache_list);
346 while (node != NULL){
347 cache_info = (bt_cache_info_t *)node->data;
349 if (cache_info == NULL) {
350 node = g_list_next(node);
354 dev_info = cache_info->dev_info;
355 if (strcasecmp(dev_info->address,
357 BT_DBG("Device Found");
358 if (paired_status == TRUE)
359 cache_info->dev_info->paired = TRUE;
361 cache_info->dev_info->paired = FALSE;
364 node = g_list_next(node);
369 static void __bt_device_remote_connected_properties(
370 bt_remote_dev_info_t *remote_dev_info,
371 char *address, gboolean connected)
373 int result = BLUETOOTH_ERROR_NONE;
375 GVariant *param = NULL;
378 if (remote_dev_info->uuid_count > 0 ) {
379 for (i = 0; i<remote_dev_info->uuid_count; i++) {
380 char *uuid = remote_dev_info->uuids[i];
381 if (strcasecmp(uuid, HID_UUID) == 0){
382 int event = BLUETOOTH_EVENT_NONE;
384 event = (connected == TRUE) ?
385 BLUETOOTH_HID_CONNECTED :
386 BLUETOOTH_HID_DISCONNECTED;
387 param = g_variant_new("(is)", result,
389 _bt_send_event(BT_HID_EVENT, event,
399 void _bt_handle_adapter_event(GVariant *msg, const char *member)
403 int result = BLUETOOTH_ERROR_NONE;
404 GVariant *param = NULL;
405 ret_if(member == NULL);
407 if (strcasecmp(member, "DeviceCreated") == 0) {
408 char *object_path = NULL;
410 bt_remote_dev_info_t *remote_dev_info;
412 ret_if(_bt_is_device_creating() == FALSE);
414 /* Bonding from remote device */
415 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
417 g_variant_get(msg, "(&o)", &object_path);
418 _bt_convert_device_path_to_address((const char*)object_path, address);
420 remote_dev_info = _bt_get_remote_device_info(address);
421 if (remote_dev_info == NULL) {
426 _bt_free_device_info(remote_dev_info);
428 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
429 char *object_path = NULL;
431 bt_cache_info_t *cache_info;
432 bt_remote_dev_info_t *dev_info;
435 /* Bonding from remote device */
436 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
437 g_variant_get(msg, "(&o)", &object_path);
439 /* Fix : NULL_RETURNS */
443 _bt_convert_device_path_to_address((const char *)object_path, address);
445 node = g_list_first(p_cache_list);
447 while (node != NULL){
448 cache_info = (bt_cache_info_t *)node->data;
450 if (cache_info == NULL) {
451 node = g_list_next(node);
455 dev_info = cache_info->dev_info;
456 if (strcasecmp(dev_info->address,
458 p_cache_list = g_list_remove(p_cache_list,
460 __bt_free_cache_info(cache_info);
463 node = g_list_next(node);
466 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
467 BT_DBG("Advertising Enabled");
472 gboolean status = FALSE;
474 g_variant_get(msg, "(ib)", &slot_id, &status);
476 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
478 /* Send event to application */
479 _bt_set_advertising_status(slot_id, status);
481 sender = _bt_get_adv_slot_owner(slot_id);
482 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
485 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
487 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
488 param = g_variant_new("(ii)", result,
490 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
494 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
495 __bt_unregister_adv_slot_owner(slot_id);
496 } else if (strcasecmp(member, "RssiEnabled") == 0) {
497 BT_DBG("RSSI Enabled");
498 gboolean status = FALSE;
499 char *address = NULL;
501 g_variant_get(msg,"(sib)", &address, &link_type, &status);
503 BT_DBG("RSSI Enabled [%s %d]", address, status);
504 param = g_variant_new("(isib)", result,
505 address, link_type, status);
506 _bt_send_event(BT_DEVICE_EVENT,
507 BLUETOOTH_EVENT_RSSI_ENABLED,
510 } else if (strcasecmp(member, "RssiAlert") == 0) {
511 BT_DBG("RSSI Alert");
515 char *address = NULL;
516 g_variant_get(msg,"(siii)", &address, &link_type, &alert_type, &rssi_dbm);
518 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
519 address, alert_type, rssi_dbm);
520 param = g_variant_new("(isiii)", result,
521 address, link_type, alert_type, rssi_dbm);
522 _bt_send_event(BT_DEVICE_EVENT,
523 BLUETOOTH_EVENT_RSSI_ALERT,
526 } else if (strcasecmp(member, "RawRssi") == 0) {
530 char *address = NULL;
531 g_variant_get(msg,"(sii)", &address, &link_type, &rssi_dbm);
533 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
534 address, link_type, rssi_dbm);
535 param = g_variant_new("(isii)", result,
536 address, link_type, rssi_dbm);
537 _bt_send_event(BT_DEVICE_EVENT,
538 BLUETOOTH_EVENT_RAW_RSSI,
541 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
542 BT_ERR_C("Hardware error received from BLUEZ");
543 _bt_recover_adapter();
544 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
545 BT_ERR_C("Tx timeout error received from BLUEZ");
546 _bt_recover_adapter();
551 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
553 GDBusProxy *adapter_proxy;
555 int result = BLUETOOTH_ERROR_NONE;
556 GVariantIter value_iter;
557 GVariant *val = NULL;
559 char *property = NULL;
560 GVariant *param = NULL;
561 g_variant_iter_init (&value_iter, msg);
562 while ((g_variant_iter_loop (&value_iter,"{sv}", &property, &val))) {
563 BT_INFO("Property %s", property);
565 if (strcasecmp(property, "Discovering") == 0) {
566 gboolean discovering = FALSE;
567 g_variant_get(val, "b", &discovering);
568 /* Send event to application */
569 BT_DBG("Discovering %d", discovering);
570 if (discovering == TRUE) {
571 _bt_set_discovery_status(TRUE);
572 param = g_variant_new("(i)", result);
573 _bt_send_event(BT_ADAPTER_EVENT,
574 BLUETOOTH_EVENT_DISCOVERY_STARTED,
577 ret_if(event_id > 0);
579 adapter_proxy = _bt_get_adapter_proxy();
580 ret_if(adapter_proxy == NULL);
582 /* Need to stop searching */
583 g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
585 G_DBUS_CALL_FLAGS_NONE,
589 BT_ERR("Dbus Error : %s", err->message);
593 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
594 (GSourceFunc)_bt_discovery_finished_cb, NULL);
596 } else if (strcasecmp(property, "LEDiscovering") == 0) {
597 gboolean le_discovering = FALSE;
599 g_variant_get(val, "b", &le_discovering);
600 /* Send event to application */
601 if (le_discovering == TRUE) {
602 _bt_set_le_scan_status(TRUE);
603 param = g_variant_new("(i)", result);
604 _bt_send_event(BT_LE_ADAPTER_EVENT,
605 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
608 ret_if(event_id > 0);
610 adapter_proxy = _bt_get_adapter_proxy();
611 ret_if(adapter_proxy == NULL);
613 /* Need to stop searching */
614 g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
616 G_DBUS_CALL_FLAGS_NONE,
620 BT_ERR("Dbus Error %s", err->message);
624 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
625 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
627 } else if (strcasecmp(property, "Name") == 0) {
629 g_variant_get(val, "s", &name);
630 param = g_variant_new("(is)", result, name);
631 /* Send event to application */
632 _bt_send_event(BT_ADAPTER_EVENT,
633 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
636 } else if (strcasecmp(property, "Alias") == 0) {
638 g_variant_get(val, "s", &alias);
639 param = g_variant_new("(is)", result, alias);
640 /* Send event to application */
641 _bt_send_event(BT_ADAPTER_EVENT,
642 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
645 } else if (strcasecmp(property, "Discoverable") == 0) {
646 gboolean discoverable = FALSE;
648 g_variant_get(val, "b", &discoverable);
649 BT_DBG("discoverable %d", discoverable);
651 if (discoverable == FALSE) {
652 if (_bt_get_discoverable_timeout_property() > 0) {
654 adapter_proxy = _bt_get_adapter_properties_proxy();
655 ret_if(adapter_proxy == NULL);
656 g_dbus_proxy_call_sync(adapter_proxy, "Set",
657 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
658 "DiscoverableTimeout",
659 g_variant_new("i", time)),
660 G_DBUS_CALL_FLAGS_NONE,
665 BT_ERR("StopLEDiscovery Failed: %s", err->message);
670 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
672 /* Send event to application */
673 BT_INFO("[Connectable]");
674 param = g_variant_new("(in)", result, mode);
675 _bt_send_event(BT_ADAPTER_EVENT,
676 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
679 _bt_get_discoverable_mode(&mode);
681 /* Event will be sent by "DiscoverableTimeout" signal */
682 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
684 g_variant_unref(val);
688 /* Send event to application */
689 BT_INFO("[General Discoverable]");
690 param = g_variant_new("(in)", result, mode);
691 _bt_send_event(BT_ADAPTER_EVENT,
692 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
695 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
696 _bt_get_discoverable_mode(&mode);
698 /* Event was already sent by "Discoverable" signal */
699 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
700 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
702 g_variant_unref(val);
706 /* Send event to application */
707 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
708 _bt_get_discoverable_timeout_property());
709 param = g_variant_new("(in)", result, mode);
710 _bt_send_event(BT_ADAPTER_EVENT,
711 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
713 } else if (strcasecmp(property, "Powered") == 0) {
714 /* TODO: Need to check this operation!! */
715 gboolean powered = FALSE;
718 g_variant_get(val, "b" ,&powered);
719 BT_DBG("Powered = %d", powered);
720 if (powered == FALSE) {
722 _bt_handle_adapter_removed();
724 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
725 bt_state != VCONFKEY_BT_STATUS_OFF) {
726 _bt_disable_adapter();
730 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
731 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
732 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
737 _bt_handle_adapter_added();
740 } else if (strcasecmp(property, "Connectable") == 0) {
741 gboolean connectable = FALSE;
743 g_variant_get(val, "b", &connectable);
745 BT_DBG("Connectable property is changed : %d", connectable);
746 param = g_variant_new("(b)", connectable);
747 _bt_send_event(BT_ADAPTER_EVENT,
748 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
750 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
751 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
753 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
754 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
757 GVariantIter *iter = NULL;
758 g_variant_get(val, "as", &iter);
759 while (g_variant_iter_loop(iter, "s", &name)) {
760 BT_DBG("name = %s", name);
761 g_variant_iter_loop(iter, "s", &value);
762 BT_DBG("Value = %s", value);
763 if (FALSE == _bt_update_le_feature_support(name, value))
764 BT_INFO("Fail to update LE feature info");
767 g_variant_iter_free(iter);
769 BT_DBG("property : [%s]", property);
774 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
778 GVariantIter value_iter;
779 GVariant *child = NULL, *val = NULL;
780 char *property = NULL;
781 g_variant_iter_init (&value_iter, msg);
782 while ((child = g_variant_iter_next_value (&value_iter))) {
783 g_variant_get(child, "{sv}", &property, &val);
785 ret_if(property == NULL);
787 BT_DBG("property :%s", property);
789 if (strcasecmp(property, "Status") == 0) {
791 g_variant_get(val, "s", &status);
793 if (strcasecmp(status, "active") == 0){
794 _bt_obex_transfer_started(path);
795 } else if (strcasecmp(status, "complete") == 0) {
796 _bt_obex_transfer_completed(path, TRUE);
797 _bt_pbap_obex_transfer_completed(path, TRUE);
798 } else if (strcasecmp(status, "error") == 0){
799 _bt_obex_transfer_completed(path, FALSE);
800 _bt_pbap_obex_transfer_completed(path, FALSE);
803 } else if (strcasecmp(property, "Transferred") == 0) {
804 static int transferred = 0;
805 g_variant_get(val, "t", &transferred);
807 _bt_obex_transfer_progress(path,transferred);
810 g_variant_unref(val);
811 g_variant_unref(child);
816 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
821 int result = BLUETOOTH_ERROR_NONE;
822 GVariantIter value_iter;
824 char *property = NULL;
826 GVariant *param = NULL;
827 bt_remote_dev_info_t *remote_dev_info;
828 g_variant_iter_init (&value_iter, msg);
829 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
830 BT_DBG("Property %s", property);
831 if (strcasecmp(property, "Connected") == 0) {
834 g_variant_get(val, "i", &connected);
836 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
837 BLUETOOTH_EVENT_DEVICE_CONNECTED :
838 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
840 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
842 _bt_convert_device_path_to_address(path, address);
844 BT_DBG("connected: %d", connected);
845 BT_DBG("address: %s", address);
847 remote_dev_info = _bt_get_remote_device_info(address);
849 if (remote_dev_info != NULL) {
850 __bt_device_remote_connected_properties(
851 remote_dev_info, address,
852 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
854 _bt_free_device_info(remote_dev_info);
856 param = g_variant_new("(is)", result, address);
857 /* Send event to application */
858 _bt_send_event(BT_DEVICE_EVENT,
862 } else if (strcasecmp(property, "RSSI") == 0) {
863 bt_remote_dev_info_t *remote_dev_info;
865 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
867 _bt_convert_device_path_to_address(path, address);
868 BT_DBG("address: %s", address);
870 remote_dev_info = _bt_get_remote_device_info(address);
871 if (remote_dev_info == NULL) {
873 g_variant_unref(val);
877 BT_DBG("Address type %d", remote_dev_info->addr_type);
879 if (remote_dev_info && remote_dev_info->addr_type == 0) {
880 BT_DBG("Name %s", remote_dev_info->name);
882 GVariant *uuids = NULL;
883 GVariantBuilder *builder = NULL;
885 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
886 for (i=0; i < remote_dev_info->uuid_count; i++) {
887 g_variant_builder_add(builder, "s",
888 remote_dev_info->uuids[i]);
890 uuids = g_variant_new("as", builder);
891 g_variant_builder_unref(builder);
892 GVariant *manufacturer_data = NULL;
893 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
894 remote_dev_info->manufacturer_data,
895 remote_dev_info->manufacturer_data_len,
898 param = g_variant_new("(isunsbub@asn@ay)", result,
899 remote_dev_info->address,
900 remote_dev_info->class,
901 remote_dev_info->rssi,
902 remote_dev_info->name,
903 remote_dev_info->paired,
904 remote_dev_info->connected,
905 remote_dev_info->trust,
907 remote_dev_info->manufacturer_data_len,
910 _bt_send_event(BT_ADAPTER_EVENT,
911 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
915 _bt_free_device_info(remote_dev_info);
916 } else if (strcasecmp(property, "GattConnected") == 0) {
917 gboolean gatt_connected = FALSE;
919 g_variant_get(val, "b", &gatt_connected);
921 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
922 BLUETOOTH_EVENT_GATT_DISCONNECTED;
924 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
926 _bt_convert_device_path_to_address(path, address);
928 BT_DBG("gatt_connected: %d", gatt_connected);
929 BT_DBG("address: %s", address);
930 param = g_variant_new("(is)", result, address);
931 /* Send event to application */
932 _bt_send_event(BT_DEVICE_EVENT,
936 } else if (strcasecmp(property, "Paired") == 0) {
937 gboolean paired = FALSE;
938 bt_remote_dev_info_t *remote_dev_info;
939 g_variant_get(val, "b", &paired);
940 _bt_agent_set_canceled(FALSE);
941 /* BlueZ sends paired signal for each paired device */
942 /* during activation, We should ignore this, otherwise*/
943 /* application thinks that a new device got paired */
944 if (_bt_adapter_get_status() != BT_ACTIVATED) {
945 BT_DBG("BT is not activated, so ignore this");
947 g_variant_unref(val);
951 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
953 _bt_convert_device_path_to_address(path, address);
955 remote_dev_info = _bt_get_remote_device_info(address);
956 if (remote_dev_info == NULL) {
958 g_variant_unref(val);
963 if(paired == FALSE) {
964 BT_INFO("Unpaired: %s", address);
965 __bt_update_remote_cache_devinfo(address, FALSE);
966 param = g_variant_new("(is)", result, address);
967 _bt_send_event(BT_ADAPTER_EVENT,
968 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
971 BT_INFO("Paired: %s", address);
972 __bt_update_remote_cache_devinfo(address, TRUE);
974 if (_bt_is_device_creating() == TRUE) {
975 BT_DBG("Try to Pair by me");
976 _bt_free_device_info(remote_dev_info);
979 g_variant_unref(val);
982 GVariant *uuids = NULL;
983 GVariantBuilder *builder = NULL;
985 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
986 for (i=0; i < remote_dev_info->uuid_count; i++) {
987 g_variant_builder_add(builder, "s",
988 remote_dev_info->uuids[i]);
990 uuids = g_variant_new("as", builder);
991 g_variant_builder_unref(builder);
992 GVariant *manufacturer_data = NULL;
993 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
994 remote_dev_info->manufacturer_data,
995 remote_dev_info->manufacturer_data_len,
999 param = g_variant_new("(isunsbub@asn@ay)", result,
1000 address, remote_dev_info->class,
1001 remote_dev_info->rssi,
1002 remote_dev_info->name,
1003 remote_dev_info->paired,
1004 remote_dev_info->connected,
1005 remote_dev_info->trust,
1007 remote_dev_info->manufacturer_data_len,
1009 _bt_send_event(BT_ADAPTER_EVENT,
1010 BLUETOOTH_EVENT_BONDING_FINISHED,
1013 _bt_free_device_info(remote_dev_info);
1015 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1016 gboolean paired = FALSE;
1017 bt_remote_dev_info_t *remote_dev_info;
1019 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1020 BT_DBG("BT is not activated, so ignore this");
1022 g_variant_unref(val);
1026 g_variant_get(val, "b", &paired);
1027 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1028 BT_DBG("LegacyPaired: %d", paired);
1029 _bt_convert_device_path_to_address(path, address);
1031 remote_dev_info = _bt_get_remote_device_info(address);
1032 if (remote_dev_info == NULL) {
1035 g_variant_unref(val);
1039 BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
1040 remote_dev_info->name);
1041 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1042 remote_dev_info->name, NULL, NULL, NULL);
1044 _bt_free_device_info(remote_dev_info);
1046 } else if (strcasecmp(property, "Trusted") == 0) {
1047 gboolean trusted = FALSE;
1049 g_variant_get(val, "b", &trusted);
1051 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1052 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1054 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1056 _bt_convert_device_path_to_address(path, address);
1058 BT_DBG("trusted: %d", trusted);
1059 BT_DBG("address: %s", address);
1060 param = g_variant_new("(is)", result, address);
1061 /* Send event to application */
1062 _bt_send_event(BT_DEVICE_EVENT,
1071 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1074 int result = BLUETOOTH_ERROR_NONE;
1075 GVariantIter value_iter;
1076 char *property = NULL;
1078 GVariant *val = NULL;
1079 GVariant *child = NULL;
1080 bt_remote_dev_info_t *remote_dev_info;
1081 GVariant *param = NULL;
1082 g_variant_iter_init (&value_iter, msg);
1083 while ((child = g_variant_iter_next_value (&value_iter))) {
1084 g_variant_get(child, "{sv}", &property, &val);
1085 BT_INFO("Property %s", property);
1086 if (strcasecmp(property, "Connected") == 0) {
1087 gboolean connected = FALSE;
1089 g_variant_get(val, "b", &connected);
1091 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1092 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1094 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1096 _bt_convert_device_path_to_address(path, address);
1098 BT_DBG("connected: %d", connected);
1099 BT_DBG("address: %s", address);
1101 remote_dev_info = _bt_get_remote_device_info(address);
1103 if (remote_dev_info != NULL) {
1104 __bt_device_remote_connected_properties(
1105 remote_dev_info, address, connected);
1106 _bt_free_device_info(remote_dev_info);
1108 param = g_variant_new("(is)", result, address);
1109 /* Send event to application */
1110 _bt_send_event(BT_AVRCP_EVENT,
1116 g_variant_unref(child);
1117 g_variant_unref(val);
1122 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1124 char *interface_name = NULL;
1125 GVariant *val = NULL;
1127 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val,NULL);
1129 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1130 __bt_adapter_property_changed_event(val,
1132 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1133 __bt_device_property_changed_event(val,object_path);
1134 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1135 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1136 __bt_obex_property_changed_event(val,
1138 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1139 __bt_media_control_changed_event(val,
1141 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1142 _bt_handle_avrcp_control_event(val,
1144 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1145 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1146 _bt_handle_network_client_event(val,
1148 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1149 __bt_gatt_char_property_changed_event(val,
1152 g_variant_unref(val);
1155 void __bt_opc_property_changed_event(GVariant *msg,
1158 GVariantIter value_iter;
1159 char *property = NULL;
1160 GVariant *val = NULL;
1161 GVariant *child = NULL;
1163 g_variant_iter_init (&value_iter, msg);
1164 while ((child = g_variant_iter_next_value (&value_iter))) {
1165 g_variant_get(child, "{sv}", &property, &val);
1166 ret_if(property == NULL);
1168 if (strcasecmp(property, "Status") == 0) {
1169 char *status = NULL;
1170 g_variant_get(val, "s", &status);
1171 BT_DBG("Status is %s", status);
1173 if(strcasecmp(status, "active") == 0){
1174 _bt_obex_client_started(path);
1175 }else if (strcasecmp(status, "complete") == 0) {
1176 _bt_obex_client_completed(path, TRUE);
1177 }else if (strcasecmp(status, "error") == 0){
1178 _bt_obex_client_completed(path, FALSE);
1181 } else if (strcasecmp(property, "Transferred") == 0) {
1182 static int transferred = 0;
1183 g_variant_get(val, "t", &transferred);
1185 _bt_obex_client_progress(path, transferred);
1187 BT_DBG("property : [%s]", property);
1190 g_variant_unref(child);
1191 g_variant_unref(val);
1195 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1197 char *interface_name = NULL;
1198 GVariant *value = NULL;
1199 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1200 BT_INFO("interface_name = %s", interface_name);
1201 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1202 __bt_opc_property_changed_event(value,
1205 BT_DBG("interface_name : [%s]", interface_name);
1207 g_variant_unref(value);
1211 void _bt_handle_input_event(GVariant *msg, const char *path)
1213 int result = BLUETOOTH_ERROR_NONE;
1214 gboolean property_flag = FALSE;
1215 GVariantIter value_iter;
1216 char *property = NULL;
1217 GVariant *child = NULL, *val = NULL;
1218 bt_remote_dev_info_t *remote_dev_info;
1219 GVariant *param = NULL;
1220 g_variant_iter_init (&value_iter, msg);
1221 while ((child = g_variant_iter_next_value (&value_iter))) {
1222 g_variant_get(child, "{sv}", &property, &val);
1224 ret_if(property == NULL);
1226 if (strcasecmp(property, "Connected") == 0) {
1227 int event = BLUETOOTH_EVENT_NONE;
1229 g_variant_get(val, "b", &property_flag);
1231 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1233 _bt_convert_device_path_to_address(path, address);
1235 event = (property_flag == TRUE) ?
1236 BLUETOOTH_HID_CONNECTED :
1237 BLUETOOTH_HID_DISCONNECTED;
1238 param = g_variant_new("(is)", result, address);
1239 _bt_send_event(BT_HID_EVENT, event,
1241 /* Check HID connection type (Keyboard or Mouse) and update the status */
1242 remote_dev_info = _bt_get_remote_device_info(address);
1244 if (property_flag == TRUE) {
1245 hid_connected_device_count++;
1246 __bt_set_device_values(TRUE,
1247 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1249 hid_connected_device_count--;
1250 if (hid_connected_device_count == 0)
1251 __bt_set_device_values(FALSE,
1252 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1255 if (remote_dev_info != NULL) {
1256 BT_DBG("HID device class [%x]", remote_dev_info->class);
1257 if (remote_dev_info->class &
1258 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1259 #ifdef ENABLE_TIZEN_2_4
1260 __bt_set_device_values(property_flag,
1261 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1266 if (remote_dev_info->class &
1267 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1268 #ifdef ENABLE_TIZEN_2_4
1269 __bt_set_device_values(property_flag,
1270 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1273 _bt_free_device_info(remote_dev_info);
1278 g_variant_unref(val);
1279 g_variant_unref(child);
1283 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1285 int result = BLUETOOTH_ERROR_NONE;
1286 char *address = NULL;
1287 char *device = NULL;
1288 GVariant *param = NULL;
1289 ret_if(member == NULL);
1290 if (strcasecmp(member, "PeerConnected") == 0) {
1291 g_variant_get(msg, "(ss)", &device, &address);
1293 __bt_set_device_values(TRUE,
1294 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1295 param = g_variant_new("(iss)", result, device, address);
1296 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1300 nap_connected_device_count++;
1301 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1302 g_variant_get(msg, "(ss)", &device, &address);
1303 nap_connected_device_count--;
1304 if (nap_connected_device_count == 0)
1305 __bt_set_device_values(FALSE,
1306 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1307 param = g_variant_new("(iss)", result, device, address);
1308 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1315 void _bt_handle_network_client_event(GVariant *msg,
1320 int result = BLUETOOTH_ERROR_NONE;
1321 gboolean property_flag = FALSE;
1322 char *property = NULL;
1323 GVariant *val = NULL;
1324 GVariantIter value_iter;
1325 GVariant *param = NULL;
1326 g_variant_iter_init (&value_iter, msg);
1327 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1328 if (strcasecmp(property, "Connected") == 0) {
1329 int event = BLUETOOTH_EVENT_NONE;
1332 g_variant_get(val, "b", &property_flag);
1333 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1335 _bt_convert_device_path_to_address(path, address);
1337 BT_DBG("property_flag %d", property_flag);
1338 if (property_flag == TRUE) {
1339 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1340 nap_connected_device_count++;
1341 __bt_set_device_values(TRUE,
1342 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1344 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1345 nap_connected_device_count--;
1346 if (nap_connected_device_count == 0)
1347 __bt_set_device_values(FALSE,
1348 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1350 param = g_variant_new("(is)", result, address);
1351 _bt_send_event(BT_NETWORK_EVENT, event,
1360 void __bt_gatt_char_property_changed_event(GVariant *msg,
1363 GVariantIter value_iter;
1364 char *property = NULL;
1365 char * char_handle = NULL;
1366 GVariant *val = NULL;
1367 int result = BLUETOOTH_ERROR_NONE;
1368 GVariant *param = NULL;
1369 g_variant_iter_init (&value_iter, msg);
1370 char_handle = g_strdup(path);
1371 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1372 BT_INFO("Property %s", property);
1374 ret_if(property == NULL);
1376 if (strcasecmp(property, "Notifying") == 0) {
1377 gboolean property_flag = FALSE;
1378 g_variant_get(val, "b", &property_flag);
1379 if (property_flag == TRUE)
1380 BT_DBG("notifying is enabled");
1382 BT_DBG("notifying is disabled");
1383 } else if (strcasecmp(property, "ChangedValue") == 0) {
1385 GByteArray *gp_byte_array = NULL;
1386 BT_INFO("Type '%s'\n", g_variant_get_type_string (val));
1389 gp_byte_array = g_byte_array_new();
1390 len = g_variant_get_size(val);
1391 BT_DBG("Len = %d", len);
1392 g_byte_array_append (gp_byte_array,
1393 (const guint8 *) g_variant_get_data(val), len);
1394 if (gp_byte_array->len != 0) {
1395 GVariant *byte_array = NULL;
1396 byte_array = g_variant_new_from_data(
1397 G_VARIANT_TYPE_BYTESTRING,
1398 gp_byte_array->data,
1401 param = g_variant_new("(is@ay)", result, char_handle,
1403 _bt_send_event(BT_DEVICE_EVENT,
1404 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
1407 g_byte_array_free(gp_byte_array, TRUE);
1411 g_free(char_handle);
1413 void _bt_handle_device_event(GVariant *msg, const char *member,const char *path)
1416 int result = BLUETOOTH_ERROR_NONE;
1419 const char *property = NULL;
1420 GVariant *param = NULL;
1421 ret_if(path == NULL);
1423 if (strcasecmp(member, "PropertyChanged") == 0) {
1425 g_variant_get(msg, "(s)", &property);
1427 ret_if(property == NULL);
1429 if (strcasecmp(property, "GattConnected") == 0) {
1430 gboolean connected = FALSE;
1432 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1433 _bt_convert_device_path_to_address(path, address);
1434 g_variant_get(msg, "(b)", &connected);
1436 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1437 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1438 param = g_variant_new("(is)", result, address);
1439 _bt_send_event(BT_DEVICE_EVENT,
1443 } else if (strcasecmp(property, "Paired") == 0) {
1444 gboolean paired = FALSE;
1445 bt_remote_dev_info_t *remote_dev_info;
1446 g_variant_get(msg, "(b)", &paired);
1448 ret_if(paired == FALSE);
1450 /* BlueZ sends paired signal for each paired device */
1451 /* during activation, We should ignore this, otherwise*/
1452 /* application thinks that a new device got paired */
1453 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1454 BT_DBG("BT is not activated, so ignore this");
1458 if (_bt_is_device_creating() == TRUE) {
1459 BT_DBG("Try to Pair by me");
1463 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1465 _bt_convert_device_path_to_address(path, address);
1467 remote_dev_info = _bt_get_remote_device_info(address);
1468 if (remote_dev_info == NULL) {
1472 GVariant *uuids = NULL;
1473 GVariantBuilder *builder = NULL;
1475 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1476 for (i=0; i < remote_dev_info->uuid_count; i++) {
1477 g_variant_builder_add(builder, "s",
1478 remote_dev_info->uuids[i]);
1480 uuids = g_variant_new("as", builder);
1481 g_variant_builder_unref(builder);
1482 GVariant *manufacturer_data = NULL;
1483 manufacturer_data = g_variant_new_from_data(
1484 G_VARIANT_TYPE_BYTESTRING,
1485 remote_dev_info->manufacturer_data,
1486 remote_dev_info->manufacturer_data_len,
1488 param = g_variant_new("(isunsbub@asn@ay)", result,
1490 remote_dev_info->class,
1491 remote_dev_info->rssi,
1492 remote_dev_info->name,
1493 remote_dev_info->paired,
1494 remote_dev_info->connected,
1495 remote_dev_info->trust,
1497 remote_dev_info->manufacturer_data_len,
1499 _bt_send_event(BT_ADAPTER_EVENT,
1500 BLUETOOTH_EVENT_BONDING_FINISHED,
1502 _bt_free_device_info(remote_dev_info);
1505 } else if (strcasecmp(property, "UUIDs") == 0) {
1506 /* Once we get the updated uuid information after
1507 * reverse service search, update it to application */
1509 bt_remote_dev_info_t *remote_dev_info;
1511 ret_if(_bt_is_device_creating() == TRUE);
1513 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1515 _bt_convert_device_path_to_address(path, address);
1517 remote_dev_info = _bt_get_remote_device_info(address);
1518 if (remote_dev_info == NULL) {
1523 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1524 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1525 GVariant *uuids = NULL;
1526 GVariantBuilder *builder = NULL;
1528 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1529 for (i=0; i < remote_dev_info->uuid_count; i++) {
1530 g_variant_builder_add(builder, "s",
1531 remote_dev_info->uuids[i]);
1533 uuids = g_variant_new("as", builder);
1534 g_variant_builder_unref(builder);
1535 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1536 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1539 param = g_variant_new("(isunsbub@asn@ay)", result,
1540 address, remote_dev_info->class,
1541 remote_dev_info->rssi,
1542 remote_dev_info->name,
1543 remote_dev_info->paired,
1544 remote_dev_info->connected,
1545 remote_dev_info->trust,
1547 remote_dev_info->manufacturer_data_len,
1549 _bt_send_event(BT_ADAPTER_EVENT,
1550 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1554 _bt_free_device_info(remote_dev_info);
1557 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1558 unsigned char addr_type = 0;
1560 g_variant_get(msg, "(y)", &addr_type);
1562 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1564 _bt_convert_device_path_to_address(path, address);
1565 dev_name = _bt_get_bonded_device_name(address);
1567 BT_INFO("Address : %s Type : %d", address, addr_type);
1568 BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1569 !addr_type ? dev_name : address);
1572 _bt_logging_connection(TRUE, addr_type);
1573 #ifdef ENABLE_TIZEN_2_4
1574 journal_bt_connected();
1576 param = g_variant_new("(isy)", result, address, addr_type);
1577 /*Send event to application*/
1578 _bt_send_event(BT_DEVICE_EVENT,
1579 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1582 } else if (strcasecmp(member, "Disconnected") == 0) {
1583 unsigned char disc_reason = 0;
1584 unsigned char addr_type = 0;
1585 gboolean sending = FALSE;
1587 g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
1589 result = disc_reason;
1591 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1593 _bt_convert_device_path_to_address(path, address);
1594 dev_name = _bt_get_bonded_device_name(address);
1595 #ifdef ENABLE_TIZEN_2_4
1596 journal_bt_disconnected();
1599 /* 0x00 BDADDR_BRDER
1600 0x01 BDADDR_LE_PUBLIC
1601 0x02 BDADDR_LE_RANDOM */
1602 BT_INFO("Address : %s Type : %d", address, addr_type);
1603 BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1604 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1605 !addr_type ? dev_name : address);
1608 _bt_headset_set_local_connection(FALSE);
1609 _bt_logging_connection(FALSE, addr_type);
1611 /*Check for any OPP transfer on the device and cancel
1614 _bt_obex_check_pending_transfer(address);
1615 _bt_opp_client_is_sending(&sending);
1617 _bt_opp_client_check_pending_transfer(address);
1618 param = g_variant_new("(isy)", result, address, addr_type);
1619 _bt_send_event(BT_DEVICE_EVENT,
1620 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1623 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1625 char *profile_uuid = NULL;
1626 bt_headset_wait_t *wait_list;
1628 g_variant_get(msg, "(si)", &profile_uuid, &state);
1630 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1632 _bt_convert_device_path_to_address(path, address);
1634 BT_DBG("Address: %s", address);
1635 BT_DBG("Profile UUID: %s", profile_uuid);
1636 BT_DBG("State: %d", state);
1638 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1639 (state == BT_PROFILE_STATE_CONNECTED)) {
1641 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1642 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1643 bluetooth_device_address_t device_address;
1645 bt_headset_wait_t *wait_list;
1647 __bt_set_device_values(TRUE,
1648 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1650 __bt_connection_manager_set_state(address, event);
1652 if (_bt_headset_get_local_connection() == FALSE)
1653 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1655 /* Connection Started from local device therefore no need to
1656 * intiate connection for pending profile */
1657 _bt_headset_set_local_connection(FALSE);
1659 param = g_variant_new("(is)", result, address);
1660 _bt_send_event(BT_HEADSET_EVENT, event,
1662 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1665 if (g_strcmp0(connected_address, address) != 0) {
1666 _bt_convert_addr_string_to_type(
1667 device_address.addr,
1669 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1670 &device_address, NULL);
1674 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1675 BT_STATE_CONNECTED, address);
1677 wait_list = _bt_get_audio_wait_data();
1678 if (wait_list != NULL &&
1679 (g_strcmp0(wait_list->address, address) == 0))
1680 _bt_rel_wait_data();
1682 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1683 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1685 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1687 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1689 g_free(profile_uuid);
1693 __bt_set_device_values(FALSE,
1694 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1696 __bt_connection_manager_set_state(address, event);
1697 param = g_variant_new("(is)", result, address);
1698 _bt_send_event(BT_HEADSET_EVENT, event,
1700 /* Remove data from the connected list */
1701 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1702 wait_list = _bt_get_audio_wait_data();
1704 if (wait_list == NULL) {
1706 g_free(profile_uuid);
1710 if (((wait_list->type == BT_AUDIO_ALL) &&
1711 (wait_list->ag_flag == TRUE)) ||
1712 (wait_list->type == BT_AUDIO_A2DP) ||
1713 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1714 bluetooth_device_address_t device_address;
1715 _bt_convert_addr_string_to_type(
1716 device_address.addr,
1717 wait_list->address);
1719 _bt_audio_connect(wait_list->req_id,
1722 wait_list->out_param1);
1724 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1726 if (state == BT_PROFILE_STATE_CONNECTED) {
1727 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1728 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1729 bluetooth_device_address_t device_address;
1731 param = g_variant_new("(is)", result, address);
1732 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1734 connected = _bt_is_headset_type_connected(
1738 if (g_strcmp0(connected_address,
1740 _bt_convert_addr_string_to_type(
1741 device_address.addr,
1743 _bt_audio_disconnect(0,
1745 &device_address, NULL);
1748 BT_DBG("device Path: %s", path);
1749 _bt_add_headset_to_list(BT_AVRCP,
1750 BT_STATE_CONNECTED, address);
1751 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1752 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1753 param = g_variant_new("(is)", result, address);
1754 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1756 /* Remove data from the connected list */
1757 _bt_remove_headset_from_list(BT_AVRCP, address);
1759 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1760 if (state == BT_PROFILE_STATE_CONNECTED) {
1761 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1762 BT_INFO("A2DP Source is connected");
1763 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1764 g_variant_new("(is)", result, address));
1765 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1766 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
1767 BT_INFO("A2DP Source Disconnected");
1768 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1769 g_variant_new("(is)", result, address));
1771 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
1772 ((state == BT_PROFILE_STATE_CONNECTED) ||
1773 (state == BT_PROFILE_STATE_DISCONNECTED))) {
1775 if (state == BT_PROFILE_STATE_CONNECTED)
1776 event = BLUETOOTH_HID_CONNECTED;
1778 event = BLUETOOTH_HID_DISCONNECTED;
1779 param = g_variant_new("(is)", result, address);
1780 _bt_send_event(BT_HID_EVENT, event,
1783 if (state == BT_PROFILE_STATE_CONNECTED)
1784 __bt_set_device_values(TRUE,
1785 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1787 __bt_set_device_values(FALSE,
1788 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1791 g_free(profile_uuid);
1792 } else if (strcasecmp(member, "AdvReport") == 0) {
1794 bt_remote_le_dev_info_t *le_dev_info = NULL;
1795 char *buffer = NULL;
1797 bt_le_adv_info_t *adv_info = NULL;
1798 GVariant *value = NULL;
1799 ret_if(_bt_is_le_scanning() == FALSE);
1801 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
1803 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
1804 &le_dev_info->addr_type,
1805 &le_dev_info->adv_type,
1807 &le_dev_info->adv_data_len,
1809 buffer_len = g_variant_get_size(value);
1811 buffer = (char *)g_variant_get_data(value);
1813 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
1815 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1816 _bt_send_scan_result_event(le_dev_info, NULL);
1817 _bt_free_le_device_info(le_dev_info);
1818 g_variant_unref(value);
1822 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
1823 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
1824 adv_info->addr = g_strdup(le_dev_info->address);
1825 adv_info->data_len = le_dev_info->adv_data_len;
1826 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
1827 memcpy(adv_info->data, le_dev_info->adv_data,
1828 le_dev_info->adv_data_len);
1830 __bt_add_adv_ind_info(adv_info);
1832 } else { /* SCAN_RSP */
1833 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
1835 _bt_send_scan_result_event(le_dev_info, adv_info);
1836 __bt_del_adv_ind_info(le_dev_info->address);
1839 _bt_free_le_device_info(le_dev_info);
1840 g_variant_unref(value);
1845 void __bt_set_audio_values(gboolean connected, char *address)
1848 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1850 /* Set the headset name */
1851 if (connected == TRUE) {
1852 name = _bt_get_bonded_device_name(address);
1854 name = g_strdup("");
1857 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
1859 BT_ERR("vconf_set_str failed");
1864 /* Set the headset state */
1865 if (vconf_get_int(VCONFKEY_BT_DEVICE,
1866 &bt_device_state) != 0) {
1867 BT_ERR("vconf_get_str failed");
1870 #ifdef TIZEN_SUPPORT_DUAL_HF
1871 if ((connected == TRUE) &&
1872 (FALSE == __bt_is_companion_device(address))) {
1873 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1874 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
1875 (FALSE == __bt_is_companion_device(address))) {
1876 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1879 if (connected == TRUE) {
1880 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1881 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
1882 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1886 if (vconf_set_int(VCONFKEY_BT_DEVICE,
1887 bt_device_state) != 0) {
1888 BT_ERR("vconf_set_int failed");
1892 void _bt_handle_headset_event(GVariant *msg, const char *path)
1894 int result = BLUETOOTH_ERROR_NONE;
1895 gboolean property_flag = FALSE;
1896 char *property = NULL;
1897 GVariant *value = NULL;
1898 GVariant *param = NULL;
1899 g_variant_get(msg, "(sv)", &property, &value);
1901 ret_if(property == NULL);
1903 BT_DBG("Property = %s \n", property);
1904 /* We allow only 1 headset connection (HSP or HFP)*/
1905 if (strcasecmp(property, "Connected") == 0) {
1906 int event = BLUETOOTH_EVENT_NONE;
1907 bt_headset_wait_t *wait_list;
1909 g_variant_get(value, "b", &property_flag);
1911 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1913 /* Fix : NULL_RETURNS */
1914 if (address == NULL)
1917 _bt_convert_device_path_to_address(path, address);
1919 if (property_flag == TRUE) {
1920 event = BLUETOOTH_EVENT_AG_CONNECTED;
1921 if (_bt_headset_get_local_connection() == FALSE)
1922 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
1924 _bt_headset_set_local_connection(FALSE);
1928 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
1930 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
1931 if (previous_state == BT_STATE_DISCONNECTING)
1932 _bt_send_hf_local_term_event(address);
1934 /* Set the State machine here */
1935 __bt_connection_manager_set_state(address, event);
1936 __bt_set_audio_values(property_flag, address);
1937 param = g_variant_new("(is)", result, address);
1938 _bt_send_event(BT_HEADSET_EVENT, event,
1941 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
1942 /* Remove data from the connected list */
1943 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
1945 wait_list = _bt_get_audio_wait_data();
1946 if (wait_list == NULL) {
1951 bluetooth_device_address_t device_address;
1953 _bt_set_audio_wait_data_flag(TRUE);
1955 _bt_convert_addr_string_to_type(device_address.addr,
1956 wait_list->address);
1957 _bt_audio_connect(wait_list->req_id, wait_list->type,
1958 &device_address, wait_list->out_param1);
1959 _bt_rel_wait_data();
1960 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
1961 /* Add data to the connected list */
1962 _bt_add_headset_to_list(BT_AUDIO_HSP,
1963 BT_STATE_CONNECTED, address);
1965 wait_list = _bt_get_audio_wait_data();
1966 if (wait_list != NULL &&
1967 (g_strcmp0(wait_list->address, address) == 0))
1968 _bt_rel_wait_data();
1970 BT_INFO("Check A2DP pending connect");
1971 _bt_audio_check_pending_connect();
1974 } else if (strcasecmp(property, "State") == 0) {
1977 g_variant_get(value, "s", &state);
1979 /* This code assumes we support only 1 headset connection */
1980 /* Need to use the headset list, if we support multi-headsets */
1981 if (strcasecmp(state, "Playing") == 0) {
1982 BT_DBG("Playing: Sco Connected");
1983 } else if (strcasecmp(state, "connected") == 0 ||
1984 strcasecmp(state, "disconnected") == 0) {
1985 BT_DBG("connected/disconnected: Sco Disconnected");
1987 BT_ERR("Not handled state - %s", state);
1992 } else if (strcasecmp(property, "SpeakerGain") == 0) {
1996 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1998 _bt_convert_device_path_to_address(path, address);
2000 g_variant_get(value, "i", &spkr_gain);
2001 param = g_variant_new("(isq)", result, address, spkr_gain);
2002 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2006 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2010 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2012 _bt_convert_device_path_to_address(path, address);
2014 g_variant_get(value, "i", &mic_gain);
2015 param = g_variant_new("(isq)", result, address, mic_gain);
2016 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2023 g_variant_unref(value);
2026 void _bt_handle_sink_event(GVariant *msg, const char *path)
2028 GVariantIter value_iter;
2029 char *property = NULL;
2031 bt_headset_wait_t *wait_list;
2033 GVariant *child = NULL;
2034 GVariant *val = NULL;
2035 GVariant *param = NULL;
2036 g_variant_iter_init (&value_iter, msg);
2037 while ((child = g_variant_iter_next_value (&value_iter))) {
2039 g_variant_get(child, "{sv}", &property, &val);
2041 ret_if(property == NULL);
2043 BT_DBG("Property = %s \n", property);
2046 if (strcasecmp(property, "State") == 0) {
2047 int result = BLUETOOTH_ERROR_NONE;
2050 g_variant_get(val, "s", &value);
2051 BT_DBG("value: %s", value);
2053 if (g_strcmp0(value, "disconnected") == 0) {
2056 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2058 _bt_convert_device_path_to_address(path, address);
2060 __bt_set_device_values(FALSE,
2061 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2062 param = g_variant_new("(is)", result, address);
2063 _bt_send_event(BT_HEADSET_EVENT,
2064 BLUETOOTH_EVENT_AV_DISCONNECTED,
2067 /* Remove data from the connected list */
2068 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2069 wait_list = _bt_get_audio_wait_data();
2070 if (wait_list == NULL) {
2073 g_variant_unref(val);
2074 g_variant_unref(child);
2079 if (((wait_list->type == BT_AUDIO_ALL) &&
2080 (wait_list->ag_flag == TRUE)) ||
2081 (wait_list->type == BT_AUDIO_A2DP) ||
2082 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2083 bluetooth_device_address_t device_address;
2084 _bt_convert_addr_string_to_type(
2085 device_address.addr,
2086 wait_list->address);
2088 _bt_audio_connect(wait_list->req_id,
2091 wait_list->out_param1);
2094 }else if (strcasecmp(value, "Connected") == 0) {
2096 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2097 bluetooth_device_address_t device_address;
2100 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2102 _bt_convert_device_path_to_address(path, address);
2104 __bt_set_device_values(TRUE,
2105 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2106 param = g_variant_new("(is)", result, address);
2107 _bt_send_event(BT_HEADSET_EVENT,
2108 BLUETOOTH_EVENT_AV_CONNECTED,
2110 /* Check for existing Media device to disconnect */
2111 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2114 /* Match connected device address */
2115 if (g_strcmp0(connected_address, address) != 0) {
2116 /* Convert BD adress from string type */
2117 _bt_convert_addr_string_to_type(
2118 device_address.addr,
2120 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2121 &device_address, NULL);
2125 /* Add data to the connected list */
2126 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2127 BT_STATE_CONNECTED, address);
2134 g_variant_unref(val);
2135 g_variant_unref(child);
2139 void _bt_handle_agent_event(GVariant *msg, const char *member)
2141 int result = BLUETOOTH_ERROR_NONE;
2142 char *address = NULL;
2145 GVariant *param = NULL;
2146 ret_if(member == NULL);
2148 if (strcasecmp(member, "ObexAuthorize") == 0) {
2149 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2150 param = g_variant_new("(iss)", result, address, name);
2151 _bt_send_event(BT_OPP_SERVER_EVENT,
2152 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2156 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2157 bt_rfcomm_server_info_t *server_info;
2159 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2161 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2162 ret_if(server_info == NULL);
2163 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2164 param = g_variant_new("(isssn)", result, address, uuid, name,
2165 server_info->control_fd);
2166 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2167 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2175 static int __bt_get_object_path(GVariant *msg, char **path)
2177 g_variant_get(msg, "(o*)", path, NULL);
2179 return BLUETOOTH_ERROR_INTERNAL;
2181 return BLUETOOTH_ERROR_NONE;
2184 static void __bt_devices_list_free(void)
2186 bt_cache_info_t *cache_info;
2189 node = g_list_first(p_cache_list);
2191 while (node != NULL){
2192 cache_info = (bt_cache_info_t *)node->data;
2193 p_cache_list = g_list_remove(p_cache_list, cache_info);
2194 __bt_free_cache_info(cache_info);
2196 node = g_list_next(node);
2200 static int __bt_parse_event(GVariant *msg)
2204 char *interface_name= NULL;
2205 GVariant *inner_iter = NULL;
2207 g_variant_iter_init(&iter, msg);
2209 while ((child = g_variant_iter_next_value(&iter))) {
2210 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
2211 if (g_strcmp0(interface_name,
2212 BT_DEVICE_INTERFACE) == 0) {
2213 g_variant_unref(inner_iter);
2214 g_variant_unref(child);
2215 return BT_DEVICE_EVENT;
2216 } else if (g_strcmp0(interface_name,
2217 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2218 g_variant_unref(inner_iter);
2219 g_variant_unref(child);
2220 return BT_MEDIA_TRANSFER_EVENT;
2221 } else if (g_strcmp0(interface_name,
2222 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2223 g_variant_unref(inner_iter);
2224 g_variant_unref(child);
2225 return BT_AVRCP_CONTROL_EVENT;
2227 g_variant_unref(inner_iter);
2228 g_variant_unref(child);
2234 static void __bt_manager_event_filter(GDBusConnection *connection,
2235 const gchar *sender_name,
2236 const gchar *object_path,
2237 const gchar *interface_name,
2238 const gchar *signal_name,
2239 GVariant *parameters,
2242 bt_event_type_t bt_event = 0x00;
2243 int result = BLUETOOTH_ERROR_NONE;
2245 char *obj_path = NULL;
2246 GVariant *param = NULL;
2247 if (signal_name == NULL)
2249 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2250 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2252 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0){
2253 #ifdef USB_BLUETOOTH
2254 BT_DBG("Enable Adapter");
2255 _bt_enable_adapter();
2257 _bt_handle_adapter_added();
2261 bt_event = __bt_parse_event(value);
2262 if (bt_event == BT_DEVICE_EVENT) {
2263 bt_cache_info_t *cache_info;
2264 bt_remote_dev_info_t *dev_info;
2266 ret_if(_bt_is_discovering() == FALSE &&
2267 _bt_is_le_scanning() == FALSE);
2269 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2270 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2271 cache_info->dev_info = dev_info;
2273 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2274 BT_ERR("Fail to parse the properies");
2275 __bt_free_cache_info(cache_info);
2276 g_variant_unref(value);
2280 if (dev_info->addr_type != BDADDR_BREDR) {
2281 /* Whenever emit the property changed from bluez,
2282 some property doesn't reach to bt-service.
2283 So LE device is handled as AdvReport signal */
2284 __bt_free_cache_info(cache_info);
2285 g_variant_unref(value);
2289 if (dev_info->name == NULL)
2290 /* If Remote device name is NULL or still RNR is not done
2291 * then display address as name.
2293 dev_info->name = g_strdup(dev_info->address);
2295 GVariant *uuids = NULL;
2296 GVariantBuilder *builder = NULL;
2298 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2299 for (i=0; i < dev_info->uuid_count; i++) {
2300 g_variant_builder_add(builder, "s",
2301 dev_info->uuids[i]);
2303 uuids = g_variant_new("as", builder);
2304 g_variant_builder_unref(builder);
2305 GVariant *manufacturer_data = NULL;
2306 manufacturer_data = g_variant_new_from_data(
2307 G_VARIANT_TYPE_BYTESTRING,
2308 dev_info->manufacturer_data,
2309 dev_info->manufacturer_data_len,
2311 param = g_variant_new("(isunsbub@asn@ay)", result,
2317 dev_info->connected,
2320 dev_info->manufacturer_data_len,
2322 _bt_send_event(BT_ADAPTER_EVENT,
2323 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2325 p_cache_list = g_list_append(p_cache_list, cache_info);
2326 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2327 BT_DBG("Device path : %s ", obj_path);
2328 _bt_set_control_device_path(obj_path);
2331 g_variant_unref(value);
2332 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2333 #ifdef USB_BLUETOOTH
2334 BT_DBG("InterfacesRemoved");
2335 _bt_handle_adapter_removed();
2338 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2339 bt_event = BT_MEDIA_TRANSFER_EVENT;
2340 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2341 bt_event = BT_DEVICE_EVENT;
2342 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2343 bt_event = BT_AVRCP_CONTROL_EVENT;
2345 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2346 _bt_handle_adapter_event(parameters, signal_name);
2347 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2348 BT_INFO("Object Path %s", obj_path);
2349 _bt_remove_control_device_path(obj_path);
2352 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2355 char *previous = NULL;
2356 char *current = NULL;
2358 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2359 BT_ERR("Fail to get the owner info");
2363 if (*current != '\0') {
2373 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2374 BT_DBG("Bluetoothd is terminated");
2375 if (_bt_adapter_get_status() != BT_DEACTIVATING) {
2378 _bt_handle_adapter_removed();
2379 __bt_devices_list_free();
2382 _bt_obex_server_check_allocation(&value);
2384 if (value == TRUE) {
2385 /* Check if the obex server was terminated abnormally */
2386 _bt_obex_server_check_termination(name);
2389 _bt_rfcomm_server_check_existence(&value);
2391 if (value == TRUE) {
2392 /* The obex server was terminated abnormally */
2393 _bt_rfcomm_server_check_termination(name);
2396 /* Stop advertising started by terminated process */
2397 _bt_stop_advertising_by_terminated_process(name);
2399 _bt_stop_le_scan(name);
2403 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2404 const char *path = object_path;
2406 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2407 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2410 _bt_handle_property_changed_event(parameters, object_path);
2411 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2412 _bt_handle_adapter_event(parameters, signal_name);
2413 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2414 _bt_handle_input_event(parameters, object_path);
2415 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2416 _bt_handle_network_server_event(parameters, signal_name);
2417 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2418 _bt_handle_headset_event(parameters, object_path);
2419 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2420 _bt_handle_sink_event(parameters, object_path);
2421 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2422 _bt_handle_agent_event(parameters, signal_name);
2423 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2424 _bt_handle_device_event(parameters, signal_name, object_path);
2430 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2433 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2434 char *interface_name = NULL;
2436 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2437 retv_if(interface_name == NULL, FALSE);
2439 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2440 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2448 static void __bt_obexd_event_filter(GDBusConnection *connection,
2449 const gchar *sender_name,
2450 const gchar *object_path,
2451 const gchar *interface_name,
2452 const gchar *signal_name,
2453 GVariant *parameters,
2456 const char *member = signal_name;
2457 char *obj_path = NULL;
2458 ret_if(member == NULL);
2460 if (strcasecmp(member, "InterfacesAdded") == 0) {
2461 if (__bt_get_object_path(parameters, &obj_path)) {
2462 BT_ERR("Fail to get the path");
2465 BT_INFO("object_path = [%s]", object_path);
2467 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2468 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2469 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2474 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2475 BT_DBG("Obex_Server_Session_Transfer connected");
2476 _bt_obex_transfer_connected();
2479 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2480 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2481 if (__bt_get_object_path(parameters, &obj_path)) {
2482 BT_ERR("Fail to get the path");
2485 BT_INFO("object_path = [%s]", object_path);
2487 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2488 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2489 BT_DBG("Call PBAP Disconnected");
2490 _bt_obex_pbap_client_disconnect(obj_path);
2493 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2494 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2499 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2500 BT_DBG("Obex_Server_Session_Transfer disconnected");
2501 _bt_obex_transfer_disconnected();
2504 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2505 const char *path = object_path;
2507 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2508 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2509 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2510 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2511 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2515 _bt_handle_property_changed_event(parameters, path);
2521 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2525 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2526 char *interface_name = NULL;
2528 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2530 retv_if(interface_name == NULL, FALSE);
2532 if (strcasecmp(interface_name,
2533 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2544 static void __bt_opc_event_filter(GDBusConnection *connection,
2545 const gchar *sender_name,
2546 const gchar *object_path,
2547 const gchar *interface_name,
2548 const gchar *signal_name,
2549 GVariant *parameters,
2552 const char *member = signal_name;
2553 char *obj_path = NULL;
2554 if (strcasecmp(member, "InterfacesAdded") == 0) {
2555 BT_DBG("InterfacesAdded");
2556 }else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2558 if (__bt_get_object_path(parameters, &obj_path)) {
2559 BT_ERR("Fail to get the path");
2563 BT_DBG("object_path =%s",obj_path);
2565 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2566 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2567 || strstr(obj_path, "transfer") == NULL) {
2571 else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2572 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2573 BT_DBG("Going to call opc disconnected");
2574 _bt_opc_disconnected(obj_path);
2577 _bt_sending_files();
2579 }else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE){
2580 char *path = (char *)object_path;
2581 BT_INFO("object_path %s", path);
2582 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2583 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2584 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2588 _bt_opc_property_changed_event(parameters, path);
2594 int _bt_opp_client_event_init(void)
2596 GError *error = NULL;
2598 if (opc_obexd_conn == NULL) {
2599 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2601 if (!opc_obexd_conn) {
2603 BT_ERR("Unable to connect to dbus: %s", error->message);
2604 g_clear_error(&error);
2606 return BLUETOOTH_ERROR_INTERNAL;
2610 if (_bt_register_service_event(opc_obexd_conn,
2611 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2612 g_object_unref(opc_obexd_conn);
2613 opc_obexd_conn = NULL;
2614 return BLUETOOTH_ERROR_INTERNAL;
2617 return BLUETOOTH_ERROR_NONE;
2620 void _bt_opp_client_event_deinit(void)
2622 if (opc_obexd_conn) {
2623 _bt_unregister_service_event(opc_obexd_conn,
2624 BT_OPP_CLIENT_EVENT);
2625 g_object_unref(opc_obexd_conn);
2626 opc_obexd_conn = NULL;
2630 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2636 static int subs_interface_added_id = -1;
2637 static int subs_interface_removed_id = -1;
2638 static int subs_name_owner_id = -1;
2639 static int subs_property_id = -1;
2640 static int subs_adapter_id = -1;
2643 if (subs_interface_added_id == -1) {
2644 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2645 NULL, BT_MANAGER_INTERFACE,
2646 BT_INTERFACES_ADDED, NULL, NULL, 0,
2647 __bt_manager_event_filter,
2650 if (subs_interface_removed_id == -1) {
2651 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2652 NULL, BT_MANAGER_INTERFACE,
2653 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2654 __bt_manager_event_filter,
2657 if (subs_name_owner_id == -1) {
2658 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
2659 NULL, BT_FREEDESKTOP_INTERFACE,
2660 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
2661 __bt_manager_event_filter,
2664 if (subs_property_id == -1) {
2665 subs_property_id = g_dbus_connection_signal_subscribe(conn,
2666 NULL, BT_PROPERTIES_INTERFACE,
2667 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2668 __bt_manager_event_filter,
2671 if (subs_adapter_id == -1) {
2672 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
2673 NULL, BT_ADAPTER_INTERFACE,
2674 NULL, NULL, NULL, 0,
2675 __bt_manager_event_filter,
2679 if (subs_interface_added_id != -1) {
2680 g_dbus_connection_signal_unsubscribe(conn,
2681 subs_interface_added_id);
2682 subs_interface_added_id = -1;
2684 if (subs_interface_removed_id != -1) {
2685 g_dbus_connection_signal_unsubscribe(conn,
2686 subs_interface_removed_id);
2687 subs_interface_removed_id = -1;
2689 if (subs_name_owner_id != -1) {
2690 g_dbus_connection_signal_unsubscribe(conn,
2691 subs_name_owner_id);
2692 subs_name_owner_id = -1;
2694 if (subs_property_id != -1) {
2695 g_dbus_connection_signal_unsubscribe(conn,
2697 subs_property_id = -1;
2699 if (subs_adapter_id == -1) {
2700 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
2701 subs_adapter_id = -1;
2707 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
2713 static int subs_device_id = -1;
2716 if (subs_device_id == -1) {
2717 subs_device_id = g_dbus_connection_signal_subscribe(conn,
2718 NULL, BT_DEVICE_INTERFACE,
2719 NULL, NULL, NULL, 0,
2720 __bt_manager_event_filter,
2724 if (subs_device_id != -1) {
2725 g_dbus_connection_signal_unsubscribe(conn,
2727 subs_device_id = -1;
2733 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
2739 static int subs_input_id = -1;
2742 if (subs_input_id == -1) {
2743 subs_input_id = g_dbus_connection_signal_subscribe(conn,
2744 NULL, BT_INPUT_INTERFACE,
2745 NULL, NULL, NULL, 0,
2746 __bt_manager_event_filter,
2750 if (subs_input_id != -1) {
2751 g_dbus_connection_signal_unsubscribe(conn,
2759 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
2765 static int subs_serv_id = -1;
2766 static int subs_client_id = -1;
2769 if (subs_serv_id == -1) {
2770 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
2771 NULL, BT_NETWORK_SERVER_INTERFACE,
2772 NULL, NULL, NULL, 0,
2773 __bt_manager_event_filter,
2776 if (subs_client_id == -1) {
2777 subs_client_id = g_dbus_connection_signal_subscribe(conn,
2778 NULL, BT_NETWORK_CLIENT_INTERFACE,
2779 NULL, NULL, NULL, 0,
2780 __bt_manager_event_filter,
2784 if (subs_serv_id != -1) {
2785 g_dbus_connection_signal_unsubscribe(conn,
2789 if (subs_client_id != -1) {
2790 g_dbus_connection_signal_unsubscribe(conn,
2792 subs_client_id = -1;
2798 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
2804 static int subs_headset_id = -1;
2805 static int subs_sink_id = -1;
2808 if (subs_headset_id == -1) {
2809 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
2810 NULL, BT_HEADSET_INTERFACE,
2811 NULL, NULL, NULL, 0,
2812 __bt_manager_event_filter,
2815 if (subs_sink_id == -1) {
2816 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
2817 NULL, BT_SINK_INTERFACE,
2818 NULL, NULL, NULL, 0,
2819 __bt_manager_event_filter,
2823 if (subs_headset_id != -1) {
2824 g_dbus_connection_signal_unsubscribe(conn,
2826 subs_headset_id = -1;
2828 if (subs_sink_id != -1) {
2829 g_dbus_connection_signal_unsubscribe(conn,
2837 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
2843 static int subs_opp_server_interface_added_id = -1;
2844 static int subs_opp_server_interface_removed_id = -1;
2845 static int subs_opp_server_property_id = -1;
2849 if (subs_opp_server_interface_added_id == -1) {
2850 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2851 NULL, BT_MANAGER_INTERFACE,
2852 BT_INTERFACES_ADDED, NULL, NULL, 0,
2853 __bt_obexd_event_filter,
2856 if (subs_opp_server_interface_removed_id == -1) {
2857 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2858 NULL, BT_MANAGER_INTERFACE,
2859 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2860 __bt_obexd_event_filter,
2863 if (subs_opp_server_property_id == -1) {
2864 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
2865 NULL, BT_PROPERTIES_INTERFACE,
2866 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2867 __bt_obexd_event_filter,
2871 if (subs_opp_server_interface_added_id != -1) {
2872 g_dbus_connection_signal_unsubscribe(conn,
2873 subs_opp_server_interface_added_id);
2874 subs_opp_server_interface_added_id = -1;
2876 if (subs_opp_server_interface_removed_id != -1) {
2877 g_dbus_connection_signal_unsubscribe(conn,
2878 subs_opp_server_interface_removed_id);
2879 subs_opp_server_interface_removed_id = -1;
2881 if (subs_opp_server_property_id != -1) {
2882 g_dbus_connection_signal_unsubscribe(conn,
2883 subs_opp_server_property_id);
2884 subs_opp_server_property_id = -1;
2890 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
2896 static int subs_opp_client_interface_added_id = -1;
2897 static int subs_opp_client_interface_removed_id = -1;
2898 static int subs_opp_client_property_id = -1;
2902 if (subs_opp_client_interface_added_id == -1) {
2903 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2904 NULL, BT_MANAGER_INTERFACE,
2905 BT_INTERFACES_ADDED, NULL, NULL, 0,
2906 __bt_opc_event_filter,
2909 if (subs_opp_client_interface_removed_id == -1) {
2910 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2911 NULL, BT_MANAGER_INTERFACE,
2912 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2913 __bt_opc_event_filter,
2916 if (subs_opp_client_property_id == -1) {
2917 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
2918 NULL, BT_PROPERTIES_INTERFACE,
2919 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2920 __bt_opc_event_filter,
2924 if (subs_opp_client_interface_added_id != -1) {
2925 g_dbus_connection_signal_unsubscribe(conn,
2926 subs_opp_client_interface_added_id);
2927 subs_opp_client_interface_added_id = -1;
2929 if (subs_opp_client_interface_removed_id != -1) {
2930 g_dbus_connection_signal_unsubscribe(conn,
2931 subs_opp_client_interface_removed_id);
2932 subs_opp_client_interface_removed_id = -1;
2934 if (subs_opp_client_property_id != -1) {
2935 g_dbus_connection_signal_unsubscribe(conn,
2936 subs_opp_client_property_id);
2937 subs_opp_client_property_id = -1;
2943 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
2949 static int subs_a2dp_source_id = -1;
2950 static int subs_a2dp_sink_id = -1;
2953 if (subs_a2dp_source_id == -1) {
2954 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
2955 NULL, BT_A2DP_SOURCE_INTERFACE,
2956 NULL, NULL, NULL, 0,
2957 __bt_opc_event_filter,
2960 if (subs_a2dp_sink_id == -1) {
2961 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
2962 NULL, BT_SINK_INTERFACE,
2963 NULL, NULL, NULL, 0,
2964 __bt_opc_event_filter,
2968 if (subs_a2dp_source_id != -1) {
2969 g_dbus_connection_signal_unsubscribe(conn,
2970 subs_a2dp_source_id);
2971 subs_a2dp_source_id = -1;
2973 if (subs_a2dp_sink_id != -1) {
2974 g_dbus_connection_signal_unsubscribe(conn,
2976 subs_a2dp_sink_id = -1;
2982 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
2986 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2988 switch (event_type) {
2989 case BT_MANAGER_EVENT:
2990 _bt_register_manager_subscribe_signal(g_conn, TRUE);
2992 case BT_DEVICE_EVENT:
2993 _bt_register_device_subscribe_signal(g_conn, TRUE);
2996 _bt_register_input_subscribe_signal(g_conn, TRUE);
2998 case BT_NETWORK_EVENT:
2999 _bt_register_network_subscribe_signal(g_conn, TRUE);
3001 case BT_HEADSET_EVENT:
3002 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3005 case BT_OPP_SERVER_EVENT:
3006 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3007 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3009 case BT_OPP_CLIENT_EVENT:
3010 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3011 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3013 case BT_A2DP_SOURCE_EVENT:
3014 BT_INFO("A2dp Source event");
3015 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3018 BT_ERR("Unknown event");
3019 return BLUETOOTH_ERROR_INTERNAL;
3022 return BLUETOOTH_ERROR_NONE;
3025 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3029 ret_if(g_conn == NULL);
3031 switch (event_type) {
3032 case BT_MANAGER_EVENT:
3033 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3034 _bt_register_device_subscribe_signal(g_conn, FALSE);
3035 _bt_register_input_subscribe_signal(g_conn, FALSE);
3036 _bt_register_network_subscribe_signal(g_conn, FALSE);
3037 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3039 case BT_OPP_SERVER_EVENT:
3040 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3042 case BT_OPP_CLIENT_EVENT:
3043 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3046 BT_ERR("Unknown event");
3053 static int __bt_init_manager_receiver(void)
3057 GError *error = NULL;
3059 if (manager_conn == NULL) {
3060 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3061 if (error != NULL) {
3062 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3063 g_clear_error(&error);
3065 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3068 if (_bt_register_service_event(manager_conn,
3069 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3071 if (_bt_register_service_event(manager_conn,
3072 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3075 if (_bt_register_service_event(manager_conn,
3076 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3079 if (_bt_register_service_event(manager_conn,
3080 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3083 if (_bt_register_service_event(manager_conn,
3084 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3086 return BLUETOOTH_ERROR_NONE;
3089 g_object_unref(manager_conn);
3090 manager_conn = NULL;
3095 return BLUETOOTH_ERROR_INTERNAL;
3098 static int __bt_init_obexd_receiver(void)
3101 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3102 GError *error = NULL;
3104 if (obexd_conn == NULL) {
3105 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3106 if (error != NULL) {
3107 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3108 g_clear_error(&error);
3110 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3113 if (_bt_register_service_event(obexd_conn,
3114 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3115 BT_ERR("Error while registering service event");
3116 g_object_unref(obexd_conn);
3118 return BLUETOOTH_ERROR_INTERNAL;
3123 return BLUETOOTH_ERROR_NONE;
3126 /* To receive the event from bluez */
3127 int _bt_init_service_event_receiver(void)
3133 result = __bt_init_manager_receiver();
3134 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3136 result = __bt_init_obexd_receiver();
3137 if (result != BLUETOOTH_ERROR_NONE)
3138 BT_ERR("Fail to init obexd receiver");
3142 return BLUETOOTH_ERROR_NONE;
3145 void _bt_deinit_service_event_receiver(void)
3149 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3151 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3154 g_object_unref(manager_conn);
3155 manager_conn = NULL;
3159 g_object_unref(obexd_conn);
3164 g_source_remove(event_id);