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) {
723 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
724 bt_state != VCONFKEY_BT_STATUS_OFF) {
725 _bt_disable_adapter();
727 #ifdef ENABLE_TIZEN_2_4
728 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
729 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
730 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
734 } else if (strcasecmp(property, "Connectable") == 0) {
735 gboolean connectable = FALSE;
737 g_variant_get(val, "b", &connectable);
739 BT_DBG("Connectable property is changed : %d", connectable);
740 param = g_variant_new("(b)", connectable);
741 _bt_send_event(BT_ADAPTER_EVENT,
742 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
744 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
745 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
747 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
748 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
751 GVariantIter *iter = NULL;
752 g_variant_get(val, "as", &iter);
753 while (g_variant_iter_loop(iter, "s", &name)) {
754 BT_DBG("name = %s", name);
755 g_variant_iter_loop(iter, "s", &value);
756 BT_DBG("Value = %s", value);
757 if (FALSE == _bt_update_le_feature_support(name, value))
758 BT_INFO("Fail to update LE feature info");
761 g_variant_iter_free(iter);
763 BT_DBG("property : [%s]", property);
768 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
772 GVariantIter value_iter;
773 GVariant *child = NULL, *val = NULL;
774 char *property = NULL;
775 g_variant_iter_init (&value_iter, msg);
776 while ((child = g_variant_iter_next_value (&value_iter))) {
777 g_variant_get(child, "{sv}", &property, &val);
779 ret_if(property == NULL);
781 BT_DBG("property :%s", property);
783 if (strcasecmp(property, "Status") == 0) {
785 g_variant_get(val, "s", &status);
787 if (strcasecmp(status, "active") == 0){
788 _bt_obex_transfer_started(path);
789 } else if (strcasecmp(status, "complete") == 0) {
790 _bt_obex_transfer_completed(path, TRUE);
791 _bt_pbap_obex_transfer_completed(path, TRUE);
792 } else if (strcasecmp(status, "error") == 0){
793 _bt_obex_transfer_completed(path, FALSE);
794 _bt_pbap_obex_transfer_completed(path, FALSE);
797 } else if (strcasecmp(property, "Transferred") == 0) {
798 static int transferred = 0;
799 g_variant_get(val, "t", &transferred);
801 _bt_obex_transfer_progress(path,transferred);
804 g_variant_unref(val);
805 g_variant_unref(child);
810 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
815 int result = BLUETOOTH_ERROR_NONE;
816 GVariantIter value_iter;
818 char *property = NULL;
820 GVariant *param = NULL;
821 bt_remote_dev_info_t *remote_dev_info;
822 g_variant_iter_init (&value_iter, msg);
823 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
824 BT_DBG("Property %s", property);
825 if (strcasecmp(property, "Connected") == 0) {
828 g_variant_get(val, "i", &connected);
830 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
831 BLUETOOTH_EVENT_DEVICE_CONNECTED :
832 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
834 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
836 _bt_convert_device_path_to_address(path, address);
838 BT_DBG("connected: %d", connected);
839 BT_DBG("address: %s", address);
841 remote_dev_info = _bt_get_remote_device_info(address);
843 if (remote_dev_info != NULL) {
844 __bt_device_remote_connected_properties(
845 remote_dev_info, address,
846 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
848 _bt_free_device_info(remote_dev_info);
850 param = g_variant_new("(is)", result, address);
851 /* Send event to application */
852 _bt_send_event(BT_DEVICE_EVENT,
856 } else if (strcasecmp(property, "RSSI") == 0) {
857 bt_remote_dev_info_t *remote_dev_info;
859 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
861 _bt_convert_device_path_to_address(path, address);
862 BT_DBG("address: %s", address);
864 remote_dev_info = _bt_get_remote_device_info(address);
865 if (remote_dev_info == NULL) {
867 g_variant_unref(val);
871 BT_DBG("Address type %d", remote_dev_info->addr_type);
873 if (remote_dev_info && remote_dev_info->addr_type == 0) {
874 BT_DBG("Name %s", remote_dev_info->name);
876 GVariant *uuids = NULL;
877 GVariantBuilder *builder = NULL;
879 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
880 for (i=0; i < remote_dev_info->uuid_count; i++) {
881 g_variant_builder_add(builder, "s",
882 remote_dev_info->uuids[i]);
884 uuids = g_variant_new("as", builder);
885 g_variant_builder_unref(builder);
886 GVariant *manufacturer_data = NULL;
887 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
888 remote_dev_info->manufacturer_data,
889 remote_dev_info->manufacturer_data_len,
892 param = g_variant_new("(isunsbub@asn@ay)", result,
893 remote_dev_info->address,
894 remote_dev_info->class,
895 remote_dev_info->rssi,
896 remote_dev_info->name,
897 remote_dev_info->paired,
898 remote_dev_info->connected,
899 remote_dev_info->trust,
901 remote_dev_info->manufacturer_data_len,
904 _bt_send_event(BT_ADAPTER_EVENT,
905 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
909 _bt_free_device_info(remote_dev_info);
910 } else if (strcasecmp(property, "GattConnected") == 0) {
911 gboolean gatt_connected = FALSE;
913 g_variant_get(val, "b", &gatt_connected);
915 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
916 BLUETOOTH_EVENT_GATT_DISCONNECTED;
918 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
920 _bt_convert_device_path_to_address(path, address);
922 BT_DBG("gatt_connected: %d", gatt_connected);
923 BT_DBG("address: %s", address);
924 param = g_variant_new("(is)", result, address);
925 /* Send event to application */
926 _bt_send_event(BT_DEVICE_EVENT,
930 } else if (strcasecmp(property, "Paired") == 0) {
931 gboolean paired = FALSE;
932 bt_remote_dev_info_t *remote_dev_info;
933 g_variant_get(val, "b", &paired);
934 _bt_agent_set_canceled(FALSE);
935 /* BlueZ sends paired signal for each paired device */
936 /* during activation, We should ignore this, otherwise*/
937 /* application thinks that a new device got paired */
938 if (_bt_adapter_get_status() != BT_ACTIVATED) {
939 BT_DBG("BT is not activated, so ignore this");
941 g_variant_unref(val);
945 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
947 _bt_convert_device_path_to_address(path, address);
949 remote_dev_info = _bt_get_remote_device_info(address);
950 if (remote_dev_info == NULL) {
952 g_variant_unref(val);
957 if(paired == FALSE) {
958 BT_INFO("Unpaired: %s", address);
959 __bt_update_remote_cache_devinfo(address, FALSE);
960 param = g_variant_new("(is)", result, address);
961 _bt_send_event(BT_ADAPTER_EVENT,
962 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
965 BT_INFO("Paired: %s", address);
966 __bt_update_remote_cache_devinfo(address, TRUE);
968 if (_bt_is_device_creating() == TRUE) {
969 BT_DBG("Try to Pair by me");
970 _bt_free_device_info(remote_dev_info);
973 g_variant_unref(val);
976 GVariant *uuids = NULL;
977 GVariantBuilder *builder = NULL;
979 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
980 for (i=0; i < remote_dev_info->uuid_count; i++) {
981 g_variant_builder_add(builder, "s",
982 remote_dev_info->uuids[i]);
984 uuids = g_variant_new("as", builder);
985 g_variant_builder_unref(builder);
986 GVariant *manufacturer_data = NULL;
987 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
988 remote_dev_info->manufacturer_data,
989 remote_dev_info->manufacturer_data_len,
993 param = g_variant_new("(isunsbub@asn@ay)", result,
994 address, remote_dev_info->class,
995 remote_dev_info->rssi,
996 remote_dev_info->name,
997 remote_dev_info->paired,
998 remote_dev_info->connected,
999 remote_dev_info->trust,
1001 remote_dev_info->manufacturer_data_len,
1003 _bt_send_event(BT_ADAPTER_EVENT,
1004 BLUETOOTH_EVENT_BONDING_FINISHED,
1007 _bt_free_device_info(remote_dev_info);
1009 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1010 gboolean paired = FALSE;
1011 bt_remote_dev_info_t *remote_dev_info;
1013 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1014 BT_DBG("BT is not activated, so ignore this");
1016 g_variant_unref(val);
1020 g_variant_get(val, "b", &paired);
1021 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1022 BT_DBG("LegacyPaired: %d", paired);
1023 _bt_convert_device_path_to_address(path, address);
1025 remote_dev_info = _bt_get_remote_device_info(address);
1026 if (remote_dev_info == NULL) {
1029 g_variant_unref(val);
1033 BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
1034 remote_dev_info->name);
1035 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1036 remote_dev_info->name, NULL, NULL, NULL);
1038 _bt_free_device_info(remote_dev_info);
1040 } else if (strcasecmp(property, "Trusted") == 0) {
1041 gboolean trusted = FALSE;
1043 g_variant_get(val, "b", &trusted);
1045 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1046 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1048 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1050 _bt_convert_device_path_to_address(path, address);
1052 BT_DBG("trusted: %d", trusted);
1053 BT_DBG("address: %s", address);
1054 param = g_variant_new("(is)", result, address);
1055 /* Send event to application */
1056 _bt_send_event(BT_DEVICE_EVENT,
1065 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1068 int result = BLUETOOTH_ERROR_NONE;
1069 GVariantIter value_iter;
1070 char *property = NULL;
1072 GVariant *val = NULL;
1073 GVariant *child = NULL;
1074 bt_remote_dev_info_t *remote_dev_info;
1075 GVariant *param = NULL;
1076 g_variant_iter_init (&value_iter, msg);
1077 while ((child = g_variant_iter_next_value (&value_iter))) {
1078 g_variant_get(child, "{sv}", &property, &val);
1079 BT_INFO("Property %s", property);
1080 if (strcasecmp(property, "Connected") == 0) {
1081 gboolean connected = FALSE;
1083 g_variant_get(val, "b", &connected);
1085 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1086 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1088 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1090 _bt_convert_device_path_to_address(path, address);
1092 BT_DBG("connected: %d", connected);
1093 BT_DBG("address: %s", address);
1095 remote_dev_info = _bt_get_remote_device_info(address);
1097 if (remote_dev_info != NULL) {
1098 __bt_device_remote_connected_properties(
1099 remote_dev_info, address, connected);
1100 _bt_free_device_info(remote_dev_info);
1102 param = g_variant_new("(is)", result, address);
1103 /* Send event to application */
1104 _bt_send_event(BT_AVRCP_EVENT,
1110 g_variant_unref(child);
1111 g_variant_unref(val);
1116 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1118 char *interface_name = NULL;
1119 GVariant *val = NULL;
1121 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val,NULL);
1123 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1124 __bt_adapter_property_changed_event(val,
1126 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1127 __bt_device_property_changed_event(val,object_path);
1128 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1129 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1130 __bt_obex_property_changed_event(val,
1132 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1133 __bt_media_control_changed_event(val,
1135 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1136 _bt_handle_avrcp_control_event(val,
1138 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1139 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1140 _bt_handle_network_client_event(val,
1142 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1143 __bt_gatt_char_property_changed_event(val,
1146 g_variant_unref(val);
1149 void __bt_opc_property_changed_event(GVariant *msg,
1152 GVariantIter value_iter;
1153 char *property = NULL;
1154 GVariant *val = NULL;
1155 GVariant *child = NULL;
1157 g_variant_iter_init (&value_iter, msg);
1158 while ((child = g_variant_iter_next_value (&value_iter))) {
1159 g_variant_get(child, "{sv}", &property, &val);
1160 ret_if(property == NULL);
1162 if (strcasecmp(property, "Status") == 0) {
1163 char *status = NULL;
1164 g_variant_get(val, "s", &status);
1165 BT_DBG("Status is %s", status);
1167 if(strcasecmp(status, "active") == 0){
1168 _bt_obex_client_started(path);
1169 }else if (strcasecmp(status, "complete") == 0) {
1170 _bt_obex_client_completed(path, TRUE);
1171 }else if (strcasecmp(status, "error") == 0){
1172 _bt_obex_client_completed(path, FALSE);
1175 } else if (strcasecmp(property, "Transferred") == 0) {
1176 static int transferred = 0;
1177 g_variant_get(val, "t", &transferred);
1179 _bt_obex_client_progress(path, transferred);
1181 BT_DBG("property : [%s]", property);
1184 g_variant_unref(child);
1185 g_variant_unref(val);
1189 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1191 char *interface_name = NULL;
1192 GVariant *value = NULL;
1193 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1194 BT_INFO("interface_name = %s", interface_name);
1195 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1196 __bt_opc_property_changed_event(value,
1199 BT_DBG("interface_name : [%s]", interface_name);
1201 g_variant_unref(value);
1205 void _bt_handle_input_event(GVariant *msg, const char *path)
1207 int result = BLUETOOTH_ERROR_NONE;
1208 gboolean property_flag = FALSE;
1209 GVariantIter value_iter;
1210 char *property = NULL;
1211 GVariant *child = NULL, *val = NULL;
1212 bt_remote_dev_info_t *remote_dev_info;
1213 GVariant *param = NULL;
1214 g_variant_iter_init (&value_iter, msg);
1215 while ((child = g_variant_iter_next_value (&value_iter))) {
1216 g_variant_get(child, "{sv}", &property, &val);
1218 ret_if(property == NULL);
1220 if (strcasecmp(property, "Connected") == 0) {
1221 int event = BLUETOOTH_EVENT_NONE;
1223 g_variant_get(val, "b", &property_flag);
1225 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1227 _bt_convert_device_path_to_address(path, address);
1229 event = (property_flag == TRUE) ?
1230 BLUETOOTH_HID_CONNECTED :
1231 BLUETOOTH_HID_DISCONNECTED;
1232 param = g_variant_new("(is)", result, address);
1233 _bt_send_event(BT_HID_EVENT, event,
1235 /* Check HID connection type (Keyboard or Mouse) and update the status */
1236 remote_dev_info = _bt_get_remote_device_info(address);
1238 if (property_flag == TRUE) {
1239 hid_connected_device_count++;
1240 __bt_set_device_values(TRUE,
1241 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1243 hid_connected_device_count--;
1244 if (hid_connected_device_count == 0)
1245 __bt_set_device_values(FALSE,
1246 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1249 if (remote_dev_info != NULL) {
1250 BT_DBG("HID device class [%x]", remote_dev_info->class);
1251 if (remote_dev_info->class &
1252 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1253 #ifdef ENABLE_TIZEN_2_4
1254 __bt_set_device_values(property_flag,
1255 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1260 if (remote_dev_info->class &
1261 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1262 #ifdef ENABLE_TIZEN_2_4
1263 __bt_set_device_values(property_flag,
1264 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1267 _bt_free_device_info(remote_dev_info);
1272 g_variant_unref(val);
1273 g_variant_unref(child);
1277 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1279 int result = BLUETOOTH_ERROR_NONE;
1280 char *address = NULL;
1281 char *device = NULL;
1282 GVariant *param = NULL;
1283 ret_if(member == NULL);
1284 if (strcasecmp(member, "PeerConnected") == 0) {
1285 g_variant_get(msg, "(ss)", &device, &address);
1287 __bt_set_device_values(TRUE,
1288 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1289 param = g_variant_new("(iss)", result, device, address);
1290 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1294 nap_connected_device_count++;
1295 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1296 g_variant_get(msg, "(ss)", &device, &address);
1297 nap_connected_device_count--;
1298 if (nap_connected_device_count == 0)
1299 __bt_set_device_values(FALSE,
1300 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1301 param = g_variant_new("(iss)", result, device, address);
1302 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1309 void _bt_handle_network_client_event(GVariant *msg,
1314 int result = BLUETOOTH_ERROR_NONE;
1315 gboolean property_flag = FALSE;
1316 char *property = NULL;
1317 GVariant *val = NULL;
1318 GVariantIter value_iter;
1319 GVariant *param = NULL;
1320 g_variant_iter_init (&value_iter, msg);
1321 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1322 if (strcasecmp(property, "Connected") == 0) {
1323 int event = BLUETOOTH_EVENT_NONE;
1326 g_variant_get(val, "b", &property_flag);
1327 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1329 _bt_convert_device_path_to_address(path, address);
1331 BT_DBG("property_flag %d", property_flag);
1332 if (property_flag == TRUE) {
1333 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1334 nap_connected_device_count++;
1335 __bt_set_device_values(TRUE,
1336 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1338 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1339 nap_connected_device_count--;
1340 if (nap_connected_device_count == 0)
1341 __bt_set_device_values(FALSE,
1342 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1344 param = g_variant_new("(is)", result, address);
1345 _bt_send_event(BT_NETWORK_EVENT, event,
1354 void __bt_gatt_char_property_changed_event(GVariant *msg,
1357 GVariantIter value_iter;
1358 char *property = NULL;
1359 char * char_handle = NULL;
1360 GVariant *val = NULL;
1361 int result = BLUETOOTH_ERROR_NONE;
1362 GVariant *param = NULL;
1363 g_variant_iter_init (&value_iter, msg);
1364 char_handle = g_strdup(path);
1365 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1366 BT_INFO("Property %s", property);
1368 ret_if(property == NULL);
1370 if (strcasecmp(property, "Notifying") == 0) {
1371 gboolean property_flag = FALSE;
1372 g_variant_get(val, "b", &property_flag);
1373 if (property_flag == TRUE)
1374 BT_DBG("notifying is enabled");
1376 BT_DBG("notifying is disabled");
1377 } else if (strcasecmp(property, "ChangedValue") == 0) {
1379 GByteArray *gp_byte_array = NULL;
1380 BT_INFO("Type '%s'\n", g_variant_get_type_string (val));
1383 gp_byte_array = g_byte_array_new();
1384 len = g_variant_get_size(val);
1385 BT_DBG("Len = %d", len);
1386 g_byte_array_append (gp_byte_array,
1387 (const guint8 *) g_variant_get_data(val), len);
1388 if (gp_byte_array->len != 0) {
1389 GVariant *byte_array = NULL;
1390 byte_array = g_variant_new_from_data(
1391 G_VARIANT_TYPE_BYTESTRING,
1392 gp_byte_array->data,
1395 param = g_variant_new("(is@ay)", result, char_handle,
1397 _bt_send_event(BT_DEVICE_EVENT,
1398 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
1401 g_byte_array_free(gp_byte_array, TRUE);
1405 g_free(char_handle);
1407 void _bt_handle_device_event(GVariant *msg, const char *member,const char *path)
1410 int result = BLUETOOTH_ERROR_NONE;
1413 const char *property = NULL;
1414 GVariant *param = NULL;
1415 ret_if(path == NULL);
1417 if (strcasecmp(member, "PropertyChanged") == 0) {
1419 g_variant_get(msg, "(s)", &property);
1421 ret_if(property == NULL);
1423 if (strcasecmp(property, "GattConnected") == 0) {
1424 gboolean connected = FALSE;
1426 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1427 _bt_convert_device_path_to_address(path, address);
1428 g_variant_get(msg, "(b)", &connected);
1430 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1431 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1432 param = g_variant_new("(is)", result, address);
1433 _bt_send_event(BT_DEVICE_EVENT,
1437 } else if (strcasecmp(property, "Paired") == 0) {
1438 gboolean paired = FALSE;
1439 bt_remote_dev_info_t *remote_dev_info;
1440 g_variant_get(msg, "(b)", &paired);
1442 ret_if(paired == FALSE);
1444 /* BlueZ sends paired signal for each paired device */
1445 /* during activation, We should ignore this, otherwise*/
1446 /* application thinks that a new device got paired */
1447 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1448 BT_DBG("BT is not activated, so ignore this");
1452 if (_bt_is_device_creating() == TRUE) {
1453 BT_DBG("Try to Pair by me");
1457 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1459 _bt_convert_device_path_to_address(path, address);
1461 remote_dev_info = _bt_get_remote_device_info(address);
1462 if (remote_dev_info == NULL) {
1466 GVariant *uuids = NULL;
1467 GVariantBuilder *builder = NULL;
1469 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1470 for (i=0; i < remote_dev_info->uuid_count; i++) {
1471 g_variant_builder_add(builder, "s",
1472 remote_dev_info->uuids[i]);
1474 uuids = g_variant_new("as", builder);
1475 g_variant_builder_unref(builder);
1476 GVariant *manufacturer_data = NULL;
1477 manufacturer_data = g_variant_new_from_data(
1478 G_VARIANT_TYPE_BYTESTRING,
1479 remote_dev_info->manufacturer_data,
1480 remote_dev_info->manufacturer_data_len,
1482 param = g_variant_new("(isunsbub@asn@ay)", result,
1484 remote_dev_info->class,
1485 remote_dev_info->rssi,
1486 remote_dev_info->name,
1487 remote_dev_info->paired,
1488 remote_dev_info->connected,
1489 remote_dev_info->trust,
1491 remote_dev_info->manufacturer_data_len,
1493 _bt_send_event(BT_ADAPTER_EVENT,
1494 BLUETOOTH_EVENT_BONDING_FINISHED,
1496 _bt_free_device_info(remote_dev_info);
1499 } else if (strcasecmp(property, "UUIDs") == 0) {
1500 /* Once we get the updated uuid information after
1501 * reverse service search, update it to application */
1503 bt_remote_dev_info_t *remote_dev_info;
1505 ret_if(_bt_is_device_creating() == TRUE);
1507 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1509 _bt_convert_device_path_to_address(path, address);
1511 remote_dev_info = _bt_get_remote_device_info(address);
1512 if (remote_dev_info == NULL) {
1517 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1518 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1519 GVariant *uuids = NULL;
1520 GVariantBuilder *builder = NULL;
1522 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1523 for (i=0; i < remote_dev_info->uuid_count; i++) {
1524 g_variant_builder_add(builder, "s",
1525 remote_dev_info->uuids[i]);
1527 uuids = g_variant_new("as", builder);
1528 g_variant_builder_unref(builder);
1529 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1530 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1533 param = g_variant_new("(isunsbub@asn@ay)", result,
1534 address, remote_dev_info->class,
1535 remote_dev_info->rssi,
1536 remote_dev_info->name,
1537 remote_dev_info->paired,
1538 remote_dev_info->connected,
1539 remote_dev_info->trust,
1541 remote_dev_info->manufacturer_data_len,
1543 _bt_send_event(BT_ADAPTER_EVENT,
1544 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1548 _bt_free_device_info(remote_dev_info);
1551 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1552 unsigned char addr_type = 0;
1554 g_variant_get(msg, "(y)", &addr_type);
1556 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1558 _bt_convert_device_path_to_address(path, address);
1559 dev_name = _bt_get_bonded_device_name(address);
1561 BT_INFO("Address : %s Type : %d", address, addr_type);
1562 BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1563 !addr_type ? dev_name : address);
1566 _bt_logging_connection(TRUE, addr_type);
1567 #ifdef ENABLE_TIZEN_2_4
1568 journal_bt_connected();
1570 param = g_variant_new("(isy)", result, address, addr_type);
1571 /*Send event to application*/
1572 _bt_send_event(BT_DEVICE_EVENT,
1573 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1576 } else if (strcasecmp(member, "Disconnected") == 0) {
1577 unsigned char disc_reason = 0;
1578 unsigned char addr_type = 0;
1579 gboolean sending = FALSE;
1581 g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
1583 result = disc_reason;
1585 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1587 _bt_convert_device_path_to_address(path, address);
1588 dev_name = _bt_get_bonded_device_name(address);
1589 #ifdef ENABLE_TIZEN_2_4
1590 journal_bt_disconnected();
1593 /* 0x00 BDADDR_BRDER
1594 0x01 BDADDR_LE_PUBLIC
1595 0x02 BDADDR_LE_RANDOM */
1596 BT_INFO("Address : %s Type : %d", address, addr_type);
1597 BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1598 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1599 !addr_type ? dev_name : address);
1602 _bt_headset_set_local_connection(FALSE);
1603 _bt_logging_connection(FALSE, addr_type);
1605 /*Check for any OPP transfer on the device and cancel
1608 _bt_obex_check_pending_transfer(address);
1609 _bt_opp_client_is_sending(&sending);
1611 _bt_opp_client_check_pending_transfer(address);
1612 param = g_variant_new("(isy)", result, address, addr_type);
1613 _bt_send_event(BT_DEVICE_EVENT,
1614 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1617 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1619 char *profile_uuid = NULL;
1620 bt_headset_wait_t *wait_list;
1622 g_variant_get(msg, "(si)", &profile_uuid, &state);
1624 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1626 _bt_convert_device_path_to_address(path, address);
1628 BT_DBG("Address: %s", address);
1629 BT_DBG("Profile UUID: %s", profile_uuid);
1630 BT_DBG("State: %d", state);
1632 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1633 (state == BT_PROFILE_STATE_CONNECTED)) {
1635 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1636 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1637 bluetooth_device_address_t device_address;
1639 bt_headset_wait_t *wait_list;
1641 __bt_set_device_values(TRUE,
1642 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1644 __bt_connection_manager_set_state(address, event);
1646 if (_bt_headset_get_local_connection() == FALSE)
1647 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1649 /* Connection Started from local device therefore no need to
1650 * intiate connection for pending profile */
1651 _bt_headset_set_local_connection(FALSE);
1653 param = g_variant_new("(is)", result, address);
1654 _bt_send_event(BT_HEADSET_EVENT, event,
1656 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1659 if (g_strcmp0(connected_address, address) != 0) {
1660 _bt_convert_addr_string_to_type(
1661 device_address.addr,
1663 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1664 &device_address, NULL);
1668 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1669 BT_STATE_CONNECTED, address);
1671 wait_list = _bt_get_audio_wait_data();
1672 if (wait_list != NULL &&
1673 (g_strcmp0(wait_list->address, address) == 0))
1674 _bt_rel_wait_data();
1676 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1677 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1679 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1681 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1683 g_free(profile_uuid);
1687 __bt_set_device_values(FALSE,
1688 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1690 __bt_connection_manager_set_state(address, event);
1691 param = g_variant_new("(is)", result, address);
1692 _bt_send_event(BT_HEADSET_EVENT, event,
1694 /* Remove data from the connected list */
1695 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1696 wait_list = _bt_get_audio_wait_data();
1698 if (wait_list == NULL) {
1700 g_free(profile_uuid);
1704 if (((wait_list->type == BT_AUDIO_ALL) &&
1705 (wait_list->ag_flag == TRUE)) ||
1706 (wait_list->type == BT_AUDIO_A2DP) ||
1707 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1708 bluetooth_device_address_t device_address;
1709 _bt_convert_addr_string_to_type(
1710 device_address.addr,
1711 wait_list->address);
1713 _bt_audio_connect(wait_list->req_id,
1716 wait_list->out_param1);
1718 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1720 if (state == BT_PROFILE_STATE_CONNECTED) {
1721 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1722 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1723 bluetooth_device_address_t device_address;
1725 param = g_variant_new("(is)", result, address);
1726 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1728 connected = _bt_is_headset_type_connected(
1732 if (g_strcmp0(connected_address,
1734 _bt_convert_addr_string_to_type(
1735 device_address.addr,
1737 _bt_audio_disconnect(0,
1739 &device_address, NULL);
1742 BT_DBG("device Path: %s", path);
1743 _bt_add_headset_to_list(BT_AVRCP,
1744 BT_STATE_CONNECTED, address);
1745 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1746 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1747 param = g_variant_new("(is)", result, address);
1748 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1750 /* Remove data from the connected list */
1751 _bt_remove_headset_from_list(BT_AVRCP, address);
1753 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1754 if (state == BT_PROFILE_STATE_CONNECTED) {
1755 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1756 BT_INFO("A2DP Source is connected");
1757 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1758 g_variant_new("(is)", result, address));
1759 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1760 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
1761 BT_INFO("A2DP Source Disconnected");
1762 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1763 g_variant_new("(is)", result, address));
1765 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
1766 ((state == BT_PROFILE_STATE_CONNECTED) ||
1767 (state == BT_PROFILE_STATE_DISCONNECTED))) {
1769 if (state == BT_PROFILE_STATE_CONNECTED)
1770 event = BLUETOOTH_HID_CONNECTED;
1772 event = BLUETOOTH_HID_DISCONNECTED;
1773 param = g_variant_new("(is)", result, address);
1774 _bt_send_event(BT_HID_EVENT, event,
1777 if (state == BT_PROFILE_STATE_CONNECTED)
1778 __bt_set_device_values(TRUE,
1779 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1781 __bt_set_device_values(FALSE,
1782 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1785 g_free(profile_uuid);
1786 } else if (strcasecmp(member, "AdvReport") == 0) {
1788 bt_remote_le_dev_info_t *le_dev_info = NULL;
1789 char *buffer = NULL;
1791 bt_le_adv_info_t *adv_info = NULL;
1792 GVariant *value = NULL;
1793 ret_if(_bt_is_le_scanning() == FALSE);
1795 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
1797 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
1798 &le_dev_info->addr_type,
1799 &le_dev_info->adv_type,
1801 &le_dev_info->adv_data_len,
1803 buffer_len = g_variant_get_size(value);
1805 buffer = (char *)g_variant_get_data(value);
1807 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
1809 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1810 _bt_send_scan_result_event(le_dev_info, NULL);
1811 _bt_free_le_device_info(le_dev_info);
1812 g_variant_unref(value);
1816 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
1817 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
1818 adv_info->addr = g_strdup(le_dev_info->address);
1819 adv_info->data_len = le_dev_info->adv_data_len;
1820 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
1821 memcpy(adv_info->data, le_dev_info->adv_data,
1822 le_dev_info->adv_data_len);
1824 __bt_add_adv_ind_info(adv_info);
1826 } else { /* SCAN_RSP */
1827 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
1829 _bt_send_scan_result_event(le_dev_info, adv_info);
1830 __bt_del_adv_ind_info(le_dev_info->address);
1833 _bt_free_le_device_info(le_dev_info);
1834 g_variant_unref(value);
1839 void __bt_set_audio_values(gboolean connected, char *address)
1842 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1844 /* Set the headset name */
1845 if (connected == TRUE) {
1846 name = _bt_get_bonded_device_name(address);
1848 name = g_strdup("");
1851 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
1853 BT_ERR("vconf_set_str failed");
1858 /* Set the headset state */
1859 if (vconf_get_int(VCONFKEY_BT_DEVICE,
1860 &bt_device_state) != 0) {
1861 BT_ERR("vconf_get_str failed");
1864 #ifdef TIZEN_SUPPORT_DUAL_HF
1865 if ((connected == TRUE) &&
1866 (FALSE == __bt_is_companion_device(address))) {
1867 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1868 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
1869 (FALSE == __bt_is_companion_device(address))) {
1870 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1873 if (connected == TRUE) {
1874 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1875 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
1876 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1880 if (vconf_set_int(VCONFKEY_BT_DEVICE,
1881 bt_device_state) != 0) {
1882 BT_ERR("vconf_set_int failed");
1886 void _bt_handle_headset_event(GVariant *msg, const char *path)
1888 int result = BLUETOOTH_ERROR_NONE;
1889 gboolean property_flag = FALSE;
1890 char *property = NULL;
1891 GVariant *value = NULL;
1892 GVariant *param = NULL;
1893 g_variant_get(msg, "(sv)", &property, &value);
1895 ret_if(property == NULL);
1897 BT_DBG("Property = %s \n", property);
1898 /* We allow only 1 headset connection (HSP or HFP)*/
1899 if (strcasecmp(property, "Connected") == 0) {
1900 int event = BLUETOOTH_EVENT_NONE;
1901 bt_headset_wait_t *wait_list;
1903 g_variant_get(value, "b", &property_flag);
1905 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1907 /* Fix : NULL_RETURNS */
1908 if (address == NULL)
1911 _bt_convert_device_path_to_address(path, address);
1913 if (property_flag == TRUE) {
1914 event = BLUETOOTH_EVENT_AG_CONNECTED;
1915 if (_bt_headset_get_local_connection() == FALSE)
1916 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
1918 _bt_headset_set_local_connection(FALSE);
1922 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
1924 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
1925 if (previous_state == BT_STATE_DISCONNECTING)
1926 _bt_send_hf_local_term_event(address);
1928 /* Set the State machine here */
1929 __bt_connection_manager_set_state(address, event);
1930 __bt_set_audio_values(property_flag, address);
1931 param = g_variant_new("(is)", result, address);
1932 _bt_send_event(BT_HEADSET_EVENT, event,
1935 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
1936 /* Remove data from the connected list */
1937 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
1939 wait_list = _bt_get_audio_wait_data();
1940 if (wait_list == NULL) {
1945 bluetooth_device_address_t device_address;
1947 _bt_set_audio_wait_data_flag(TRUE);
1949 _bt_convert_addr_string_to_type(device_address.addr,
1950 wait_list->address);
1951 _bt_audio_connect(wait_list->req_id, wait_list->type,
1952 &device_address, wait_list->out_param1);
1953 _bt_rel_wait_data();
1954 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
1955 /* Add data to the connected list */
1956 _bt_add_headset_to_list(BT_AUDIO_HSP,
1957 BT_STATE_CONNECTED, address);
1959 wait_list = _bt_get_audio_wait_data();
1960 if (wait_list != NULL &&
1961 (g_strcmp0(wait_list->address, address) == 0))
1962 _bt_rel_wait_data();
1964 BT_INFO("Check A2DP pending connect");
1965 _bt_audio_check_pending_connect();
1968 } else if (strcasecmp(property, "State") == 0) {
1971 g_variant_get(value, "s", &state);
1973 /* This code assumes we support only 1 headset connection */
1974 /* Need to use the headset list, if we support multi-headsets */
1975 if (strcasecmp(state, "Playing") == 0) {
1976 BT_DBG("Playing: Sco Connected");
1977 } else if (strcasecmp(state, "connected") == 0 ||
1978 strcasecmp(state, "disconnected") == 0) {
1979 BT_DBG("connected/disconnected: Sco Disconnected");
1981 BT_ERR("Not handled state - %s", state);
1986 } else if (strcasecmp(property, "SpeakerGain") == 0) {
1990 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1992 _bt_convert_device_path_to_address(path, address);
1994 g_variant_get(value, "i", &spkr_gain);
1995 param = g_variant_new("(isq)", result, address, spkr_gain);
1996 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2000 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2004 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2006 _bt_convert_device_path_to_address(path, address);
2008 g_variant_get(value, "i", &mic_gain);
2009 param = g_variant_new("(isq)", result, address, mic_gain);
2010 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2017 g_variant_unref(value);
2020 void _bt_handle_sink_event(GVariant *msg, const char *path)
2022 GVariantIter value_iter;
2023 char *property = NULL;
2025 bt_headset_wait_t *wait_list;
2027 GVariant *child = NULL;
2028 GVariant *val = NULL;
2029 GVariant *param = NULL;
2030 g_variant_iter_init (&value_iter, msg);
2031 while ((child = g_variant_iter_next_value (&value_iter))) {
2033 g_variant_get(child, "{sv}", &property, &val);
2035 ret_if(property == NULL);
2037 BT_DBG("Property = %s \n", property);
2040 if (strcasecmp(property, "State") == 0) {
2041 int result = BLUETOOTH_ERROR_NONE;
2044 g_variant_get(val, "s", &value);
2045 BT_DBG("value: %s", value);
2047 if (g_strcmp0(value, "disconnected") == 0) {
2050 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2052 _bt_convert_device_path_to_address(path, address);
2054 __bt_set_device_values(FALSE,
2055 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2056 param = g_variant_new("(is)", result, address);
2057 _bt_send_event(BT_HEADSET_EVENT,
2058 BLUETOOTH_EVENT_AV_DISCONNECTED,
2061 /* Remove data from the connected list */
2062 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2063 wait_list = _bt_get_audio_wait_data();
2064 if (wait_list == NULL) {
2067 g_variant_unref(val);
2068 g_variant_unref(child);
2073 if (((wait_list->type == BT_AUDIO_ALL) &&
2074 (wait_list->ag_flag == TRUE)) ||
2075 (wait_list->type == BT_AUDIO_A2DP) ||
2076 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2077 bluetooth_device_address_t device_address;
2078 _bt_convert_addr_string_to_type(
2079 device_address.addr,
2080 wait_list->address);
2082 _bt_audio_connect(wait_list->req_id,
2085 wait_list->out_param1);
2088 }else if (strcasecmp(value, "Connected") == 0) {
2090 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2091 bluetooth_device_address_t device_address;
2094 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2096 _bt_convert_device_path_to_address(path, address);
2098 __bt_set_device_values(TRUE,
2099 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2100 param = g_variant_new("(is)", result, address);
2101 _bt_send_event(BT_HEADSET_EVENT,
2102 BLUETOOTH_EVENT_AV_CONNECTED,
2104 /* Check for existing Media device to disconnect */
2105 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2108 /* Match connected device address */
2109 if (g_strcmp0(connected_address, address) != 0) {
2110 /* Convert BD adress from string type */
2111 _bt_convert_addr_string_to_type(
2112 device_address.addr,
2114 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2115 &device_address, NULL);
2119 /* Add data to the connected list */
2120 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2121 BT_STATE_CONNECTED, address);
2128 g_variant_unref(val);
2129 g_variant_unref(child);
2133 void _bt_handle_agent_event(GVariant *msg, const char *member)
2135 int result = BLUETOOTH_ERROR_NONE;
2136 char *address = NULL;
2139 GVariant *param = NULL;
2140 ret_if(member == NULL);
2142 if (strcasecmp(member, "ObexAuthorize") == 0) {
2143 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2144 param = g_variant_new("(iss)", result, address, name);
2145 _bt_send_event(BT_OPP_SERVER_EVENT,
2146 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2150 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2151 bt_rfcomm_server_info_t *server_info;
2153 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2155 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2156 ret_if(server_info == NULL);
2157 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2158 param = g_variant_new("(isssn)", result, address, uuid, name,
2159 server_info->control_fd);
2160 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2161 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2169 static int __bt_get_object_path(GVariant *msg, char **path)
2171 g_variant_get(msg, "(o*)", path, NULL);
2173 return BLUETOOTH_ERROR_INTERNAL;
2175 return BLUETOOTH_ERROR_NONE;
2178 static void __bt_devices_list_free(void)
2180 bt_cache_info_t *cache_info;
2183 node = g_list_first(p_cache_list);
2185 while (node != NULL){
2186 cache_info = (bt_cache_info_t *)node->data;
2187 p_cache_list = g_list_remove(p_cache_list, cache_info);
2188 __bt_free_cache_info(cache_info);
2190 node = g_list_next(node);
2194 static int __bt_parse_event(GVariant *msg)
2198 char *interface_name= NULL;
2199 GVariant *inner_iter = NULL;
2201 g_variant_iter_init(&iter, msg);
2203 while ((child = g_variant_iter_next_value(&iter))) {
2204 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
2205 if (g_strcmp0(interface_name,
2206 BT_DEVICE_INTERFACE) == 0) {
2207 g_variant_unref(inner_iter);
2208 g_variant_unref(child);
2209 return BT_DEVICE_EVENT;
2210 } else if (g_strcmp0(interface_name,
2211 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2212 g_variant_unref(inner_iter);
2213 g_variant_unref(child);
2214 return BT_MEDIA_TRANSFER_EVENT;
2215 } else if (g_strcmp0(interface_name,
2216 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2217 g_variant_unref(inner_iter);
2218 g_variant_unref(child);
2219 return BT_AVRCP_CONTROL_EVENT;
2221 g_variant_unref(inner_iter);
2222 g_variant_unref(child);
2228 static void __bt_manager_event_filter(GDBusConnection *connection,
2229 const gchar *sender_name,
2230 const gchar *object_path,
2231 const gchar *interface_name,
2232 const gchar *signal_name,
2233 GVariant *parameters,
2236 bt_event_type_t bt_event = 0x00;
2237 int result = BLUETOOTH_ERROR_NONE;
2239 char *obj_path = NULL;
2240 GVariant *param = NULL;
2241 if (signal_name == NULL)
2243 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2244 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2246 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0)
2247 _bt_handle_adapter_added();
2249 bt_event = __bt_parse_event(value);
2250 if (bt_event == BT_DEVICE_EVENT) {
2251 bt_cache_info_t *cache_info;
2252 bt_remote_dev_info_t *dev_info;
2254 ret_if(_bt_is_discovering() == FALSE &&
2255 _bt_is_le_scanning() == FALSE);
2257 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2258 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2259 cache_info->dev_info = dev_info;
2261 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2262 BT_ERR("Fail to parse the properies");
2263 __bt_free_cache_info(cache_info);
2264 g_variant_unref(value);
2268 if (dev_info->addr_type != BDADDR_BREDR) {
2269 /* Whenever emit the property changed from bluez,
2270 some property doesn't reach to bt-service.
2271 So LE device is handled as AdvReport signal */
2272 __bt_free_cache_info(cache_info);
2273 g_variant_unref(value);
2277 if (dev_info->name == NULL)
2278 /* If Remote device name is NULL or still RNR is not done
2279 * then display address as name.
2281 dev_info->name = g_strdup(dev_info->address);
2283 GVariant *uuids = NULL;
2284 GVariantBuilder *builder = NULL;
2286 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2287 for (i=0; i < dev_info->uuid_count; i++) {
2288 g_variant_builder_add(builder, "s",
2289 dev_info->uuids[i]);
2291 uuids = g_variant_new("as", builder);
2292 g_variant_builder_unref(builder);
2293 GVariant *manufacturer_data = NULL;
2294 manufacturer_data = g_variant_new_from_data(
2295 G_VARIANT_TYPE_BYTESTRING,
2296 dev_info->manufacturer_data,
2297 dev_info->manufacturer_data_len,
2299 param = g_variant_new("(isunsbub@asn@ay)", result,
2305 dev_info->connected,
2308 dev_info->manufacturer_data_len,
2310 _bt_send_event(BT_ADAPTER_EVENT,
2311 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2313 p_cache_list = g_list_append(p_cache_list, cache_info);
2314 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2315 BT_DBG("Device path : %s ", obj_path);
2316 _bt_set_control_device_path(obj_path);
2319 g_variant_unref(value);
2320 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2321 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2322 bt_event = BT_MEDIA_TRANSFER_EVENT;
2323 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2324 bt_event = BT_DEVICE_EVENT;
2325 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2326 bt_event = BT_AVRCP_CONTROL_EVENT;
2328 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2329 _bt_handle_adapter_event(parameters, signal_name);
2330 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2331 BT_INFO("Object Path %s", obj_path);
2332 _bt_remove_control_device_path(obj_path);
2335 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2338 char *previous = NULL;
2339 char *current = NULL;
2341 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2342 BT_ERR("Fail to get the owner info");
2346 if (*current != '\0') {
2356 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2357 BT_DBG("Bluetoothd is terminated");
2358 if (_bt_adapter_get_status() != BT_DEACTIVATING) {
2361 _bt_handle_adapter_removed();
2362 __bt_devices_list_free();
2365 _bt_obex_server_check_allocation(&value);
2367 if (value == TRUE) {
2368 /* Check if the obex server was terminated abnormally */
2369 _bt_obex_server_check_termination(name);
2372 _bt_rfcomm_server_check_existence(&value);
2374 if (value == TRUE) {
2375 /* The obex server was terminated abnormally */
2376 _bt_rfcomm_server_check_termination(name);
2379 /* Stop advertising started by terminated process */
2380 _bt_stop_advertising_by_terminated_process(name);
2382 _bt_stop_le_scan(name);
2386 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2387 const char *path = object_path;
2389 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2390 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2393 _bt_handle_property_changed_event(parameters, object_path);
2394 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2395 _bt_handle_adapter_event(parameters, signal_name);
2396 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2397 _bt_handle_input_event(parameters, object_path);
2398 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2399 _bt_handle_network_server_event(parameters, signal_name);
2400 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2401 _bt_handle_headset_event(parameters, object_path);
2402 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2403 _bt_handle_sink_event(parameters, object_path);
2404 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2405 _bt_handle_agent_event(parameters, signal_name);
2406 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2407 _bt_handle_device_event(parameters, signal_name, object_path);
2413 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2416 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2417 char *interface_name = NULL;
2419 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2420 retv_if(interface_name == NULL, FALSE);
2422 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2423 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2431 static void __bt_obexd_event_filter(GDBusConnection *connection,
2432 const gchar *sender_name,
2433 const gchar *object_path,
2434 const gchar *interface_name,
2435 const gchar *signal_name,
2436 GVariant *parameters,
2439 const char *member = signal_name;
2440 char *obj_path = NULL;
2441 ret_if(member == NULL);
2443 if (strcasecmp(member, "InterfacesAdded") == 0) {
2444 if (__bt_get_object_path(parameters, &obj_path)) {
2445 BT_ERR("Fail to get the path");
2448 BT_INFO("object_path = [%s]", object_path);
2450 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2451 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2452 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2457 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2458 BT_DBG("Obex_Server_Session_Transfer connected");
2459 _bt_obex_transfer_connected();
2462 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2463 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2464 if (__bt_get_object_path(parameters, &obj_path)) {
2465 BT_ERR("Fail to get the path");
2468 BT_INFO("object_path = [%s]", object_path);
2470 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2471 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2472 BT_DBG("Call PBAP Disconnected");
2473 _bt_obex_pbap_client_disconnect(obj_path);
2476 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2477 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2482 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2483 BT_DBG("Obex_Server_Session_Transfer disconnected");
2484 _bt_obex_transfer_disconnected();
2487 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2488 const char *path = object_path;
2490 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2491 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2492 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2493 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2494 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2498 _bt_handle_property_changed_event(parameters, path);
2504 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2508 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2509 char *interface_name = NULL;
2511 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2513 retv_if(interface_name == NULL, FALSE);
2515 if (strcasecmp(interface_name,
2516 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2527 static void __bt_opc_event_filter(GDBusConnection *connection,
2528 const gchar *sender_name,
2529 const gchar *object_path,
2530 const gchar *interface_name,
2531 const gchar *signal_name,
2532 GVariant *parameters,
2535 const char *member = signal_name;
2536 char *obj_path = NULL;
2537 if (strcasecmp(member, "InterfacesAdded") == 0) {
2538 BT_DBG("InterfacesAdded");
2539 }else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2541 if (__bt_get_object_path(parameters, &obj_path)) {
2542 BT_ERR("Fail to get the path");
2546 BT_DBG("object_path =%s",obj_path);
2548 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2549 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2550 || strstr(obj_path, "transfer") == NULL) {
2554 else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2555 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2556 BT_DBG("Going to call opc disconnected");
2557 _bt_opc_disconnected(obj_path);
2560 _bt_sending_files();
2562 }else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE){
2563 char *path = (char *)object_path;
2564 BT_INFO("object_path %s", path);
2565 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2566 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2567 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2571 _bt_opc_property_changed_event(parameters, path);
2577 int _bt_opp_client_event_init(void)
2579 GError *error = NULL;
2581 if (opc_obexd_conn == NULL) {
2582 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2584 if (!opc_obexd_conn) {
2586 BT_ERR("Unable to connect to dbus: %s", error->message);
2587 g_clear_error(&error);
2589 return BLUETOOTH_ERROR_INTERNAL;
2593 if (_bt_register_service_event(opc_obexd_conn,
2594 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2595 g_object_unref(opc_obexd_conn);
2596 opc_obexd_conn = NULL;
2597 return BLUETOOTH_ERROR_INTERNAL;
2600 return BLUETOOTH_ERROR_NONE;
2603 void _bt_opp_client_event_deinit(void)
2605 if (opc_obexd_conn) {
2606 _bt_unregister_service_event(opc_obexd_conn,
2607 BT_OPP_CLIENT_EVENT);
2608 g_object_unref(opc_obexd_conn);
2609 opc_obexd_conn = NULL;
2613 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2619 static int subs_interface_added_id = -1;
2620 static int subs_interface_removed_id = -1;
2621 static int subs_name_owner_id = -1;
2622 static int subs_property_id = -1;
2623 static int subs_adapter_id = -1;
2626 if (subs_interface_added_id == -1) {
2627 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2628 NULL, BT_MANAGER_INTERFACE,
2629 BT_INTERFACES_ADDED, NULL, NULL, 0,
2630 __bt_manager_event_filter,
2633 if (subs_interface_removed_id == -1) {
2634 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2635 NULL, BT_MANAGER_INTERFACE,
2636 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2637 __bt_manager_event_filter,
2640 if (subs_name_owner_id == -1) {
2641 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
2642 NULL, BT_FREEDESKTOP_INTERFACE,
2643 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
2644 __bt_manager_event_filter,
2647 if (subs_property_id == -1) {
2648 subs_property_id = g_dbus_connection_signal_subscribe(conn,
2649 NULL, BT_PROPERTIES_INTERFACE,
2650 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2651 __bt_manager_event_filter,
2654 if (subs_adapter_id == -1) {
2655 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
2656 NULL, BT_ADAPTER_INTERFACE,
2657 NULL, NULL, NULL, 0,
2658 __bt_manager_event_filter,
2662 if (subs_interface_added_id != -1) {
2663 g_dbus_connection_signal_unsubscribe(conn,
2664 subs_interface_added_id);
2665 subs_interface_added_id = -1;
2667 if (subs_interface_removed_id != -1) {
2668 g_dbus_connection_signal_unsubscribe(conn,
2669 subs_interface_removed_id);
2670 subs_interface_removed_id = -1;
2672 if (subs_name_owner_id != -1) {
2673 g_dbus_connection_signal_unsubscribe(conn,
2674 subs_name_owner_id);
2675 subs_name_owner_id = -1;
2677 if (subs_property_id != -1) {
2678 g_dbus_connection_signal_unsubscribe(conn,
2680 subs_property_id = -1;
2682 if (subs_adapter_id == -1) {
2683 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
2684 subs_adapter_id = -1;
2690 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
2696 static int subs_device_id = -1;
2699 if (subs_device_id == -1) {
2700 subs_device_id = g_dbus_connection_signal_subscribe(conn,
2701 NULL, BT_DEVICE_INTERFACE,
2702 NULL, NULL, NULL, 0,
2703 __bt_manager_event_filter,
2707 if (subs_device_id != -1) {
2708 g_dbus_connection_signal_unsubscribe(conn,
2710 subs_device_id = -1;
2716 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
2722 static int subs_input_id = -1;
2725 if (subs_input_id == -1) {
2726 subs_input_id = g_dbus_connection_signal_subscribe(conn,
2727 NULL, BT_INPUT_INTERFACE,
2728 NULL, NULL, NULL, 0,
2729 __bt_manager_event_filter,
2733 if (subs_input_id != -1) {
2734 g_dbus_connection_signal_unsubscribe(conn,
2742 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
2748 static int subs_serv_id = -1;
2749 static int subs_client_id = -1;
2752 if (subs_serv_id == -1) {
2753 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
2754 NULL, BT_NETWORK_SERVER_INTERFACE,
2755 NULL, NULL, NULL, 0,
2756 __bt_manager_event_filter,
2759 if (subs_client_id == -1) {
2760 subs_client_id = g_dbus_connection_signal_subscribe(conn,
2761 NULL, BT_NETWORK_CLIENT_INTERFACE,
2762 NULL, NULL, NULL, 0,
2763 __bt_manager_event_filter,
2767 if (subs_serv_id != -1) {
2768 g_dbus_connection_signal_unsubscribe(conn,
2772 if (subs_client_id != -1) {
2773 g_dbus_connection_signal_unsubscribe(conn,
2775 subs_client_id = -1;
2781 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
2787 static int subs_headset_id = -1;
2788 static int subs_sink_id = -1;
2791 if (subs_headset_id == -1) {
2792 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
2793 NULL, BT_HEADSET_INTERFACE,
2794 NULL, NULL, NULL, 0,
2795 __bt_manager_event_filter,
2798 if (subs_sink_id == -1) {
2799 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
2800 NULL, BT_SINK_INTERFACE,
2801 NULL, NULL, NULL, 0,
2802 __bt_manager_event_filter,
2806 if (subs_headset_id != -1) {
2807 g_dbus_connection_signal_unsubscribe(conn,
2809 subs_headset_id = -1;
2811 if (subs_sink_id != -1) {
2812 g_dbus_connection_signal_unsubscribe(conn,
2820 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
2826 static int subs_opp_server_interface_added_id = -1;
2827 static int subs_opp_server_interface_removed_id = -1;
2828 static int subs_opp_server_property_id = -1;
2832 if (subs_opp_server_interface_added_id == -1) {
2833 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2834 NULL, BT_MANAGER_INTERFACE,
2835 BT_INTERFACES_ADDED, NULL, NULL, 0,
2836 __bt_obexd_event_filter,
2839 if (subs_opp_server_interface_removed_id == -1) {
2840 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2841 NULL, BT_MANAGER_INTERFACE,
2842 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2843 __bt_obexd_event_filter,
2846 if (subs_opp_server_property_id == -1) {
2847 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
2848 NULL, BT_PROPERTIES_INTERFACE,
2849 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2850 __bt_obexd_event_filter,
2854 if (subs_opp_server_interface_added_id != -1) {
2855 g_dbus_connection_signal_unsubscribe(conn,
2856 subs_opp_server_interface_added_id);
2857 subs_opp_server_interface_added_id = -1;
2859 if (subs_opp_server_interface_removed_id != -1) {
2860 g_dbus_connection_signal_unsubscribe(conn,
2861 subs_opp_server_interface_removed_id);
2862 subs_opp_server_interface_removed_id = -1;
2864 if (subs_opp_server_property_id != -1) {
2865 g_dbus_connection_signal_unsubscribe(conn,
2866 subs_opp_server_property_id);
2867 subs_opp_server_property_id = -1;
2873 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
2879 static int subs_opp_client_interface_added_id = -1;
2880 static int subs_opp_client_interface_removed_id = -1;
2881 static int subs_opp_client_property_id = -1;
2885 if (subs_opp_client_interface_added_id == -1) {
2886 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2887 NULL, BT_MANAGER_INTERFACE,
2888 BT_INTERFACES_ADDED, NULL, NULL, 0,
2889 __bt_opc_event_filter,
2892 if (subs_opp_client_interface_removed_id == -1) {
2893 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2894 NULL, BT_MANAGER_INTERFACE,
2895 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2896 __bt_opc_event_filter,
2899 if (subs_opp_client_property_id == -1) {
2900 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
2901 NULL, BT_PROPERTIES_INTERFACE,
2902 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2903 __bt_opc_event_filter,
2907 if (subs_opp_client_interface_added_id != -1) {
2908 g_dbus_connection_signal_unsubscribe(conn,
2909 subs_opp_client_interface_added_id);
2910 subs_opp_client_interface_added_id = -1;
2912 if (subs_opp_client_interface_removed_id != -1) {
2913 g_dbus_connection_signal_unsubscribe(conn,
2914 subs_opp_client_interface_removed_id);
2915 subs_opp_client_interface_removed_id = -1;
2917 if (subs_opp_client_property_id != -1) {
2918 g_dbus_connection_signal_unsubscribe(conn,
2919 subs_opp_client_property_id);
2920 subs_opp_client_property_id = -1;
2926 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
2932 static int subs_a2dp_source_id = -1;
2933 static int subs_a2dp_sink_id = -1;
2936 if (subs_a2dp_source_id == -1) {
2937 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
2938 NULL, BT_A2DP_SOURCE_INTERFACE,
2939 NULL, NULL, NULL, 0,
2940 __bt_opc_event_filter,
2943 if (subs_a2dp_sink_id == -1) {
2944 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
2945 NULL, BT_SINK_INTERFACE,
2946 NULL, NULL, NULL, 0,
2947 __bt_opc_event_filter,
2951 if (subs_a2dp_source_id != -1) {
2952 g_dbus_connection_signal_unsubscribe(conn,
2953 subs_a2dp_source_id);
2954 subs_a2dp_source_id = -1;
2956 if (subs_a2dp_sink_id != -1) {
2957 g_dbus_connection_signal_unsubscribe(conn,
2959 subs_a2dp_sink_id = -1;
2965 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
2969 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2971 switch (event_type) {
2972 case BT_MANAGER_EVENT:
2973 _bt_register_manager_subscribe_signal(g_conn, TRUE);
2975 case BT_DEVICE_EVENT:
2976 _bt_register_device_subscribe_signal(g_conn, TRUE);
2979 _bt_register_input_subscribe_signal(g_conn, TRUE);
2981 case BT_NETWORK_EVENT:
2982 _bt_register_network_subscribe_signal(g_conn, TRUE);
2984 case BT_HEADSET_EVENT:
2985 _bt_register_audio_subscribe_signal(g_conn, TRUE);
2988 case BT_OPP_SERVER_EVENT:
2989 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
2990 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
2992 case BT_OPP_CLIENT_EVENT:
2993 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
2994 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
2996 case BT_A2DP_SOURCE_EVENT:
2997 BT_INFO("A2dp Source event");
2998 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3001 BT_ERR("Unknown event");
3002 return BLUETOOTH_ERROR_INTERNAL;
3005 return BLUETOOTH_ERROR_NONE;
3008 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3012 ret_if(g_conn == NULL);
3014 switch (event_type) {
3015 case BT_MANAGER_EVENT:
3016 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3017 _bt_register_device_subscribe_signal(g_conn, FALSE);
3018 _bt_register_input_subscribe_signal(g_conn, FALSE);
3019 _bt_register_network_subscribe_signal(g_conn, FALSE);
3020 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3022 case BT_OPP_SERVER_EVENT:
3023 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3025 case BT_OPP_CLIENT_EVENT:
3026 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3029 BT_ERR("Unknown event");
3036 static int __bt_init_manager_receiver(void)
3040 GError *error = NULL;
3042 if (manager_conn == NULL) {
3043 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3044 if (error != NULL) {
3045 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3046 g_clear_error(&error);
3048 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3051 if (_bt_register_service_event(manager_conn,
3052 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3054 if (_bt_register_service_event(manager_conn,
3055 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3058 if (_bt_register_service_event(manager_conn,
3059 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3062 if (_bt_register_service_event(manager_conn,
3063 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3066 if (_bt_register_service_event(manager_conn,
3067 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3069 return BLUETOOTH_ERROR_NONE;
3072 g_object_unref(manager_conn);
3073 manager_conn = NULL;
3078 return BLUETOOTH_ERROR_INTERNAL;
3081 static int __bt_init_obexd_receiver(void)
3084 GError *error = NULL;
3086 if (obexd_conn == NULL) {
3087 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3088 if (error != NULL) {
3089 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3090 g_clear_error(&error);
3092 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3095 if (_bt_register_service_event(obexd_conn,
3096 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3097 BT_ERR("Error while registering service event");
3098 g_object_unref(obexd_conn);
3100 return BLUETOOTH_ERROR_INTERNAL;
3105 return BLUETOOTH_ERROR_NONE;
3108 /* To receive the event from bluez */
3109 int _bt_init_service_event_receiver(void)
3115 result = __bt_init_manager_receiver();
3116 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3118 result = __bt_init_obexd_receiver();
3119 if (result != BLUETOOTH_ERROR_NONE)
3120 BT_ERR("Fail to init obexd receiver");
3124 return BLUETOOTH_ERROR_NONE;
3127 void _bt_deinit_service_event_receiver(void)
3131 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3133 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3136 g_object_unref(manager_conn);
3137 manager_conn = NULL;
3141 g_object_unref(obexd_conn);
3146 g_source_remove(event_id);