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_set_discovery_status(FALSE);
306 param = g_variant_new("(i)", result);
307 _bt_send_event(BT_ADAPTER_EVENT,
308 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
315 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
317 int result = BLUETOOTH_ERROR_NONE;
319 GVariant *param = NULL;
320 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
321 if (_bt_get_cancel_by_user() == TRUE) {
322 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
325 _bt_set_cancel_by_user(FALSE);
326 _bt_set_le_scan_status(FALSE);
327 param = g_variant_new("(i)", result);
328 _bt_send_event(BT_LE_ADAPTER_EVENT,
329 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
336 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
340 ret_if(address == NULL);
343 bt_cache_info_t *cache_info;
344 bt_remote_dev_info_t *dev_info;
346 node = g_list_first(p_cache_list);
348 while (node != NULL){
349 cache_info = (bt_cache_info_t *)node->data;
351 if (cache_info == NULL) {
352 node = g_list_next(node);
356 dev_info = cache_info->dev_info;
357 if (strcasecmp(dev_info->address,
359 BT_DBG("Device Found");
360 if (paired_status == TRUE)
361 cache_info->dev_info->paired = TRUE;
363 cache_info->dev_info->paired = FALSE;
366 node = g_list_next(node);
371 static void __bt_device_remote_connected_properties(
372 bt_remote_dev_info_t *remote_dev_info,
373 char *address, gboolean connected)
375 int result = BLUETOOTH_ERROR_NONE;
377 GVariant *param = NULL;
380 if (remote_dev_info->uuid_count > 0 ) {
381 for (i = 0; i<remote_dev_info->uuid_count; i++) {
382 char *uuid = remote_dev_info->uuids[i];
383 if (strcasecmp(uuid, HID_UUID) == 0){
384 int event = BLUETOOTH_EVENT_NONE;
386 event = (connected == TRUE) ?
387 BLUETOOTH_HID_CONNECTED :
388 BLUETOOTH_HID_DISCONNECTED;
389 param = g_variant_new("(is)", result,
391 _bt_send_event(BT_HID_EVENT, event,
401 void _bt_handle_adapter_event(GVariant *msg, const char *member)
405 int result = BLUETOOTH_ERROR_NONE;
406 GVariant *param = NULL;
407 ret_if(member == NULL);
409 if (strcasecmp(member, "DeviceCreated") == 0) {
410 char *object_path = NULL;
412 bt_remote_dev_info_t *remote_dev_info;
414 ret_if(_bt_is_device_creating() == FALSE);
416 /* Bonding from remote device */
417 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
419 g_variant_get(msg, "(&o)", &object_path);
420 _bt_convert_device_path_to_address((const char*)object_path, address);
422 remote_dev_info = _bt_get_remote_device_info(address);
423 if (remote_dev_info == NULL) {
428 _bt_free_device_info(remote_dev_info);
430 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
431 char *object_path = NULL;
433 bt_cache_info_t *cache_info;
434 bt_remote_dev_info_t *dev_info;
437 /* Bonding from remote device */
438 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
439 g_variant_get(msg, "(&o)", &object_path);
441 /* Fix : NULL_RETURNS */
445 _bt_convert_device_path_to_address((const char *)object_path, address);
447 node = g_list_first(p_cache_list);
449 while (node != NULL){
450 cache_info = (bt_cache_info_t *)node->data;
452 if (cache_info == NULL) {
453 node = g_list_next(node);
457 dev_info = cache_info->dev_info;
458 if (strcasecmp(dev_info->address,
460 p_cache_list = g_list_remove(p_cache_list,
462 __bt_free_cache_info(cache_info);
465 node = g_list_next(node);
468 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
469 BT_DBG("Advertising Enabled");
474 gboolean status = FALSE;
476 g_variant_get(msg, "(ib)", &slot_id, &status);
478 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
480 /* Send event to application */
481 _bt_set_advertising_status(slot_id, status);
483 sender = _bt_get_adv_slot_owner(slot_id);
484 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
487 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
489 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
490 param = g_variant_new("(ii)", result,
492 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
496 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
497 __bt_unregister_adv_slot_owner(slot_id);
498 } else if (strcasecmp(member, "RssiEnabled") == 0) {
499 BT_DBG("RSSI Enabled");
500 gboolean status = FALSE;
501 char *address = NULL;
503 g_variant_get(msg,"(sib)", &address, &link_type, &status);
505 BT_DBG("RSSI Enabled [%s %d]", address, status);
506 param = g_variant_new("(isib)", result,
507 address, link_type, status);
508 _bt_send_event(BT_DEVICE_EVENT,
509 BLUETOOTH_EVENT_RSSI_ENABLED,
512 } else if (strcasecmp(member, "RssiAlert") == 0) {
513 BT_DBG("RSSI Alert");
517 char *address = NULL;
518 g_variant_get(msg,"(siii)", &address, &link_type, &alert_type, &rssi_dbm);
520 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
521 address, alert_type, rssi_dbm);
522 param = g_variant_new("(isiii)", result,
523 address, link_type, alert_type, rssi_dbm);
524 _bt_send_event(BT_DEVICE_EVENT,
525 BLUETOOTH_EVENT_RSSI_ALERT,
528 } else if (strcasecmp(member, "RawRssi") == 0) {
532 char *address = NULL;
533 g_variant_get(msg,"(sii)", &address, &link_type, &rssi_dbm);
535 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
536 address, link_type, rssi_dbm);
537 param = g_variant_new("(isii)", result,
538 address, link_type, rssi_dbm);
539 _bt_send_event(BT_DEVICE_EVENT,
540 BLUETOOTH_EVENT_RAW_RSSI,
543 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
544 BT_ERR_C("Hardware error received from BLUEZ");
545 _bt_recover_adapter();
546 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
547 BT_ERR_C("Tx timeout error received from BLUEZ");
548 _bt_recover_adapter();
553 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
555 GDBusProxy *adapter_proxy;
557 int result = BLUETOOTH_ERROR_NONE;
558 GVariantIter value_iter;
559 GVariant *val = NULL;
561 char *property = NULL;
562 GVariant *param = NULL;
563 g_variant_iter_init (&value_iter, msg);
564 while ((g_variant_iter_loop (&value_iter,"{sv}", &property, &val))) {
565 BT_INFO("Property %s", property);
567 if (strcasecmp(property, "Discovering") == 0) {
568 gboolean discovering = FALSE;
569 g_variant_get(val, "b", &discovering);
570 /* Send event to application */
571 BT_DBG("Discovering %d", discovering);
572 if (discovering == TRUE) {
573 _bt_set_discovery_status(TRUE);
574 param = g_variant_new("(i)", result);
575 _bt_send_event(BT_ADAPTER_EVENT,
576 BLUETOOTH_EVENT_DISCOVERY_STARTED,
579 ret_if(event_id > 0);
581 adapter_proxy = _bt_get_adapter_proxy();
582 ret_if(adapter_proxy == NULL);
584 /* Need to stop searching */
585 g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
587 G_DBUS_CALL_FLAGS_NONE,
591 BT_ERR("Dbus Error : %s", err->message);
595 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
596 (GSourceFunc)_bt_discovery_finished_cb, NULL);
598 } else if (strcasecmp(property, "LEDiscovering") == 0) {
599 gboolean le_discovering = FALSE;
601 g_variant_get(val, "b", &le_discovering);
602 /* Send event to application */
603 if (le_discovering == TRUE) {
604 _bt_set_le_scan_status(TRUE);
605 param = g_variant_new("(i)", result);
606 _bt_send_event(BT_LE_ADAPTER_EVENT,
607 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
610 ret_if(event_id > 0);
612 adapter_proxy = _bt_get_adapter_proxy();
613 ret_if(adapter_proxy == NULL);
615 /* Need to stop searching */
616 g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
618 G_DBUS_CALL_FLAGS_NONE,
622 BT_ERR("Dbus Error %s", err->message);
626 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
627 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
629 } else if (strcasecmp(property, "Name") == 0) {
631 g_variant_get(val, "s", &name);
632 param = g_variant_new("(is)", result, name);
633 /* Send event to application */
634 _bt_send_event(BT_ADAPTER_EVENT,
635 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
638 } else if (strcasecmp(property, "Alias") == 0) {
640 g_variant_get(val, "s", &alias);
641 param = g_variant_new("(is)", result, alias);
642 /* Send event to application */
643 _bt_send_event(BT_ADAPTER_EVENT,
644 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
647 } else if (strcasecmp(property, "Discoverable") == 0) {
648 gboolean discoverable = FALSE;
650 g_variant_get(val, "b", &discoverable);
651 BT_DBG("discoverable %d", discoverable);
653 if (discoverable == FALSE) {
654 if (_bt_get_discoverable_timeout_property() > 0) {
656 adapter_proxy = _bt_get_adapter_properties_proxy();
657 ret_if(adapter_proxy == NULL);
658 g_dbus_proxy_call_sync(adapter_proxy, "Set",
659 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
660 "DiscoverableTimeout",
661 g_variant_new("i", time)),
662 G_DBUS_CALL_FLAGS_NONE,
667 BT_ERR("StopLEDiscovery Failed: %s", err->message);
672 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
674 /* Send event to application */
675 BT_INFO("[Connectable]");
676 param = g_variant_new("(in)", result, mode);
677 _bt_send_event(BT_ADAPTER_EVENT,
678 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
681 _bt_get_discoverable_mode(&mode);
683 /* Event will be sent by "DiscoverableTimeout" signal */
684 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
686 g_variant_unref(val);
690 /* Send event to application */
691 BT_INFO("[General Discoverable]");
692 param = g_variant_new("(in)", result, mode);
693 _bt_send_event(BT_ADAPTER_EVENT,
694 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
697 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
698 _bt_get_discoverable_mode(&mode);
700 /* Event was already sent by "Discoverable" signal */
701 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
702 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
704 g_variant_unref(val);
708 /* Send event to application */
709 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
710 _bt_get_discoverable_timeout_property());
711 param = g_variant_new("(in)", result, mode);
712 _bt_send_event(BT_ADAPTER_EVENT,
713 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
715 } else if (strcasecmp(property, "Powered") == 0) {
716 /* TODO: Need to check this operation!! */
717 gboolean powered = FALSE;
720 g_variant_get(val, "b" ,&powered);
721 BT_DBG("Powered = %d", powered);
722 if (powered == FALSE) {
724 _bt_handle_adapter_removed();
726 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
727 bt_state != VCONFKEY_BT_STATUS_OFF) {
728 _bt_disable_adapter();
732 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
733 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
734 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
739 _bt_handle_adapter_added();
742 } else if (strcasecmp(property, "Connectable") == 0) {
743 gboolean connectable = FALSE;
745 g_variant_get(val, "b", &connectable);
747 BT_DBG("Connectable property is changed : %d", connectable);
748 param = g_variant_new("(b)", connectable);
749 _bt_send_event(BT_ADAPTER_EVENT,
750 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
752 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
753 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
755 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
756 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
759 GVariantIter *iter = NULL;
760 g_variant_get(val, "as", &iter);
761 while (g_variant_iter_loop(iter, "s", &name)) {
762 BT_DBG("name = %s", name);
763 g_variant_iter_loop(iter, "s", &value);
764 BT_DBG("Value = %s", value);
765 if (FALSE == _bt_update_le_feature_support(name, value))
766 BT_INFO("Fail to update LE feature info");
769 g_variant_iter_free(iter);
771 BT_DBG("property : [%s]", property);
776 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
780 GVariantIter value_iter;
781 GVariant *child = NULL, *val = NULL;
782 char *property = NULL;
783 g_variant_iter_init (&value_iter, msg);
784 while ((child = g_variant_iter_next_value (&value_iter))) {
785 g_variant_get(child, "{sv}", &property, &val);
787 ret_if(property == NULL);
789 BT_DBG("property :%s", property);
791 if (strcasecmp(property, "Status") == 0) {
793 g_variant_get(val, "s", &status);
795 if (strcasecmp(status, "active") == 0){
796 _bt_obex_transfer_started(path);
797 } else if (strcasecmp(status, "complete") == 0) {
798 _bt_obex_transfer_completed(path, TRUE);
799 _bt_pbap_obex_transfer_completed(path, TRUE);
800 } else if (strcasecmp(status, "error") == 0){
801 _bt_obex_transfer_completed(path, FALSE);
802 _bt_pbap_obex_transfer_completed(path, FALSE);
805 } else if (strcasecmp(property, "Transferred") == 0) {
806 static int transferred = 0;
807 g_variant_get(val, "t", &transferred);
809 _bt_obex_transfer_progress(path,transferred);
812 g_variant_unref(val);
813 g_variant_unref(child);
818 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
823 int result = BLUETOOTH_ERROR_NONE;
824 GVariantIter value_iter;
826 char *property = NULL;
828 GVariant *param = NULL;
829 bt_remote_dev_info_t *remote_dev_info;
830 g_variant_iter_init (&value_iter, msg);
831 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
832 BT_DBG("Property %s", property);
833 if (strcasecmp(property, "Connected") == 0) {
836 g_variant_get(val, "i", &connected);
838 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
839 BLUETOOTH_EVENT_DEVICE_CONNECTED :
840 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
842 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
844 _bt_convert_device_path_to_address(path, address);
846 BT_DBG("connected: %d", connected);
847 BT_DBG("address: %s", address);
849 remote_dev_info = _bt_get_remote_device_info(address);
851 if (remote_dev_info != NULL) {
852 __bt_device_remote_connected_properties(
853 remote_dev_info, address,
854 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
856 _bt_free_device_info(remote_dev_info);
858 param = g_variant_new("(is)", result, address);
859 /* Send event to application */
860 _bt_send_event(BT_DEVICE_EVENT,
864 } else if (strcasecmp(property, "RSSI") == 0) {
865 bt_remote_dev_info_t *remote_dev_info;
867 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
869 _bt_convert_device_path_to_address(path, address);
870 BT_DBG("address: %s", address);
872 remote_dev_info = _bt_get_remote_device_info(address);
873 if (remote_dev_info == NULL) {
875 g_variant_unref(val);
879 BT_DBG("Address type %d", remote_dev_info->addr_type);
881 if (remote_dev_info && remote_dev_info->addr_type == 0) {
882 BT_DBG("Name %s", remote_dev_info->name);
884 GVariant *uuids = NULL;
885 GVariantBuilder *builder = NULL;
887 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
888 for (i=0; i < remote_dev_info->uuid_count; i++) {
889 g_variant_builder_add(builder, "s",
890 remote_dev_info->uuids[i]);
892 uuids = g_variant_new("as", builder);
893 g_variant_builder_unref(builder);
894 GVariant *manufacturer_data = NULL;
895 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
896 remote_dev_info->manufacturer_data,
897 remote_dev_info->manufacturer_data_len,
900 param = g_variant_new("(isunsbub@asn@ay)", result,
901 remote_dev_info->address,
902 remote_dev_info->class,
903 remote_dev_info->rssi,
904 remote_dev_info->name,
905 remote_dev_info->paired,
906 remote_dev_info->connected,
907 remote_dev_info->trust,
909 remote_dev_info->manufacturer_data_len,
912 _bt_send_event(BT_ADAPTER_EVENT,
913 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
917 _bt_free_device_info(remote_dev_info);
918 } else if (strcasecmp(property, "GattConnected") == 0) {
919 gboolean gatt_connected = FALSE;
921 g_variant_get(val, "b", &gatt_connected);
923 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
924 BLUETOOTH_EVENT_GATT_DISCONNECTED;
926 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
928 _bt_convert_device_path_to_address(path, address);
930 BT_DBG("gatt_connected: %d", gatt_connected);
931 BT_DBG("address: %s", address);
932 param = g_variant_new("(is)", result, address);
933 /* Send event to application */
934 _bt_send_event(BT_DEVICE_EVENT,
938 } else if (strcasecmp(property, "Paired") == 0) {
939 gboolean paired = FALSE;
940 bt_remote_dev_info_t *remote_dev_info;
941 g_variant_get(val, "b", &paired);
942 _bt_agent_set_canceled(FALSE);
943 /* BlueZ sends paired signal for each paired device */
944 /* during activation, We should ignore this, otherwise*/
945 /* application thinks that a new device got paired */
946 if (_bt_adapter_get_status() != BT_ACTIVATED) {
947 BT_DBG("BT is not activated, so ignore this");
949 g_variant_unref(val);
953 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
955 _bt_convert_device_path_to_address(path, address);
957 remote_dev_info = _bt_get_remote_device_info(address);
958 if (remote_dev_info == NULL) {
960 g_variant_unref(val);
965 if(paired == FALSE) {
966 BT_INFO("Unpaired: %s", address);
967 __bt_update_remote_cache_devinfo(address, FALSE);
968 param = g_variant_new("(is)", result, address);
969 _bt_send_event(BT_ADAPTER_EVENT,
970 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
973 BT_INFO("Paired: %s", address);
974 __bt_update_remote_cache_devinfo(address, TRUE);
976 if (_bt_is_device_creating() == TRUE) {
977 BT_DBG("Try to Pair by me");
978 _bt_free_device_info(remote_dev_info);
981 g_variant_unref(val);
984 GVariant *uuids = NULL;
985 GVariantBuilder *builder = NULL;
987 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
988 for (i=0; i < remote_dev_info->uuid_count; i++) {
989 g_variant_builder_add(builder, "s",
990 remote_dev_info->uuids[i]);
992 uuids = g_variant_new("as", builder);
993 g_variant_builder_unref(builder);
994 GVariant *manufacturer_data = NULL;
995 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
996 remote_dev_info->manufacturer_data,
997 remote_dev_info->manufacturer_data_len,
1001 param = g_variant_new("(isunsbub@asn@ay)", result,
1002 address, remote_dev_info->class,
1003 remote_dev_info->rssi,
1004 remote_dev_info->name,
1005 remote_dev_info->paired,
1006 remote_dev_info->connected,
1007 remote_dev_info->trust,
1009 remote_dev_info->manufacturer_data_len,
1011 _bt_send_event(BT_ADAPTER_EVENT,
1012 BLUETOOTH_EVENT_BONDING_FINISHED,
1015 _bt_free_device_info(remote_dev_info);
1017 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1018 gboolean paired = FALSE;
1019 bt_remote_dev_info_t *remote_dev_info;
1021 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1022 BT_DBG("BT is not activated, so ignore this");
1024 g_variant_unref(val);
1028 g_variant_get(val, "b", &paired);
1029 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1030 BT_DBG("LegacyPaired: %d", paired);
1031 _bt_convert_device_path_to_address(path, address);
1033 remote_dev_info = _bt_get_remote_device_info(address);
1034 if (remote_dev_info == NULL) {
1037 g_variant_unref(val);
1041 BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
1042 remote_dev_info->name);
1043 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1044 remote_dev_info->name, NULL, NULL, NULL);
1046 _bt_free_device_info(remote_dev_info);
1048 } else if (strcasecmp(property, "Trusted") == 0) {
1049 gboolean trusted = FALSE;
1051 g_variant_get(val, "b", &trusted);
1053 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1054 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1056 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1058 _bt_convert_device_path_to_address(path, address);
1060 BT_DBG("trusted: %d", trusted);
1061 BT_DBG("address: %s", address);
1062 param = g_variant_new("(is)", result, address);
1063 /* Send event to application */
1064 _bt_send_event(BT_DEVICE_EVENT,
1073 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1076 int result = BLUETOOTH_ERROR_NONE;
1077 GVariantIter value_iter;
1078 char *property = NULL;
1080 GVariant *val = NULL;
1081 GVariant *child = NULL;
1082 bt_remote_dev_info_t *remote_dev_info;
1083 GVariant *param = NULL;
1084 g_variant_iter_init (&value_iter, msg);
1085 while ((child = g_variant_iter_next_value (&value_iter))) {
1086 g_variant_get(child, "{sv}", &property, &val);
1087 BT_INFO("Property %s", property);
1088 if (strcasecmp(property, "Connected") == 0) {
1089 gboolean connected = FALSE;
1091 g_variant_get(val, "b", &connected);
1093 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1094 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1096 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1098 _bt_convert_device_path_to_address(path, address);
1100 BT_DBG("connected: %d", connected);
1101 BT_DBG("address: %s", address);
1103 remote_dev_info = _bt_get_remote_device_info(address);
1105 if (remote_dev_info != NULL) {
1106 __bt_device_remote_connected_properties(
1107 remote_dev_info, address, connected);
1108 _bt_free_device_info(remote_dev_info);
1110 param = g_variant_new("(is)", result, address);
1111 /* Send event to application */
1112 _bt_send_event(BT_AVRCP_EVENT,
1118 g_variant_unref(child);
1119 g_variant_unref(val);
1124 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1126 char *interface_name = NULL;
1127 GVariant *val = NULL;
1129 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val,NULL);
1131 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1132 __bt_adapter_property_changed_event(val,
1134 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1135 __bt_device_property_changed_event(val,object_path);
1136 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1137 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1138 __bt_obex_property_changed_event(val,
1140 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1141 __bt_media_control_changed_event(val,
1143 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1144 _bt_handle_avrcp_control_event(val,
1146 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1147 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1148 _bt_handle_network_client_event(val,
1150 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1151 __bt_gatt_char_property_changed_event(val,
1154 g_variant_unref(val);
1157 void __bt_opc_property_changed_event(GVariant *msg,
1160 GVariantIter value_iter;
1161 char *property = NULL;
1162 GVariant *val = NULL;
1163 GVariant *child = NULL;
1165 g_variant_iter_init (&value_iter, msg);
1166 while ((child = g_variant_iter_next_value (&value_iter))) {
1167 g_variant_get(child, "{sv}", &property, &val);
1168 ret_if(property == NULL);
1170 if (strcasecmp(property, "Status") == 0) {
1171 char *status = NULL;
1172 g_variant_get(val, "s", &status);
1173 BT_DBG("Status is %s", status);
1175 if(strcasecmp(status, "active") == 0){
1176 _bt_obex_client_started(path);
1177 }else if (strcasecmp(status, "complete") == 0) {
1178 _bt_obex_client_completed(path, TRUE);
1179 }else if (strcasecmp(status, "error") == 0){
1180 _bt_obex_client_completed(path, FALSE);
1183 } else if (strcasecmp(property, "Transferred") == 0) {
1184 static int transferred = 0;
1185 g_variant_get(val, "t", &transferred);
1187 _bt_obex_client_progress(path, transferred);
1189 BT_DBG("property : [%s]", property);
1192 g_variant_unref(child);
1193 g_variant_unref(val);
1197 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1199 char *interface_name = NULL;
1200 GVariant *value = NULL;
1201 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1202 BT_INFO("interface_name = %s", interface_name);
1203 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1204 __bt_opc_property_changed_event(value,
1207 BT_DBG("interface_name : [%s]", interface_name);
1209 g_variant_unref(value);
1213 void _bt_handle_input_event(GVariant *msg, const char *path)
1215 int result = BLUETOOTH_ERROR_NONE;
1216 gboolean property_flag = FALSE;
1217 GVariantIter value_iter;
1218 char *property = NULL;
1219 GVariant *child = NULL, *val = NULL;
1220 bt_remote_dev_info_t *remote_dev_info;
1221 GVariant *param = NULL;
1222 g_variant_iter_init (&value_iter, msg);
1223 while ((child = g_variant_iter_next_value (&value_iter))) {
1224 g_variant_get(child, "{sv}", &property, &val);
1226 ret_if(property == NULL);
1228 if (strcasecmp(property, "Connected") == 0) {
1229 int event = BLUETOOTH_EVENT_NONE;
1231 g_variant_get(val, "b", &property_flag);
1233 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1235 _bt_convert_device_path_to_address(path, address);
1237 event = (property_flag == TRUE) ?
1238 BLUETOOTH_HID_CONNECTED :
1239 BLUETOOTH_HID_DISCONNECTED;
1240 param = g_variant_new("(is)", result, address);
1241 _bt_send_event(BT_HID_EVENT, event,
1243 /* Check HID connection type (Keyboard or Mouse) and update the status */
1244 remote_dev_info = _bt_get_remote_device_info(address);
1246 if (property_flag == TRUE) {
1247 hid_connected_device_count++;
1248 __bt_set_device_values(TRUE,
1249 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1251 hid_connected_device_count--;
1252 if (hid_connected_device_count == 0)
1253 __bt_set_device_values(FALSE,
1254 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1257 if (remote_dev_info != NULL) {
1258 BT_DBG("HID device class [%x]", remote_dev_info->class);
1259 if (remote_dev_info->class &
1260 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1261 #ifdef ENABLE_TIZEN_2_4
1262 __bt_set_device_values(property_flag,
1263 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1268 if (remote_dev_info->class &
1269 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1270 #ifdef ENABLE_TIZEN_2_4
1271 __bt_set_device_values(property_flag,
1272 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1275 _bt_free_device_info(remote_dev_info);
1280 g_variant_unref(val);
1281 g_variant_unref(child);
1285 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1287 int result = BLUETOOTH_ERROR_NONE;
1288 char *address = NULL;
1289 char *device = NULL;
1290 GVariant *param = NULL;
1291 ret_if(member == NULL);
1292 if (strcasecmp(member, "PeerConnected") == 0) {
1293 g_variant_get(msg, "(ss)", &device, &address);
1295 __bt_set_device_values(TRUE,
1296 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1297 param = g_variant_new("(iss)", result, device, address);
1298 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1302 nap_connected_device_count++;
1303 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1304 g_variant_get(msg, "(ss)", &device, &address);
1305 nap_connected_device_count--;
1306 if (nap_connected_device_count == 0)
1307 __bt_set_device_values(FALSE,
1308 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1309 param = g_variant_new("(iss)", result, device, address);
1310 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1317 void _bt_handle_network_client_event(GVariant *msg,
1322 int result = BLUETOOTH_ERROR_NONE;
1323 gboolean property_flag = FALSE;
1324 char *property = NULL;
1325 GVariant *val = NULL;
1326 GVariantIter value_iter;
1327 GVariant *param = NULL;
1328 g_variant_iter_init (&value_iter, msg);
1329 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1330 if (strcasecmp(property, "Connected") == 0) {
1331 int event = BLUETOOTH_EVENT_NONE;
1334 g_variant_get(val, "b", &property_flag);
1335 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1337 _bt_convert_device_path_to_address(path, address);
1339 BT_DBG("property_flag %d", property_flag);
1340 if (property_flag == TRUE) {
1341 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1342 nap_connected_device_count++;
1343 __bt_set_device_values(TRUE,
1344 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1346 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1347 nap_connected_device_count--;
1348 if (nap_connected_device_count == 0)
1349 __bt_set_device_values(FALSE,
1350 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1352 param = g_variant_new("(is)", result, address);
1353 _bt_send_event(BT_NETWORK_EVENT, event,
1362 void __bt_gatt_char_property_changed_event(GVariant *msg,
1365 GVariantIter value_iter;
1366 char *property = NULL;
1367 char * char_handle = NULL;
1368 GVariant *val = NULL;
1369 int result = BLUETOOTH_ERROR_NONE;
1370 GVariant *param = NULL;
1371 g_variant_iter_init (&value_iter, msg);
1372 char_handle = g_strdup(path);
1373 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1374 BT_INFO("Property %s", property);
1376 ret_if(property == NULL);
1378 if (strcasecmp(property, "Notifying") == 0) {
1379 gboolean property_flag = FALSE;
1380 g_variant_get(val, "b", &property_flag);
1381 if (property_flag == TRUE)
1382 BT_DBG("notifying is enabled");
1384 BT_DBG("notifying is disabled");
1385 } else if (strcasecmp(property, "ChangedValue") == 0) {
1387 GByteArray *gp_byte_array = NULL;
1388 BT_INFO("Type '%s'\n", g_variant_get_type_string (val));
1391 gp_byte_array = g_byte_array_new();
1392 len = g_variant_get_size(val);
1393 BT_DBG("Len = %d", len);
1394 g_byte_array_append (gp_byte_array,
1395 (const guint8 *) g_variant_get_data(val), len);
1396 if (gp_byte_array->len != 0) {
1397 GVariant *byte_array = NULL;
1398 byte_array = g_variant_new_from_data(
1399 G_VARIANT_TYPE_BYTESTRING,
1400 gp_byte_array->data,
1403 param = g_variant_new("(is@ay)", result, char_handle,
1405 _bt_send_event(BT_DEVICE_EVENT,
1406 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
1409 g_byte_array_free(gp_byte_array, TRUE);
1413 g_free(char_handle);
1415 void _bt_handle_device_event(GVariant *msg, const char *member,const char *path)
1418 int result = BLUETOOTH_ERROR_NONE;
1421 const char *property = NULL;
1422 GVariant *param = NULL;
1423 ret_if(path == NULL);
1425 if (strcasecmp(member, "PropertyChanged") == 0) {
1427 g_variant_get(msg, "(s)", &property);
1429 ret_if(property == NULL);
1431 if (strcasecmp(property, "GattConnected") == 0) {
1432 gboolean connected = FALSE;
1434 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1435 _bt_convert_device_path_to_address(path, address);
1436 g_variant_get(msg, "(b)", &connected);
1438 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1439 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1440 param = g_variant_new("(is)", result, address);
1441 _bt_send_event(BT_DEVICE_EVENT,
1445 } else if (strcasecmp(property, "Paired") == 0) {
1446 gboolean paired = FALSE;
1447 bt_remote_dev_info_t *remote_dev_info;
1448 g_variant_get(msg, "(b)", &paired);
1450 ret_if(paired == FALSE);
1452 /* BlueZ sends paired signal for each paired device */
1453 /* during activation, We should ignore this, otherwise*/
1454 /* application thinks that a new device got paired */
1455 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1456 BT_DBG("BT is not activated, so ignore this");
1460 if (_bt_is_device_creating() == TRUE) {
1461 BT_DBG("Try to Pair by me");
1465 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1467 _bt_convert_device_path_to_address(path, address);
1469 remote_dev_info = _bt_get_remote_device_info(address);
1470 if (remote_dev_info == NULL) {
1474 GVariant *uuids = NULL;
1475 GVariantBuilder *builder = NULL;
1477 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1478 for (i=0; i < remote_dev_info->uuid_count; i++) {
1479 g_variant_builder_add(builder, "s",
1480 remote_dev_info->uuids[i]);
1482 uuids = g_variant_new("as", builder);
1483 g_variant_builder_unref(builder);
1484 GVariant *manufacturer_data = NULL;
1485 manufacturer_data = g_variant_new_from_data(
1486 G_VARIANT_TYPE_BYTESTRING,
1487 remote_dev_info->manufacturer_data,
1488 remote_dev_info->manufacturer_data_len,
1490 param = g_variant_new("(isunsbub@asn@ay)", result,
1492 remote_dev_info->class,
1493 remote_dev_info->rssi,
1494 remote_dev_info->name,
1495 remote_dev_info->paired,
1496 remote_dev_info->connected,
1497 remote_dev_info->trust,
1499 remote_dev_info->manufacturer_data_len,
1501 _bt_send_event(BT_ADAPTER_EVENT,
1502 BLUETOOTH_EVENT_BONDING_FINISHED,
1504 _bt_free_device_info(remote_dev_info);
1507 } else if (strcasecmp(property, "UUIDs") == 0) {
1508 /* Once we get the updated uuid information after
1509 * reverse service search, update it to application */
1511 bt_remote_dev_info_t *remote_dev_info;
1513 ret_if(_bt_is_device_creating() == TRUE);
1515 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1517 _bt_convert_device_path_to_address(path, address);
1519 remote_dev_info = _bt_get_remote_device_info(address);
1520 if (remote_dev_info == NULL) {
1525 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1526 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1527 GVariant *uuids = NULL;
1528 GVariantBuilder *builder = NULL;
1530 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1531 for (i=0; i < remote_dev_info->uuid_count; i++) {
1532 g_variant_builder_add(builder, "s",
1533 remote_dev_info->uuids[i]);
1535 uuids = g_variant_new("as", builder);
1536 g_variant_builder_unref(builder);
1537 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1538 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1541 param = g_variant_new("(isunsbub@asn@ay)", result,
1542 address, remote_dev_info->class,
1543 remote_dev_info->rssi,
1544 remote_dev_info->name,
1545 remote_dev_info->paired,
1546 remote_dev_info->connected,
1547 remote_dev_info->trust,
1549 remote_dev_info->manufacturer_data_len,
1551 _bt_send_event(BT_ADAPTER_EVENT,
1552 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1556 _bt_free_device_info(remote_dev_info);
1559 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1560 unsigned char addr_type = 0;
1562 g_variant_get(msg, "(y)", &addr_type);
1564 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1566 _bt_convert_device_path_to_address(path, address);
1567 dev_name = _bt_get_bonded_device_name(address);
1569 BT_INFO("Address : %s Type : %d", address, addr_type);
1570 BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1571 !addr_type ? dev_name : address);
1574 _bt_logging_connection(TRUE, addr_type);
1575 #ifdef ENABLE_TIZEN_2_4
1576 journal_bt_connected();
1578 param = g_variant_new("(isy)", result, address, addr_type);
1579 /*Send event to application*/
1580 _bt_send_event(BT_DEVICE_EVENT,
1581 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1584 } else if (strcasecmp(member, "Disconnected") == 0) {
1585 unsigned char disc_reason = 0;
1586 unsigned char addr_type = 0;
1587 gboolean sending = FALSE;
1589 g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
1591 result = disc_reason;
1593 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1595 _bt_convert_device_path_to_address(path, address);
1596 dev_name = _bt_get_bonded_device_name(address);
1597 #ifdef ENABLE_TIZEN_2_4
1598 journal_bt_disconnected();
1601 /* 0x00 BDADDR_BRDER
1602 0x01 BDADDR_LE_PUBLIC
1603 0x02 BDADDR_LE_RANDOM */
1604 BT_INFO("Address : %s Type : %d", address, addr_type);
1605 BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1606 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1607 !addr_type ? dev_name : address);
1610 _bt_headset_set_local_connection(FALSE);
1611 _bt_logging_connection(FALSE, addr_type);
1613 /*Check for any OPP transfer on the device and cancel
1616 _bt_obex_check_pending_transfer(address);
1617 _bt_opp_client_is_sending(&sending);
1619 _bt_opp_client_check_pending_transfer(address);
1620 param = g_variant_new("(isy)", result, address, addr_type);
1621 _bt_send_event(BT_DEVICE_EVENT,
1622 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1625 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1627 char *profile_uuid = NULL;
1628 bt_headset_wait_t *wait_list;
1630 g_variant_get(msg, "(si)", &profile_uuid, &state);
1632 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1634 _bt_convert_device_path_to_address(path, address);
1636 BT_DBG("Address: %s", address);
1637 BT_DBG("Profile UUID: %s", profile_uuid);
1638 BT_DBG("State: %d", state);
1640 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1641 (state == BT_PROFILE_STATE_CONNECTED)) {
1643 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1644 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1645 bluetooth_device_address_t device_address;
1647 bt_headset_wait_t *wait_list;
1649 __bt_set_device_values(TRUE,
1650 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1652 __bt_connection_manager_set_state(address, event);
1654 if (_bt_headset_get_local_connection() == FALSE)
1655 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1657 /* Connection Started from local device therefore no need to
1658 * intiate connection for pending profile */
1659 _bt_headset_set_local_connection(FALSE);
1661 param = g_variant_new("(is)", result, address);
1662 _bt_send_event(BT_HEADSET_EVENT, event,
1664 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1667 if (g_strcmp0(connected_address, address) != 0) {
1668 _bt_convert_addr_string_to_type(
1669 device_address.addr,
1671 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1672 &device_address, NULL);
1676 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1677 BT_STATE_CONNECTED, address);
1679 wait_list = _bt_get_audio_wait_data();
1680 if (wait_list != NULL &&
1681 (g_strcmp0(wait_list->address, address) == 0))
1682 _bt_rel_wait_data();
1684 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1685 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1687 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1689 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1691 g_free(profile_uuid);
1695 __bt_set_device_values(FALSE,
1696 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1698 __bt_connection_manager_set_state(address, event);
1699 param = g_variant_new("(is)", result, address);
1700 _bt_send_event(BT_HEADSET_EVENT, event,
1702 /* Remove data from the connected list */
1703 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1704 wait_list = _bt_get_audio_wait_data();
1706 if (wait_list == NULL) {
1708 g_free(profile_uuid);
1712 if (((wait_list->type == BT_AUDIO_ALL) &&
1713 (wait_list->ag_flag == TRUE)) ||
1714 (wait_list->type == BT_AUDIO_A2DP) ||
1715 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1716 bluetooth_device_address_t device_address;
1717 _bt_convert_addr_string_to_type(
1718 device_address.addr,
1719 wait_list->address);
1721 _bt_audio_connect(wait_list->req_id,
1724 wait_list->out_param1);
1726 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1728 if (state == BT_PROFILE_STATE_CONNECTED) {
1729 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1730 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1731 bluetooth_device_address_t device_address;
1733 param = g_variant_new("(is)", result, address);
1734 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1736 connected = _bt_is_headset_type_connected(
1740 if (g_strcmp0(connected_address,
1742 _bt_convert_addr_string_to_type(
1743 device_address.addr,
1745 _bt_audio_disconnect(0,
1747 &device_address, NULL);
1750 BT_DBG("device Path: %s", path);
1751 _bt_add_headset_to_list(BT_AVRCP,
1752 BT_STATE_CONNECTED, address);
1753 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1754 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1755 param = g_variant_new("(is)", result, address);
1756 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1758 /* Remove data from the connected list */
1759 _bt_remove_headset_from_list(BT_AVRCP, address);
1761 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1762 if (state == BT_PROFILE_STATE_CONNECTED) {
1763 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1764 BT_INFO("A2DP Source is connected");
1765 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1766 g_variant_new("(is)", result, address));
1767 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1768 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
1769 BT_INFO("A2DP Source Disconnected");
1770 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1771 g_variant_new("(is)", result, address));
1773 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
1774 ((state == BT_PROFILE_STATE_CONNECTED) ||
1775 (state == BT_PROFILE_STATE_DISCONNECTED))) {
1777 if (state == BT_PROFILE_STATE_CONNECTED)
1778 event = BLUETOOTH_HID_CONNECTED;
1780 event = BLUETOOTH_HID_DISCONNECTED;
1781 param = g_variant_new("(is)", result, address);
1782 _bt_send_event(BT_HID_EVENT, event,
1785 if (state == BT_PROFILE_STATE_CONNECTED)
1786 __bt_set_device_values(TRUE,
1787 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1789 __bt_set_device_values(FALSE,
1790 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1793 g_free(profile_uuid);
1794 } else if (strcasecmp(member, "AdvReport") == 0) {
1796 bt_remote_le_dev_info_t *le_dev_info = NULL;
1797 char *buffer = NULL;
1799 bt_le_adv_info_t *adv_info = NULL;
1800 GVariant *value = NULL;
1801 ret_if(_bt_is_le_scanning() == FALSE);
1803 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
1805 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
1806 &le_dev_info->addr_type,
1807 &le_dev_info->adv_type,
1809 &le_dev_info->adv_data_len,
1811 buffer_len = g_variant_get_size(value);
1813 buffer = (char *)g_variant_get_data(value);
1815 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
1817 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1818 _bt_send_scan_result_event(le_dev_info, NULL);
1819 _bt_free_le_device_info(le_dev_info);
1820 g_variant_unref(value);
1824 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
1825 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
1826 adv_info->addr = g_strdup(le_dev_info->address);
1827 adv_info->data_len = le_dev_info->adv_data_len;
1828 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
1829 memcpy(adv_info->data, le_dev_info->adv_data,
1830 le_dev_info->adv_data_len);
1832 __bt_add_adv_ind_info(adv_info);
1834 } else { /* SCAN_RSP */
1835 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
1837 _bt_send_scan_result_event(le_dev_info, adv_info);
1838 __bt_del_adv_ind_info(le_dev_info->address);
1841 _bt_free_le_device_info(le_dev_info);
1842 g_variant_unref(value);
1847 void __bt_set_audio_values(gboolean connected, char *address)
1850 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1852 /* Set the headset name */
1853 if (connected == TRUE) {
1854 name = _bt_get_bonded_device_name(address);
1856 name = g_strdup("");
1859 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
1861 BT_ERR("vconf_set_str failed");
1866 /* Set the headset state */
1867 if (vconf_get_int(VCONFKEY_BT_DEVICE,
1868 &bt_device_state) != 0) {
1869 BT_ERR("vconf_get_str failed");
1872 #ifdef TIZEN_SUPPORT_DUAL_HF
1873 if ((connected == TRUE) &&
1874 (FALSE == __bt_is_companion_device(address))) {
1875 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1876 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
1877 (FALSE == __bt_is_companion_device(address))) {
1878 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1881 if (connected == TRUE) {
1882 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1883 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
1884 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1888 if (vconf_set_int(VCONFKEY_BT_DEVICE,
1889 bt_device_state) != 0) {
1890 BT_ERR("vconf_set_int failed");
1894 void _bt_handle_headset_event(GVariant *msg, const char *path)
1896 int result = BLUETOOTH_ERROR_NONE;
1897 gboolean property_flag = FALSE;
1898 char *property = NULL;
1899 GVariant *value = NULL;
1900 GVariant *param = NULL;
1901 g_variant_get(msg, "(sv)", &property, &value);
1903 ret_if(property == NULL);
1905 BT_DBG("Property = %s \n", property);
1906 /* We allow only 1 headset connection (HSP or HFP)*/
1907 if (strcasecmp(property, "Connected") == 0) {
1908 int event = BLUETOOTH_EVENT_NONE;
1909 bt_headset_wait_t *wait_list;
1911 g_variant_get(value, "b", &property_flag);
1913 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1915 /* Fix : NULL_RETURNS */
1916 if (address == NULL)
1919 _bt_convert_device_path_to_address(path, address);
1921 if (property_flag == TRUE) {
1922 event = BLUETOOTH_EVENT_AG_CONNECTED;
1923 if (_bt_headset_get_local_connection() == FALSE)
1924 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
1926 _bt_headset_set_local_connection(FALSE);
1930 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
1932 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
1933 if (previous_state == BT_STATE_DISCONNECTING)
1934 _bt_send_hf_local_term_event(address);
1936 /* Set the State machine here */
1937 __bt_connection_manager_set_state(address, event);
1938 __bt_set_audio_values(property_flag, address);
1939 param = g_variant_new("(is)", result, address);
1940 _bt_send_event(BT_HEADSET_EVENT, event,
1943 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
1944 /* Remove data from the connected list */
1945 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
1947 wait_list = _bt_get_audio_wait_data();
1948 if (wait_list == NULL) {
1953 bluetooth_device_address_t device_address;
1955 _bt_set_audio_wait_data_flag(TRUE);
1957 _bt_convert_addr_string_to_type(device_address.addr,
1958 wait_list->address);
1959 _bt_audio_connect(wait_list->req_id, wait_list->type,
1960 &device_address, wait_list->out_param1);
1961 _bt_rel_wait_data();
1962 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
1963 /* Add data to the connected list */
1964 _bt_add_headset_to_list(BT_AUDIO_HSP,
1965 BT_STATE_CONNECTED, address);
1967 wait_list = _bt_get_audio_wait_data();
1968 if (wait_list != NULL &&
1969 (g_strcmp0(wait_list->address, address) == 0))
1970 _bt_rel_wait_data();
1972 BT_INFO("Check A2DP pending connect");
1973 _bt_audio_check_pending_connect();
1976 } else if (strcasecmp(property, "State") == 0) {
1979 g_variant_get(value, "s", &state);
1981 /* This code assumes we support only 1 headset connection */
1982 /* Need to use the headset list, if we support multi-headsets */
1983 if (strcasecmp(state, "Playing") == 0) {
1984 BT_DBG("Playing: Sco Connected");
1985 } else if (strcasecmp(state, "connected") == 0 ||
1986 strcasecmp(state, "disconnected") == 0) {
1987 BT_DBG("connected/disconnected: Sco Disconnected");
1989 BT_ERR("Not handled state - %s", state);
1994 } else if (strcasecmp(property, "SpeakerGain") == 0) {
1998 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2000 _bt_convert_device_path_to_address(path, address);
2002 g_variant_get(value, "i", &spkr_gain);
2003 param = g_variant_new("(isq)", result, address, spkr_gain);
2004 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2008 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2012 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2014 _bt_convert_device_path_to_address(path, address);
2016 g_variant_get(value, "i", &mic_gain);
2017 param = g_variant_new("(isq)", result, address, mic_gain);
2018 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2025 g_variant_unref(value);
2028 void _bt_handle_sink_event(GVariant *msg, const char *path)
2030 GVariantIter value_iter;
2031 char *property = NULL;
2033 bt_headset_wait_t *wait_list;
2035 GVariant *child = NULL;
2036 GVariant *val = NULL;
2037 GVariant *param = NULL;
2038 g_variant_iter_init (&value_iter, msg);
2039 while ((child = g_variant_iter_next_value (&value_iter))) {
2041 g_variant_get(child, "{sv}", &property, &val);
2043 ret_if(property == NULL);
2045 BT_DBG("Property = %s \n", property);
2048 if (strcasecmp(property, "State") == 0) {
2049 int result = BLUETOOTH_ERROR_NONE;
2052 g_variant_get(val, "s", &value);
2053 BT_DBG("value: %s", value);
2055 if (g_strcmp0(value, "disconnected") == 0) {
2058 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2060 _bt_convert_device_path_to_address(path, address);
2062 __bt_set_device_values(FALSE,
2063 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2064 param = g_variant_new("(is)", result, address);
2065 _bt_send_event(BT_HEADSET_EVENT,
2066 BLUETOOTH_EVENT_AV_DISCONNECTED,
2069 /* Remove data from the connected list */
2070 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2071 wait_list = _bt_get_audio_wait_data();
2072 if (wait_list == NULL) {
2075 g_variant_unref(val);
2076 g_variant_unref(child);
2081 if (((wait_list->type == BT_AUDIO_ALL) &&
2082 (wait_list->ag_flag == TRUE)) ||
2083 (wait_list->type == BT_AUDIO_A2DP) ||
2084 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2085 bluetooth_device_address_t device_address;
2086 _bt_convert_addr_string_to_type(
2087 device_address.addr,
2088 wait_list->address);
2090 _bt_audio_connect(wait_list->req_id,
2093 wait_list->out_param1);
2096 }else if (strcasecmp(value, "Connected") == 0) {
2098 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2099 bluetooth_device_address_t device_address;
2102 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2104 _bt_convert_device_path_to_address(path, address);
2106 __bt_set_device_values(TRUE,
2107 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2108 param = g_variant_new("(is)", result, address);
2109 _bt_send_event(BT_HEADSET_EVENT,
2110 BLUETOOTH_EVENT_AV_CONNECTED,
2112 /* Check for existing Media device to disconnect */
2113 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2116 /* Match connected device address */
2117 if (g_strcmp0(connected_address, address) != 0) {
2118 /* Convert BD adress from string type */
2119 _bt_convert_addr_string_to_type(
2120 device_address.addr,
2122 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2123 &device_address, NULL);
2127 /* Add data to the connected list */
2128 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2129 BT_STATE_CONNECTED, address);
2136 g_variant_unref(val);
2137 g_variant_unref(child);
2141 void _bt_handle_agent_event(GVariant *msg, const char *member)
2143 int result = BLUETOOTH_ERROR_NONE;
2144 char *address = NULL;
2147 GVariant *param = NULL;
2148 ret_if(member == NULL);
2150 if (strcasecmp(member, "ObexAuthorize") == 0) {
2151 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2152 param = g_variant_new("(iss)", result, address, name);
2153 _bt_send_event(BT_OPP_SERVER_EVENT,
2154 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2158 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2159 bt_rfcomm_server_info_t *server_info;
2161 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2163 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2164 ret_if(server_info == NULL);
2165 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2166 param = g_variant_new("(isssn)", result, address, uuid, name,
2167 server_info->control_fd);
2168 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2169 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2177 static int __bt_get_object_path(GVariant *msg, char **path)
2179 g_variant_get(msg, "(o*)", path, NULL);
2181 return BLUETOOTH_ERROR_INTERNAL;
2183 return BLUETOOTH_ERROR_NONE;
2186 static void __bt_devices_list_free(void)
2188 bt_cache_info_t *cache_info;
2191 node = g_list_first(p_cache_list);
2193 while (node != NULL){
2194 cache_info = (bt_cache_info_t *)node->data;
2195 p_cache_list = g_list_remove(p_cache_list, cache_info);
2196 __bt_free_cache_info(cache_info);
2198 node = g_list_next(node);
2202 static int __bt_parse_event(GVariant *msg)
2206 char *interface_name= NULL;
2207 GVariant *inner_iter = NULL;
2209 g_variant_iter_init(&iter, msg);
2211 while ((child = g_variant_iter_next_value(&iter))) {
2212 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
2213 if (g_strcmp0(interface_name,
2214 BT_DEVICE_INTERFACE) == 0) {
2215 g_variant_unref(inner_iter);
2216 g_variant_unref(child);
2217 return BT_DEVICE_EVENT;
2218 } else if (g_strcmp0(interface_name,
2219 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2220 g_variant_unref(inner_iter);
2221 g_variant_unref(child);
2222 return BT_MEDIA_TRANSFER_EVENT;
2223 } else if (g_strcmp0(interface_name,
2224 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2225 g_variant_unref(inner_iter);
2226 g_variant_unref(child);
2227 return BT_AVRCP_CONTROL_EVENT;
2229 g_variant_unref(inner_iter);
2230 g_variant_unref(child);
2236 static void __bt_manager_event_filter(GDBusConnection *connection,
2237 const gchar *sender_name,
2238 const gchar *object_path,
2239 const gchar *interface_name,
2240 const gchar *signal_name,
2241 GVariant *parameters,
2244 bt_event_type_t bt_event = 0x00;
2245 int result = BLUETOOTH_ERROR_NONE;
2247 char *obj_path = NULL;
2248 GVariant *param = NULL;
2249 if (signal_name == NULL)
2251 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2252 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2254 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0){
2255 #ifdef USB_BLUETOOTH
2256 BT_DBG("Enable Adapter");
2257 _bt_enable_adapter();
2259 _bt_handle_adapter_added();
2263 bt_event = __bt_parse_event(value);
2264 if (bt_event == BT_DEVICE_EVENT) {
2265 bt_cache_info_t *cache_info;
2266 bt_remote_dev_info_t *dev_info;
2268 ret_if(_bt_is_discovering() == FALSE &&
2269 _bt_is_le_scanning() == FALSE);
2271 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2272 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2273 cache_info->dev_info = dev_info;
2275 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2276 BT_ERR("Fail to parse the properies");
2277 __bt_free_cache_info(cache_info);
2278 g_variant_unref(value);
2282 if (dev_info->addr_type != BDADDR_BREDR) {
2283 /* Whenever emit the property changed from bluez,
2284 some property doesn't reach to bt-service.
2285 So LE device is handled as AdvReport signal */
2286 __bt_free_cache_info(cache_info);
2287 g_variant_unref(value);
2291 if (dev_info->name == NULL)
2292 /* If Remote device name is NULL or still RNR is not done
2293 * then display address as name.
2295 dev_info->name = g_strdup(dev_info->address);
2297 GVariant *uuids = NULL;
2298 GVariantBuilder *builder = NULL;
2300 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2301 for (i=0; i < dev_info->uuid_count; i++) {
2302 g_variant_builder_add(builder, "s",
2303 dev_info->uuids[i]);
2305 uuids = g_variant_new("as", builder);
2306 g_variant_builder_unref(builder);
2307 GVariant *manufacturer_data = NULL;
2308 manufacturer_data = g_variant_new_from_data(
2309 G_VARIANT_TYPE_BYTESTRING,
2310 dev_info->manufacturer_data,
2311 dev_info->manufacturer_data_len,
2313 param = g_variant_new("(isunsbub@asn@ay)", result,
2319 dev_info->connected,
2322 dev_info->manufacturer_data_len,
2324 _bt_send_event(BT_ADAPTER_EVENT,
2325 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2327 p_cache_list = g_list_append(p_cache_list, cache_info);
2328 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2329 BT_DBG("Device path : %s ", obj_path);
2330 _bt_set_control_device_path(obj_path);
2333 g_variant_unref(value);
2334 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2335 #ifdef USB_BLUETOOTH
2336 BT_DBG("InterfacesRemoved");
2337 _bt_handle_adapter_removed();
2340 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2341 bt_event = BT_MEDIA_TRANSFER_EVENT;
2342 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2343 bt_event = BT_DEVICE_EVENT;
2344 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2345 bt_event = BT_AVRCP_CONTROL_EVENT;
2347 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2348 _bt_handle_adapter_event(parameters, signal_name);
2349 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2350 BT_INFO("Object Path %s", obj_path);
2351 _bt_remove_control_device_path(obj_path);
2354 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2357 char *previous = NULL;
2358 char *current = NULL;
2360 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2361 BT_ERR("Fail to get the owner info");
2365 if (*current != '\0') {
2375 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2376 BT_DBG("Bluetoothd is terminated");
2377 if (_bt_adapter_get_status() != BT_DEACTIVATING) {
2380 _bt_handle_adapter_removed();
2381 __bt_devices_list_free();
2384 _bt_obex_server_check_allocation(&value);
2386 if (value == TRUE) {
2387 /* Check if the obex server was terminated abnormally */
2388 _bt_obex_server_check_termination(name);
2391 _bt_rfcomm_server_check_existence(&value);
2393 if (value == TRUE) {
2394 /* The obex server was terminated abnormally */
2395 _bt_rfcomm_server_check_termination(name);
2398 /* Stop advertising started by terminated process */
2399 _bt_stop_advertising_by_terminated_process(name);
2401 _bt_stop_le_scan(name);
2405 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2406 const char *path = object_path;
2408 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2409 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2412 _bt_handle_property_changed_event(parameters, object_path);
2413 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2414 _bt_handle_adapter_event(parameters, signal_name);
2415 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2416 _bt_handle_input_event(parameters, object_path);
2417 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2418 _bt_handle_network_server_event(parameters, signal_name);
2419 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2420 _bt_handle_headset_event(parameters, object_path);
2421 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2422 _bt_handle_sink_event(parameters, object_path);
2423 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2424 _bt_handle_agent_event(parameters, signal_name);
2425 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2426 _bt_handle_device_event(parameters, signal_name, object_path);
2432 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2435 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2436 char *interface_name = NULL;
2438 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2439 retv_if(interface_name == NULL, FALSE);
2441 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2442 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2450 static void __bt_obexd_event_filter(GDBusConnection *connection,
2451 const gchar *sender_name,
2452 const gchar *object_path,
2453 const gchar *interface_name,
2454 const gchar *signal_name,
2455 GVariant *parameters,
2458 const char *member = signal_name;
2459 char *obj_path = NULL;
2460 ret_if(member == NULL);
2462 if (strcasecmp(member, "InterfacesAdded") == 0) {
2463 if (__bt_get_object_path(parameters, &obj_path)) {
2464 BT_ERR("Fail to get the path");
2467 BT_INFO("object_path = [%s]", object_path);
2469 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2470 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2471 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2476 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2477 BT_DBG("Obex_Server_Session_Transfer connected");
2478 _bt_obex_transfer_connected();
2481 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2482 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2483 if (__bt_get_object_path(parameters, &obj_path)) {
2484 BT_ERR("Fail to get the path");
2487 BT_INFO("object_path = [%s]", object_path);
2489 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2490 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2491 BT_DBG("Call PBAP Disconnected");
2492 _bt_obex_pbap_client_disconnect(obj_path);
2495 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2496 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2501 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2502 BT_DBG("Obex_Server_Session_Transfer disconnected");
2503 _bt_obex_transfer_disconnected();
2506 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2507 const char *path = object_path;
2509 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2510 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2511 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2512 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2513 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2517 _bt_handle_property_changed_event(parameters, path);
2523 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2527 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2528 char *interface_name = NULL;
2530 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2532 retv_if(interface_name == NULL, FALSE);
2534 if (strcasecmp(interface_name,
2535 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2546 static void __bt_opc_event_filter(GDBusConnection *connection,
2547 const gchar *sender_name,
2548 const gchar *object_path,
2549 const gchar *interface_name,
2550 const gchar *signal_name,
2551 GVariant *parameters,
2554 const char *member = signal_name;
2555 char *obj_path = NULL;
2556 if (strcasecmp(member, "InterfacesAdded") == 0) {
2557 BT_DBG("InterfacesAdded");
2558 }else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2560 if (__bt_get_object_path(parameters, &obj_path)) {
2561 BT_ERR("Fail to get the path");
2565 BT_DBG("object_path =%s",obj_path);
2567 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2568 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2569 || strstr(obj_path, "transfer") == NULL) {
2573 else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2574 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2575 BT_DBG("Going to call opc disconnected");
2576 _bt_opc_disconnected(obj_path);
2579 _bt_sending_files();
2581 }else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE){
2582 char *path = (char *)object_path;
2583 BT_INFO("object_path %s", path);
2584 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2585 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2586 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2590 _bt_opc_property_changed_event(parameters, path);
2596 int _bt_opp_client_event_init(void)
2598 GError *error = NULL;
2600 if (opc_obexd_conn == NULL) {
2601 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2603 if (!opc_obexd_conn) {
2605 BT_ERR("Unable to connect to dbus: %s", error->message);
2606 g_clear_error(&error);
2608 return BLUETOOTH_ERROR_INTERNAL;
2612 if (_bt_register_service_event(opc_obexd_conn,
2613 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2614 g_object_unref(opc_obexd_conn);
2615 opc_obexd_conn = NULL;
2616 return BLUETOOTH_ERROR_INTERNAL;
2619 return BLUETOOTH_ERROR_NONE;
2622 void _bt_opp_client_event_deinit(void)
2624 if (opc_obexd_conn) {
2625 _bt_unregister_service_event(opc_obexd_conn,
2626 BT_OPP_CLIENT_EVENT);
2627 g_object_unref(opc_obexd_conn);
2628 opc_obexd_conn = NULL;
2632 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2638 static int subs_interface_added_id = -1;
2639 static int subs_interface_removed_id = -1;
2640 static int subs_name_owner_id = -1;
2641 static int subs_property_id = -1;
2642 static int subs_adapter_id = -1;
2645 if (subs_interface_added_id == -1) {
2646 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2647 NULL, BT_MANAGER_INTERFACE,
2648 BT_INTERFACES_ADDED, NULL, NULL, 0,
2649 __bt_manager_event_filter,
2652 if (subs_interface_removed_id == -1) {
2653 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2654 NULL, BT_MANAGER_INTERFACE,
2655 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2656 __bt_manager_event_filter,
2659 if (subs_name_owner_id == -1) {
2660 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
2661 NULL, BT_FREEDESKTOP_INTERFACE,
2662 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
2663 __bt_manager_event_filter,
2666 if (subs_property_id == -1) {
2667 subs_property_id = g_dbus_connection_signal_subscribe(conn,
2668 NULL, BT_PROPERTIES_INTERFACE,
2669 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2670 __bt_manager_event_filter,
2673 if (subs_adapter_id == -1) {
2674 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
2675 NULL, BT_ADAPTER_INTERFACE,
2676 NULL, NULL, NULL, 0,
2677 __bt_manager_event_filter,
2681 if (subs_interface_added_id != -1) {
2682 g_dbus_connection_signal_unsubscribe(conn,
2683 subs_interface_added_id);
2684 subs_interface_added_id = -1;
2686 if (subs_interface_removed_id != -1) {
2687 g_dbus_connection_signal_unsubscribe(conn,
2688 subs_interface_removed_id);
2689 subs_interface_removed_id = -1;
2691 if (subs_name_owner_id != -1) {
2692 g_dbus_connection_signal_unsubscribe(conn,
2693 subs_name_owner_id);
2694 subs_name_owner_id = -1;
2696 if (subs_property_id != -1) {
2697 g_dbus_connection_signal_unsubscribe(conn,
2699 subs_property_id = -1;
2701 if (subs_adapter_id == -1) {
2702 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
2703 subs_adapter_id = -1;
2709 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
2715 static int subs_device_id = -1;
2718 if (subs_device_id == -1) {
2719 subs_device_id = g_dbus_connection_signal_subscribe(conn,
2720 NULL, BT_DEVICE_INTERFACE,
2721 NULL, NULL, NULL, 0,
2722 __bt_manager_event_filter,
2726 if (subs_device_id != -1) {
2727 g_dbus_connection_signal_unsubscribe(conn,
2729 subs_device_id = -1;
2735 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
2741 static int subs_input_id = -1;
2744 if (subs_input_id == -1) {
2745 subs_input_id = g_dbus_connection_signal_subscribe(conn,
2746 NULL, BT_INPUT_INTERFACE,
2747 NULL, NULL, NULL, 0,
2748 __bt_manager_event_filter,
2752 if (subs_input_id != -1) {
2753 g_dbus_connection_signal_unsubscribe(conn,
2761 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
2767 static int subs_serv_id = -1;
2768 static int subs_client_id = -1;
2771 if (subs_serv_id == -1) {
2772 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
2773 NULL, BT_NETWORK_SERVER_INTERFACE,
2774 NULL, NULL, NULL, 0,
2775 __bt_manager_event_filter,
2778 if (subs_client_id == -1) {
2779 subs_client_id = g_dbus_connection_signal_subscribe(conn,
2780 NULL, BT_NETWORK_CLIENT_INTERFACE,
2781 NULL, NULL, NULL, 0,
2782 __bt_manager_event_filter,
2786 if (subs_serv_id != -1) {
2787 g_dbus_connection_signal_unsubscribe(conn,
2791 if (subs_client_id != -1) {
2792 g_dbus_connection_signal_unsubscribe(conn,
2794 subs_client_id = -1;
2800 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
2806 static int subs_headset_id = -1;
2807 static int subs_sink_id = -1;
2810 if (subs_headset_id == -1) {
2811 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
2812 NULL, BT_HEADSET_INTERFACE,
2813 NULL, NULL, NULL, 0,
2814 __bt_manager_event_filter,
2817 if (subs_sink_id == -1) {
2818 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
2819 NULL, BT_SINK_INTERFACE,
2820 NULL, NULL, NULL, 0,
2821 __bt_manager_event_filter,
2825 if (subs_headset_id != -1) {
2826 g_dbus_connection_signal_unsubscribe(conn,
2828 subs_headset_id = -1;
2830 if (subs_sink_id != -1) {
2831 g_dbus_connection_signal_unsubscribe(conn,
2839 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
2845 static int subs_opp_server_interface_added_id = -1;
2846 static int subs_opp_server_interface_removed_id = -1;
2847 static int subs_opp_server_property_id = -1;
2851 if (subs_opp_server_interface_added_id == -1) {
2852 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2853 NULL, BT_MANAGER_INTERFACE,
2854 BT_INTERFACES_ADDED, NULL, NULL, 0,
2855 __bt_obexd_event_filter,
2858 if (subs_opp_server_interface_removed_id == -1) {
2859 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2860 NULL, BT_MANAGER_INTERFACE,
2861 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2862 __bt_obexd_event_filter,
2865 if (subs_opp_server_property_id == -1) {
2866 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
2867 NULL, BT_PROPERTIES_INTERFACE,
2868 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2869 __bt_obexd_event_filter,
2873 if (subs_opp_server_interface_added_id != -1) {
2874 g_dbus_connection_signal_unsubscribe(conn,
2875 subs_opp_server_interface_added_id);
2876 subs_opp_server_interface_added_id = -1;
2878 if (subs_opp_server_interface_removed_id != -1) {
2879 g_dbus_connection_signal_unsubscribe(conn,
2880 subs_opp_server_interface_removed_id);
2881 subs_opp_server_interface_removed_id = -1;
2883 if (subs_opp_server_property_id != -1) {
2884 g_dbus_connection_signal_unsubscribe(conn,
2885 subs_opp_server_property_id);
2886 subs_opp_server_property_id = -1;
2892 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
2898 static int subs_opp_client_interface_added_id = -1;
2899 static int subs_opp_client_interface_removed_id = -1;
2900 static int subs_opp_client_property_id = -1;
2904 if (subs_opp_client_interface_added_id == -1) {
2905 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2906 NULL, BT_MANAGER_INTERFACE,
2907 BT_INTERFACES_ADDED, NULL, NULL, 0,
2908 __bt_opc_event_filter,
2911 if (subs_opp_client_interface_removed_id == -1) {
2912 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2913 NULL, BT_MANAGER_INTERFACE,
2914 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2915 __bt_opc_event_filter,
2918 if (subs_opp_client_property_id == -1) {
2919 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
2920 NULL, BT_PROPERTIES_INTERFACE,
2921 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2922 __bt_opc_event_filter,
2926 if (subs_opp_client_interface_added_id != -1) {
2927 g_dbus_connection_signal_unsubscribe(conn,
2928 subs_opp_client_interface_added_id);
2929 subs_opp_client_interface_added_id = -1;
2931 if (subs_opp_client_interface_removed_id != -1) {
2932 g_dbus_connection_signal_unsubscribe(conn,
2933 subs_opp_client_interface_removed_id);
2934 subs_opp_client_interface_removed_id = -1;
2936 if (subs_opp_client_property_id != -1) {
2937 g_dbus_connection_signal_unsubscribe(conn,
2938 subs_opp_client_property_id);
2939 subs_opp_client_property_id = -1;
2945 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
2951 static int subs_a2dp_source_id = -1;
2952 static int subs_a2dp_sink_id = -1;
2955 if (subs_a2dp_source_id == -1) {
2956 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
2957 NULL, BT_A2DP_SOURCE_INTERFACE,
2958 NULL, NULL, NULL, 0,
2959 __bt_opc_event_filter,
2962 if (subs_a2dp_sink_id == -1) {
2963 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
2964 NULL, BT_SINK_INTERFACE,
2965 NULL, NULL, NULL, 0,
2966 __bt_opc_event_filter,
2970 if (subs_a2dp_source_id != -1) {
2971 g_dbus_connection_signal_unsubscribe(conn,
2972 subs_a2dp_source_id);
2973 subs_a2dp_source_id = -1;
2975 if (subs_a2dp_sink_id != -1) {
2976 g_dbus_connection_signal_unsubscribe(conn,
2978 subs_a2dp_sink_id = -1;
2984 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
2988 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2990 switch (event_type) {
2991 case BT_MANAGER_EVENT:
2992 _bt_register_manager_subscribe_signal(g_conn, TRUE);
2994 case BT_DEVICE_EVENT:
2995 _bt_register_device_subscribe_signal(g_conn, TRUE);
2998 _bt_register_input_subscribe_signal(g_conn, TRUE);
3000 case BT_NETWORK_EVENT:
3001 _bt_register_network_subscribe_signal(g_conn, TRUE);
3003 case BT_HEADSET_EVENT:
3004 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3007 case BT_OPP_SERVER_EVENT:
3008 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3009 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3011 case BT_OPP_CLIENT_EVENT:
3012 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3013 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3015 case BT_A2DP_SOURCE_EVENT:
3016 BT_INFO("A2dp Source event");
3017 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3020 BT_ERR("Unknown event");
3021 return BLUETOOTH_ERROR_INTERNAL;
3024 return BLUETOOTH_ERROR_NONE;
3027 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3031 ret_if(g_conn == NULL);
3033 switch (event_type) {
3034 case BT_MANAGER_EVENT:
3035 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3036 _bt_register_device_subscribe_signal(g_conn, FALSE);
3037 _bt_register_input_subscribe_signal(g_conn, FALSE);
3038 _bt_register_network_subscribe_signal(g_conn, FALSE);
3039 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3041 case BT_OPP_SERVER_EVENT:
3042 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3044 case BT_OPP_CLIENT_EVENT:
3045 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3048 BT_ERR("Unknown event");
3055 static int __bt_init_manager_receiver(void)
3059 GError *error = NULL;
3061 if (manager_conn == NULL) {
3062 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3063 if (error != NULL) {
3064 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3065 g_clear_error(&error);
3067 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3070 if (_bt_register_service_event(manager_conn,
3071 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3073 if (_bt_register_service_event(manager_conn,
3074 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3077 if (_bt_register_service_event(manager_conn,
3078 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3081 if (_bt_register_service_event(manager_conn,
3082 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3085 if (_bt_register_service_event(manager_conn,
3086 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3088 return BLUETOOTH_ERROR_NONE;
3091 g_object_unref(manager_conn);
3092 manager_conn = NULL;
3097 return BLUETOOTH_ERROR_INTERNAL;
3100 static int __bt_init_obexd_receiver(void)
3104 GError *error = NULL;
3106 if (obexd_conn == NULL) {
3107 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3108 if (error != NULL) {
3109 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3110 g_clear_error(&error);
3112 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3115 if (_bt_register_service_event(obexd_conn,
3116 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3117 BT_ERR("Error while registering service event");
3118 g_object_unref(obexd_conn);
3120 return BLUETOOTH_ERROR_INTERNAL;
3125 return BLUETOOTH_ERROR_NONE;
3128 /* To receive the event from bluez */
3129 int _bt_init_service_event_receiver(void)
3135 result = __bt_init_manager_receiver();
3136 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3138 result = __bt_init_obexd_receiver();
3139 if (result != BLUETOOTH_ERROR_NONE)
3140 BT_ERR("Fail to init obexd receiver");
3144 return BLUETOOTH_ERROR_NONE;
3147 void _bt_deinit_service_event_receiver(void)
3151 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3153 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3156 g_object_unref(manager_conn);
3157 manager_conn = NULL;
3161 g_object_unref(obexd_conn);
3166 g_source_remove(event_id);