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 #ifdef ENABLE_TIZEN_2_4
733 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
734 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
735 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
741 _bt_handle_adapter_added();
744 } else if (strcasecmp(property, "Connectable") == 0) {
745 gboolean connectable = FALSE;
747 g_variant_get(val, "b", &connectable);
749 BT_DBG("Connectable property is changed : %d", connectable);
750 param = g_variant_new("(b)", connectable);
751 _bt_send_event(BT_ADAPTER_EVENT,
752 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
754 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
755 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
757 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
758 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
761 GVariantIter *iter = NULL;
762 g_variant_get(val, "as", &iter);
763 while (g_variant_iter_loop(iter, "s", &name)) {
764 BT_DBG("name = %s", name);
765 g_variant_iter_loop(iter, "s", &value);
766 BT_DBG("Value = %s", value);
767 if (FALSE == _bt_update_le_feature_support(name, value))
768 BT_INFO("Fail to update LE feature info");
771 g_variant_iter_free(iter);
773 BT_DBG("property : [%s]", property);
778 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
782 GVariantIter value_iter;
783 GVariant *child = NULL, *val = NULL;
784 char *property = NULL;
785 g_variant_iter_init (&value_iter, msg);
786 while ((child = g_variant_iter_next_value (&value_iter))) {
787 g_variant_get(child, "{sv}", &property, &val);
789 ret_if(property == NULL);
791 BT_DBG("property :%s", property);
793 if (strcasecmp(property, "Status") == 0) {
795 g_variant_get(val, "s", &status);
797 if (strcasecmp(status, "active") == 0){
798 _bt_obex_transfer_started(path);
799 } else if (strcasecmp(status, "complete") == 0) {
800 _bt_obex_transfer_completed(path, TRUE);
801 _bt_pbap_obex_transfer_completed(path, TRUE);
802 } else if (strcasecmp(status, "error") == 0){
803 _bt_obex_transfer_completed(path, FALSE);
804 _bt_pbap_obex_transfer_completed(path, FALSE);
807 } else if (strcasecmp(property, "Transferred") == 0) {
808 static int transferred = 0;
809 g_variant_get(val, "t", &transferred);
811 _bt_obex_transfer_progress(path,transferred);
814 g_variant_unref(val);
815 g_variant_unref(child);
820 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
825 int result = BLUETOOTH_ERROR_NONE;
826 GVariantIter value_iter;
828 char *property = NULL;
830 GVariant *param = NULL;
831 bt_remote_dev_info_t *remote_dev_info;
832 g_variant_iter_init (&value_iter, msg);
833 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
834 BT_DBG("Property %s", property);
835 if (strcasecmp(property, "Connected") == 0) {
838 g_variant_get(val, "i", &connected);
840 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
841 BLUETOOTH_EVENT_DEVICE_CONNECTED :
842 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
844 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
846 _bt_convert_device_path_to_address(path, address);
848 BT_DBG("connected: %d", connected);
849 BT_DBG("address: %s", address);
851 remote_dev_info = _bt_get_remote_device_info(address);
853 if (remote_dev_info != NULL) {
854 __bt_device_remote_connected_properties(
855 remote_dev_info, address,
856 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
858 _bt_free_device_info(remote_dev_info);
860 param = g_variant_new("(is)", result, address);
861 /* Send event to application */
862 _bt_send_event(BT_DEVICE_EVENT,
866 } else if (strcasecmp(property, "RSSI") == 0) {
867 bt_remote_dev_info_t *remote_dev_info;
869 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
871 _bt_convert_device_path_to_address(path, address);
872 BT_DBG("address: %s", address);
874 remote_dev_info = _bt_get_remote_device_info(address);
875 if (remote_dev_info == NULL) {
877 g_variant_unref(val);
881 BT_DBG("Address type %d", remote_dev_info->addr_type);
883 if (remote_dev_info && remote_dev_info->addr_type == 0) {
884 BT_DBG("Name %s", remote_dev_info->name);
886 GVariant *uuids = NULL;
887 GVariantBuilder *builder = NULL;
889 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
890 for (i=0; i < remote_dev_info->uuid_count; i++) {
891 g_variant_builder_add(builder, "s",
892 remote_dev_info->uuids[i]);
894 uuids = g_variant_new("as", builder);
895 g_variant_builder_unref(builder);
896 GVariant *manufacturer_data = NULL;
897 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
898 remote_dev_info->manufacturer_data,
899 remote_dev_info->manufacturer_data_len,
902 param = g_variant_new("(isunsbub@asn@ay)", result,
903 remote_dev_info->address,
904 remote_dev_info->class,
905 remote_dev_info->rssi,
906 remote_dev_info->name,
907 remote_dev_info->paired,
908 remote_dev_info->connected,
909 remote_dev_info->trust,
911 remote_dev_info->manufacturer_data_len,
914 _bt_send_event(BT_ADAPTER_EVENT,
915 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
919 _bt_free_device_info(remote_dev_info);
920 } else if (strcasecmp(property, "GattConnected") == 0) {
921 gboolean gatt_connected = FALSE;
923 g_variant_get(val, "b", &gatt_connected);
925 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
926 BLUETOOTH_EVENT_GATT_DISCONNECTED;
928 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
930 _bt_convert_device_path_to_address(path, address);
932 BT_DBG("gatt_connected: %d", gatt_connected);
933 BT_DBG("address: %s", address);
934 param = g_variant_new("(is)", result, address);
935 /* Send event to application */
936 _bt_send_event(BT_DEVICE_EVENT,
940 } else if (strcasecmp(property, "Paired") == 0) {
941 gboolean paired = FALSE;
942 bt_remote_dev_info_t *remote_dev_info;
943 g_variant_get(val, "b", &paired);
944 _bt_agent_set_canceled(FALSE);
945 /* BlueZ sends paired signal for each paired device */
946 /* during activation, We should ignore this, otherwise*/
947 /* application thinks that a new device got paired */
948 if (_bt_adapter_get_status() != BT_ACTIVATED) {
949 BT_DBG("BT is not activated, so ignore this");
951 g_variant_unref(val);
955 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
957 _bt_convert_device_path_to_address(path, address);
959 remote_dev_info = _bt_get_remote_device_info(address);
960 if (remote_dev_info == NULL) {
962 g_variant_unref(val);
967 if(paired == FALSE) {
968 BT_INFO("Unpaired: %s", address);
969 __bt_update_remote_cache_devinfo(address, FALSE);
970 param = g_variant_new("(is)", result, address);
971 _bt_send_event(BT_ADAPTER_EVENT,
972 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
975 BT_INFO("Paired: %s", address);
976 __bt_update_remote_cache_devinfo(address, TRUE);
978 if (_bt_is_device_creating() == TRUE) {
979 BT_DBG("Try to Pair by me");
980 _bt_free_device_info(remote_dev_info);
983 g_variant_unref(val);
986 GVariant *uuids = NULL;
987 GVariantBuilder *builder = NULL;
989 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
990 for (i=0; i < remote_dev_info->uuid_count; i++) {
991 g_variant_builder_add(builder, "s",
992 remote_dev_info->uuids[i]);
994 uuids = g_variant_new("as", builder);
995 g_variant_builder_unref(builder);
996 GVariant *manufacturer_data = NULL;
997 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
998 remote_dev_info->manufacturer_data,
999 remote_dev_info->manufacturer_data_len,
1003 param = g_variant_new("(isunsbub@asn@ay)", result,
1004 address, remote_dev_info->class,
1005 remote_dev_info->rssi,
1006 remote_dev_info->name,
1007 remote_dev_info->paired,
1008 remote_dev_info->connected,
1009 remote_dev_info->trust,
1011 remote_dev_info->manufacturer_data_len,
1013 _bt_send_event(BT_ADAPTER_EVENT,
1014 BLUETOOTH_EVENT_BONDING_FINISHED,
1017 _bt_free_device_info(remote_dev_info);
1019 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1020 gboolean paired = FALSE;
1021 bt_remote_dev_info_t *remote_dev_info;
1023 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1024 BT_DBG("BT is not activated, so ignore this");
1026 g_variant_unref(val);
1030 g_variant_get(val, "b", &paired);
1031 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1032 BT_DBG("LegacyPaired: %d", paired);
1033 _bt_convert_device_path_to_address(path, address);
1035 remote_dev_info = _bt_get_remote_device_info(address);
1036 if (remote_dev_info == NULL) {
1039 g_variant_unref(val);
1043 BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
1044 remote_dev_info->name);
1045 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1046 remote_dev_info->name, NULL, NULL, NULL);
1048 _bt_free_device_info(remote_dev_info);
1050 } else if (strcasecmp(property, "Trusted") == 0) {
1051 gboolean trusted = FALSE;
1053 g_variant_get(val, "b", &trusted);
1055 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1056 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1058 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1060 _bt_convert_device_path_to_address(path, address);
1062 BT_DBG("trusted: %d", trusted);
1063 BT_DBG("address: %s", address);
1064 param = g_variant_new("(is)", result, address);
1065 /* Send event to application */
1066 _bt_send_event(BT_DEVICE_EVENT,
1075 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1078 int result = BLUETOOTH_ERROR_NONE;
1079 GVariantIter value_iter;
1080 char *property = NULL;
1082 GVariant *val = NULL;
1083 GVariant *child = NULL;
1084 bt_remote_dev_info_t *remote_dev_info;
1085 GVariant *param = NULL;
1086 g_variant_iter_init (&value_iter, msg);
1087 while ((child = g_variant_iter_next_value (&value_iter))) {
1088 g_variant_get(child, "{sv}", &property, &val);
1089 BT_INFO("Property %s", property);
1090 if (strcasecmp(property, "Connected") == 0) {
1091 gboolean connected = FALSE;
1093 g_variant_get(val, "b", &connected);
1095 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1096 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1098 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1100 _bt_convert_device_path_to_address(path, address);
1102 BT_DBG("connected: %d", connected);
1103 BT_DBG("address: %s", address);
1105 remote_dev_info = _bt_get_remote_device_info(address);
1107 if (remote_dev_info != NULL) {
1108 __bt_device_remote_connected_properties(
1109 remote_dev_info, address, connected);
1110 _bt_free_device_info(remote_dev_info);
1112 param = g_variant_new("(is)", result, address);
1113 /* Send event to application */
1114 _bt_send_event(BT_AVRCP_EVENT,
1120 g_variant_unref(child);
1121 g_variant_unref(val);
1126 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1128 char *interface_name = NULL;
1129 GVariant *val = NULL;
1131 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val,NULL);
1133 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1134 __bt_adapter_property_changed_event(val,
1136 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1137 __bt_device_property_changed_event(val,object_path);
1138 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1139 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1140 __bt_obex_property_changed_event(val,
1142 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1143 __bt_media_control_changed_event(val,
1145 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1146 _bt_handle_avrcp_control_event(val,
1148 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1149 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1150 _bt_handle_network_client_event(val,
1152 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1153 __bt_gatt_char_property_changed_event(val,
1156 g_variant_unref(val);
1159 void __bt_opc_property_changed_event(GVariant *msg,
1162 GVariantIter value_iter;
1163 char *property = NULL;
1164 GVariant *val = NULL;
1165 GVariant *child = NULL;
1167 g_variant_iter_init (&value_iter, msg);
1168 while ((child = g_variant_iter_next_value (&value_iter))) {
1169 g_variant_get(child, "{sv}", &property, &val);
1170 ret_if(property == NULL);
1172 if (strcasecmp(property, "Status") == 0) {
1173 char *status = NULL;
1174 g_variant_get(val, "s", &status);
1175 BT_DBG("Status is %s", status);
1177 if(strcasecmp(status, "active") == 0){
1178 _bt_obex_client_started(path);
1179 }else if (strcasecmp(status, "complete") == 0) {
1180 _bt_obex_client_completed(path, TRUE);
1181 }else if (strcasecmp(status, "error") == 0){
1182 _bt_obex_client_completed(path, FALSE);
1185 } else if (strcasecmp(property, "Transferred") == 0) {
1186 static int transferred = 0;
1187 g_variant_get(val, "t", &transferred);
1189 _bt_obex_client_progress(path, transferred);
1191 BT_DBG("property : [%s]", property);
1194 g_variant_unref(child);
1195 g_variant_unref(val);
1199 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1201 char *interface_name = NULL;
1202 GVariant *value = NULL;
1203 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1204 BT_INFO("interface_name = %s", interface_name);
1205 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1206 __bt_opc_property_changed_event(value,
1209 BT_DBG("interface_name : [%s]", interface_name);
1211 g_variant_unref(value);
1215 void _bt_handle_input_event(GVariant *msg, const char *path)
1217 int result = BLUETOOTH_ERROR_NONE;
1218 gboolean property_flag = FALSE;
1219 GVariantIter value_iter;
1220 char *property = NULL;
1221 GVariant *child = NULL, *val = NULL;
1222 bt_remote_dev_info_t *remote_dev_info;
1223 GVariant *param = NULL;
1224 g_variant_iter_init (&value_iter, msg);
1225 while ((child = g_variant_iter_next_value (&value_iter))) {
1226 g_variant_get(child, "{sv}", &property, &val);
1228 ret_if(property == NULL);
1230 if (strcasecmp(property, "Connected") == 0) {
1231 int event = BLUETOOTH_EVENT_NONE;
1233 g_variant_get(val, "b", &property_flag);
1235 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1237 _bt_convert_device_path_to_address(path, address);
1239 event = (property_flag == TRUE) ?
1240 BLUETOOTH_HID_CONNECTED :
1241 BLUETOOTH_HID_DISCONNECTED;
1242 param = g_variant_new("(is)", result, address);
1243 _bt_send_event(BT_HID_EVENT, event,
1245 /* Check HID connection type (Keyboard or Mouse) and update the status */
1246 remote_dev_info = _bt_get_remote_device_info(address);
1248 if (property_flag == TRUE) {
1249 hid_connected_device_count++;
1250 __bt_set_device_values(TRUE,
1251 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1253 hid_connected_device_count--;
1254 if (hid_connected_device_count == 0)
1255 __bt_set_device_values(FALSE,
1256 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1259 if (remote_dev_info != NULL) {
1260 BT_DBG("HID device class [%x]", remote_dev_info->class);
1261 if (remote_dev_info->class &
1262 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1263 #ifdef ENABLE_TIZEN_2_4
1264 __bt_set_device_values(property_flag,
1265 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1270 if (remote_dev_info->class &
1271 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1272 #ifdef ENABLE_TIZEN_2_4
1273 __bt_set_device_values(property_flag,
1274 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1277 _bt_free_device_info(remote_dev_info);
1282 g_variant_unref(val);
1283 g_variant_unref(child);
1287 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1289 int result = BLUETOOTH_ERROR_NONE;
1290 char *address = NULL;
1291 char *device = NULL;
1292 GVariant *param = NULL;
1293 ret_if(member == NULL);
1294 if (strcasecmp(member, "PeerConnected") == 0) {
1295 g_variant_get(msg, "(ss)", &device, &address);
1297 __bt_set_device_values(TRUE,
1298 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1299 param = g_variant_new("(iss)", result, device, address);
1300 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1304 nap_connected_device_count++;
1305 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1306 g_variant_get(msg, "(ss)", &device, &address);
1307 nap_connected_device_count--;
1308 if (nap_connected_device_count == 0)
1309 __bt_set_device_values(FALSE,
1310 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1311 param = g_variant_new("(iss)", result, device, address);
1312 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1319 void _bt_handle_network_client_event(GVariant *msg,
1324 int result = BLUETOOTH_ERROR_NONE;
1325 gboolean property_flag = FALSE;
1326 char *property = NULL;
1327 GVariant *val = NULL;
1328 GVariantIter value_iter;
1329 GVariant *param = NULL;
1330 g_variant_iter_init (&value_iter, msg);
1331 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1332 if (strcasecmp(property, "Connected") == 0) {
1333 int event = BLUETOOTH_EVENT_NONE;
1336 g_variant_get(val, "b", &property_flag);
1337 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1339 _bt_convert_device_path_to_address(path, address);
1341 BT_DBG("property_flag %d", property_flag);
1342 if (property_flag == TRUE) {
1343 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1344 nap_connected_device_count++;
1345 __bt_set_device_values(TRUE,
1346 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1348 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1349 nap_connected_device_count--;
1350 if (nap_connected_device_count == 0)
1351 __bt_set_device_values(FALSE,
1352 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1354 param = g_variant_new("(is)", result, address);
1355 _bt_send_event(BT_NETWORK_EVENT, event,
1364 void __bt_gatt_char_property_changed_event(GVariant *msg,
1367 GVariantIter value_iter;
1368 char *property = NULL;
1369 char * char_handle = NULL;
1370 GVariant *val = NULL;
1371 int result = BLUETOOTH_ERROR_NONE;
1372 GVariant *param = NULL;
1373 g_variant_iter_init (&value_iter, msg);
1374 char_handle = g_strdup(path);
1375 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1376 BT_INFO("Property %s", property);
1378 ret_if(property == NULL);
1380 if (strcasecmp(property, "Notifying") == 0) {
1381 gboolean property_flag = FALSE;
1382 g_variant_get(val, "b", &property_flag);
1383 if (property_flag == TRUE)
1384 BT_DBG("notifying is enabled");
1386 BT_DBG("notifying is disabled");
1387 } else if (strcasecmp(property, "ChangedValue") == 0) {
1389 GByteArray *gp_byte_array = NULL;
1390 BT_INFO("Type '%s'\n", g_variant_get_type_string (val));
1393 gp_byte_array = g_byte_array_new();
1394 len = g_variant_get_size(val);
1395 BT_DBG("Len = %d", len);
1396 g_byte_array_append (gp_byte_array,
1397 (const guint8 *) g_variant_get_data(val), len);
1398 if (gp_byte_array->len != 0) {
1399 GVariant *byte_array = NULL;
1400 byte_array = g_variant_new_from_data(
1401 G_VARIANT_TYPE_BYTESTRING,
1402 gp_byte_array->data,
1405 param = g_variant_new("(is@ay)", result, char_handle,
1407 _bt_send_event(BT_DEVICE_EVENT,
1408 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
1411 g_byte_array_free(gp_byte_array, TRUE);
1415 g_free(char_handle);
1417 void _bt_handle_device_event(GVariant *msg, const char *member,const char *path)
1420 int result = BLUETOOTH_ERROR_NONE;
1423 const char *property = NULL;
1424 GVariant *param = NULL;
1425 ret_if(path == NULL);
1427 if (strcasecmp(member, "PropertyChanged") == 0) {
1429 g_variant_get(msg, "(s)", &property);
1431 ret_if(property == NULL);
1433 if (strcasecmp(property, "GattConnected") == 0) {
1434 gboolean connected = FALSE;
1436 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1437 _bt_convert_device_path_to_address(path, address);
1438 g_variant_get(msg, "(b)", &connected);
1440 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1441 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1442 param = g_variant_new("(is)", result, address);
1443 _bt_send_event(BT_DEVICE_EVENT,
1447 } else if (strcasecmp(property, "Paired") == 0) {
1448 gboolean paired = FALSE;
1449 bt_remote_dev_info_t *remote_dev_info;
1450 g_variant_get(msg, "(b)", &paired);
1452 ret_if(paired == FALSE);
1454 /* BlueZ sends paired signal for each paired device */
1455 /* during activation, We should ignore this, otherwise*/
1456 /* application thinks that a new device got paired */
1457 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1458 BT_DBG("BT is not activated, so ignore this");
1462 if (_bt_is_device_creating() == TRUE) {
1463 BT_DBG("Try to Pair by me");
1467 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1469 _bt_convert_device_path_to_address(path, address);
1471 remote_dev_info = _bt_get_remote_device_info(address);
1472 if (remote_dev_info == NULL) {
1476 GVariant *uuids = NULL;
1477 GVariantBuilder *builder = NULL;
1479 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1480 for (i=0; i < remote_dev_info->uuid_count; i++) {
1481 g_variant_builder_add(builder, "s",
1482 remote_dev_info->uuids[i]);
1484 uuids = g_variant_new("as", builder);
1485 g_variant_builder_unref(builder);
1486 GVariant *manufacturer_data = NULL;
1487 manufacturer_data = g_variant_new_from_data(
1488 G_VARIANT_TYPE_BYTESTRING,
1489 remote_dev_info->manufacturer_data,
1490 remote_dev_info->manufacturer_data_len,
1492 param = g_variant_new("(isunsbub@asn@ay)", result,
1494 remote_dev_info->class,
1495 remote_dev_info->rssi,
1496 remote_dev_info->name,
1497 remote_dev_info->paired,
1498 remote_dev_info->connected,
1499 remote_dev_info->trust,
1501 remote_dev_info->manufacturer_data_len,
1503 _bt_send_event(BT_ADAPTER_EVENT,
1504 BLUETOOTH_EVENT_BONDING_FINISHED,
1506 _bt_free_device_info(remote_dev_info);
1509 } else if (strcasecmp(property, "UUIDs") == 0) {
1510 /* Once we get the updated uuid information after
1511 * reverse service search, update it to application */
1513 bt_remote_dev_info_t *remote_dev_info;
1515 ret_if(_bt_is_device_creating() == TRUE);
1517 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1519 _bt_convert_device_path_to_address(path, address);
1521 remote_dev_info = _bt_get_remote_device_info(address);
1522 if (remote_dev_info == NULL) {
1527 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1528 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1529 GVariant *uuids = NULL;
1530 GVariantBuilder *builder = NULL;
1532 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1533 for (i=0; i < remote_dev_info->uuid_count; i++) {
1534 g_variant_builder_add(builder, "s",
1535 remote_dev_info->uuids[i]);
1537 uuids = g_variant_new("as", builder);
1538 g_variant_builder_unref(builder);
1539 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1540 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1543 param = g_variant_new("(isunsbub@asn@ay)", result,
1544 address, remote_dev_info->class,
1545 remote_dev_info->rssi,
1546 remote_dev_info->name,
1547 remote_dev_info->paired,
1548 remote_dev_info->connected,
1549 remote_dev_info->trust,
1551 remote_dev_info->manufacturer_data_len,
1553 _bt_send_event(BT_ADAPTER_EVENT,
1554 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1558 _bt_free_device_info(remote_dev_info);
1561 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1562 unsigned char addr_type = 0;
1564 g_variant_get(msg, "(y)", &addr_type);
1566 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1568 _bt_convert_device_path_to_address(path, address);
1569 dev_name = _bt_get_bonded_device_name(address);
1571 BT_INFO("Address : %s Type : %d", address, addr_type);
1572 BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1573 !addr_type ? dev_name : address);
1576 _bt_logging_connection(TRUE, addr_type);
1577 #ifdef ENABLE_TIZEN_2_4
1578 journal_bt_connected();
1580 param = g_variant_new("(isy)", result, address, addr_type);
1581 /*Send event to application*/
1582 _bt_send_event(BT_DEVICE_EVENT,
1583 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1586 } else if (strcasecmp(member, "Disconnected") == 0) {
1587 unsigned char disc_reason = 0;
1588 unsigned char addr_type = 0;
1589 gboolean sending = FALSE;
1591 g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
1593 result = disc_reason;
1595 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1597 _bt_convert_device_path_to_address(path, address);
1598 dev_name = _bt_get_bonded_device_name(address);
1599 #ifdef ENABLE_TIZEN_2_4
1600 journal_bt_disconnected();
1603 /* 0x00 BDADDR_BRDER
1604 0x01 BDADDR_LE_PUBLIC
1605 0x02 BDADDR_LE_RANDOM */
1606 BT_INFO("Address : %s Type : %d", address, addr_type);
1607 BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1608 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1609 !addr_type ? dev_name : address);
1612 _bt_headset_set_local_connection(FALSE);
1613 _bt_logging_connection(FALSE, addr_type);
1615 /*Check for any OPP transfer on the device and cancel
1618 _bt_obex_check_pending_transfer(address);
1619 _bt_opp_client_is_sending(&sending);
1621 _bt_opp_client_check_pending_transfer(address);
1622 param = g_variant_new("(isy)", result, address, addr_type);
1623 _bt_send_event(BT_DEVICE_EVENT,
1624 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1627 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1629 char *profile_uuid = NULL;
1630 bt_headset_wait_t *wait_list;
1632 g_variant_get(msg, "(si)", &profile_uuid, &state);
1634 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1636 _bt_convert_device_path_to_address(path, address);
1638 BT_DBG("Address: %s", address);
1639 BT_DBG("Profile UUID: %s", profile_uuid);
1640 BT_DBG("State: %d", state);
1642 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1643 (state == BT_PROFILE_STATE_CONNECTED)) {
1645 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1646 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1647 bluetooth_device_address_t device_address;
1649 bt_headset_wait_t *wait_list;
1651 __bt_set_device_values(TRUE,
1652 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1654 __bt_connection_manager_set_state(address, event);
1656 if (_bt_headset_get_local_connection() == FALSE)
1657 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1659 /* Connection Started from local device therefore no need to
1660 * intiate connection for pending profile */
1661 _bt_headset_set_local_connection(FALSE);
1663 param = g_variant_new("(is)", result, address);
1664 _bt_send_event(BT_HEADSET_EVENT, event,
1666 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1669 if (g_strcmp0(connected_address, address) != 0) {
1670 _bt_convert_addr_string_to_type(
1671 device_address.addr,
1673 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1674 &device_address, NULL);
1678 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1679 BT_STATE_CONNECTED, address);
1681 wait_list = _bt_get_audio_wait_data();
1682 if (wait_list != NULL &&
1683 (g_strcmp0(wait_list->address, address) == 0))
1684 _bt_rel_wait_data();
1686 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1687 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1689 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1691 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1693 g_free(profile_uuid);
1697 __bt_set_device_values(FALSE,
1698 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1700 __bt_connection_manager_set_state(address, event);
1701 param = g_variant_new("(is)", result, address);
1702 _bt_send_event(BT_HEADSET_EVENT, event,
1704 /* Remove data from the connected list */
1705 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1706 wait_list = _bt_get_audio_wait_data();
1708 if (wait_list == NULL) {
1710 g_free(profile_uuid);
1714 if (((wait_list->type == BT_AUDIO_ALL) &&
1715 (wait_list->ag_flag == TRUE)) ||
1716 (wait_list->type == BT_AUDIO_A2DP) ||
1717 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1718 bluetooth_device_address_t device_address;
1719 _bt_convert_addr_string_to_type(
1720 device_address.addr,
1721 wait_list->address);
1723 _bt_audio_connect(wait_list->req_id,
1726 wait_list->out_param1);
1728 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1730 if (state == BT_PROFILE_STATE_CONNECTED) {
1731 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1732 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1733 bluetooth_device_address_t device_address;
1735 param = g_variant_new("(is)", result, address);
1736 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1738 connected = _bt_is_headset_type_connected(
1742 if (g_strcmp0(connected_address,
1744 _bt_convert_addr_string_to_type(
1745 device_address.addr,
1747 _bt_audio_disconnect(0,
1749 &device_address, NULL);
1752 BT_DBG("device Path: %s", path);
1753 _bt_add_headset_to_list(BT_AVRCP,
1754 BT_STATE_CONNECTED, address);
1755 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1756 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1757 param = g_variant_new("(is)", result, address);
1758 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1760 /* Remove data from the connected list */
1761 _bt_remove_headset_from_list(BT_AVRCP, address);
1763 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1764 if (state == BT_PROFILE_STATE_CONNECTED) {
1765 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1766 BT_INFO("A2DP Source is connected");
1767 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1768 g_variant_new("(is)", result, address));
1769 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1770 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
1771 BT_INFO("A2DP Source Disconnected");
1772 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1773 g_variant_new("(is)", result, address));
1775 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
1776 ((state == BT_PROFILE_STATE_CONNECTED) ||
1777 (state == BT_PROFILE_STATE_DISCONNECTED))) {
1779 if (state == BT_PROFILE_STATE_CONNECTED)
1780 event = BLUETOOTH_HID_CONNECTED;
1782 event = BLUETOOTH_HID_DISCONNECTED;
1783 param = g_variant_new("(is)", result, address);
1784 _bt_send_event(BT_HID_EVENT, event,
1787 if (state == BT_PROFILE_STATE_CONNECTED)
1788 __bt_set_device_values(TRUE,
1789 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1791 __bt_set_device_values(FALSE,
1792 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1795 g_free(profile_uuid);
1796 } else if (strcasecmp(member, "AdvReport") == 0) {
1798 bt_remote_le_dev_info_t *le_dev_info = NULL;
1799 char *buffer = NULL;
1801 bt_le_adv_info_t *adv_info = NULL;
1802 GVariant *value = NULL;
1803 ret_if(_bt_is_le_scanning() == FALSE);
1805 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
1807 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
1808 &le_dev_info->addr_type,
1809 &le_dev_info->adv_type,
1811 &le_dev_info->adv_data_len,
1813 buffer_len = g_variant_get_size(value);
1815 buffer = (char *)g_variant_get_data(value);
1817 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
1819 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1820 _bt_send_scan_result_event(le_dev_info, NULL);
1821 _bt_free_le_device_info(le_dev_info);
1822 g_variant_unref(value);
1826 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
1827 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
1828 adv_info->addr = g_strdup(le_dev_info->address);
1829 adv_info->data_len = le_dev_info->adv_data_len;
1830 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
1831 memcpy(adv_info->data, le_dev_info->adv_data,
1832 le_dev_info->adv_data_len);
1834 __bt_add_adv_ind_info(adv_info);
1836 } else { /* SCAN_RSP */
1837 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
1839 _bt_send_scan_result_event(le_dev_info, adv_info);
1840 __bt_del_adv_ind_info(le_dev_info->address);
1843 _bt_free_le_device_info(le_dev_info);
1844 g_variant_unref(value);
1849 void __bt_set_audio_values(gboolean connected, char *address)
1852 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1854 /* Set the headset name */
1855 if (connected == TRUE) {
1856 name = _bt_get_bonded_device_name(address);
1858 name = g_strdup("");
1861 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
1863 BT_ERR("vconf_set_str failed");
1868 /* Set the headset state */
1869 if (vconf_get_int(VCONFKEY_BT_DEVICE,
1870 &bt_device_state) != 0) {
1871 BT_ERR("vconf_get_str failed");
1874 #ifdef TIZEN_SUPPORT_DUAL_HF
1875 if ((connected == TRUE) &&
1876 (FALSE == __bt_is_companion_device(address))) {
1877 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1878 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
1879 (FALSE == __bt_is_companion_device(address))) {
1880 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1883 if (connected == TRUE) {
1884 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1885 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
1886 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1890 if (vconf_set_int(VCONFKEY_BT_DEVICE,
1891 bt_device_state) != 0) {
1892 BT_ERR("vconf_set_int failed");
1896 void _bt_handle_headset_event(GVariant *msg, const char *path)
1898 int result = BLUETOOTH_ERROR_NONE;
1899 gboolean property_flag = FALSE;
1900 char *property = NULL;
1901 GVariant *value = NULL;
1902 GVariant *param = NULL;
1903 g_variant_get(msg, "(sv)", &property, &value);
1905 ret_if(property == NULL);
1907 BT_DBG("Property = %s \n", property);
1908 /* We allow only 1 headset connection (HSP or HFP)*/
1909 if (strcasecmp(property, "Connected") == 0) {
1910 int event = BLUETOOTH_EVENT_NONE;
1911 bt_headset_wait_t *wait_list;
1913 g_variant_get(value, "b", &property_flag);
1915 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1917 /* Fix : NULL_RETURNS */
1918 if (address == NULL)
1921 _bt_convert_device_path_to_address(path, address);
1923 if (property_flag == TRUE) {
1924 event = BLUETOOTH_EVENT_AG_CONNECTED;
1925 if (_bt_headset_get_local_connection() == FALSE)
1926 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
1928 _bt_headset_set_local_connection(FALSE);
1932 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
1934 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
1935 if (previous_state == BT_STATE_DISCONNECTING)
1936 _bt_send_hf_local_term_event(address);
1938 /* Set the State machine here */
1939 __bt_connection_manager_set_state(address, event);
1940 __bt_set_audio_values(property_flag, address);
1941 param = g_variant_new("(is)", result, address);
1942 _bt_send_event(BT_HEADSET_EVENT, event,
1945 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
1946 /* Remove data from the connected list */
1947 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
1949 wait_list = _bt_get_audio_wait_data();
1950 if (wait_list == NULL) {
1955 bluetooth_device_address_t device_address;
1957 _bt_set_audio_wait_data_flag(TRUE);
1959 _bt_convert_addr_string_to_type(device_address.addr,
1960 wait_list->address);
1961 _bt_audio_connect(wait_list->req_id, wait_list->type,
1962 &device_address, wait_list->out_param1);
1963 _bt_rel_wait_data();
1964 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
1965 /* Add data to the connected list */
1966 _bt_add_headset_to_list(BT_AUDIO_HSP,
1967 BT_STATE_CONNECTED, address);
1969 wait_list = _bt_get_audio_wait_data();
1970 if (wait_list != NULL &&
1971 (g_strcmp0(wait_list->address, address) == 0))
1972 _bt_rel_wait_data();
1974 BT_INFO("Check A2DP pending connect");
1975 _bt_audio_check_pending_connect();
1978 } else if (strcasecmp(property, "State") == 0) {
1981 g_variant_get(value, "s", &state);
1983 /* This code assumes we support only 1 headset connection */
1984 /* Need to use the headset list, if we support multi-headsets */
1985 if (strcasecmp(state, "Playing") == 0) {
1986 BT_DBG("Playing: Sco Connected");
1987 } else if (strcasecmp(state, "connected") == 0 ||
1988 strcasecmp(state, "disconnected") == 0) {
1989 BT_DBG("connected/disconnected: Sco Disconnected");
1991 BT_ERR("Not handled state - %s", state);
1996 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2000 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2002 _bt_convert_device_path_to_address(path, address);
2004 g_variant_get(value, "i", &spkr_gain);
2005 param = g_variant_new("(isq)", result, address, spkr_gain);
2006 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2010 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2014 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2016 _bt_convert_device_path_to_address(path, address);
2018 g_variant_get(value, "i", &mic_gain);
2019 param = g_variant_new("(isq)", result, address, mic_gain);
2020 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2027 g_variant_unref(value);
2030 void _bt_handle_sink_event(GVariant *msg, const char *path)
2032 GVariantIter value_iter;
2033 char *property = NULL;
2035 bt_headset_wait_t *wait_list;
2037 GVariant *child = NULL;
2038 GVariant *val = NULL;
2039 GVariant *param = NULL;
2040 g_variant_iter_init (&value_iter, msg);
2041 while ((child = g_variant_iter_next_value (&value_iter))) {
2043 g_variant_get(child, "{sv}", &property, &val);
2045 ret_if(property == NULL);
2047 BT_DBG("Property = %s \n", property);
2050 if (strcasecmp(property, "State") == 0) {
2051 int result = BLUETOOTH_ERROR_NONE;
2054 g_variant_get(val, "s", &value);
2055 BT_DBG("value: %s", value);
2057 if (g_strcmp0(value, "disconnected") == 0) {
2060 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2062 _bt_convert_device_path_to_address(path, address);
2064 __bt_set_device_values(FALSE,
2065 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2066 param = g_variant_new("(is)", result, address);
2067 _bt_send_event(BT_HEADSET_EVENT,
2068 BLUETOOTH_EVENT_AV_DISCONNECTED,
2071 /* Remove data from the connected list */
2072 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2073 wait_list = _bt_get_audio_wait_data();
2074 if (wait_list == NULL) {
2077 g_variant_unref(val);
2078 g_variant_unref(child);
2083 if (((wait_list->type == BT_AUDIO_ALL) &&
2084 (wait_list->ag_flag == TRUE)) ||
2085 (wait_list->type == BT_AUDIO_A2DP) ||
2086 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2087 bluetooth_device_address_t device_address;
2088 _bt_convert_addr_string_to_type(
2089 device_address.addr,
2090 wait_list->address);
2092 _bt_audio_connect(wait_list->req_id,
2095 wait_list->out_param1);
2098 }else if (strcasecmp(value, "Connected") == 0) {
2100 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2101 bluetooth_device_address_t device_address;
2104 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2106 _bt_convert_device_path_to_address(path, address);
2108 __bt_set_device_values(TRUE,
2109 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2110 param = g_variant_new("(is)", result, address);
2111 _bt_send_event(BT_HEADSET_EVENT,
2112 BLUETOOTH_EVENT_AV_CONNECTED,
2114 /* Check for existing Media device to disconnect */
2115 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2118 /* Match connected device address */
2119 if (g_strcmp0(connected_address, address) != 0) {
2120 /* Convert BD adress from string type */
2121 _bt_convert_addr_string_to_type(
2122 device_address.addr,
2124 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2125 &device_address, NULL);
2129 /* Add data to the connected list */
2130 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2131 BT_STATE_CONNECTED, address);
2138 g_variant_unref(val);
2139 g_variant_unref(child);
2143 void _bt_handle_agent_event(GVariant *msg, const char *member)
2145 int result = BLUETOOTH_ERROR_NONE;
2146 char *address = NULL;
2149 GVariant *param = NULL;
2150 ret_if(member == NULL);
2152 if (strcasecmp(member, "ObexAuthorize") == 0) {
2153 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2154 param = g_variant_new("(iss)", result, address, name);
2155 _bt_send_event(BT_OPP_SERVER_EVENT,
2156 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2160 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2161 bt_rfcomm_server_info_t *server_info;
2163 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2165 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2166 ret_if(server_info == NULL);
2167 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2168 param = g_variant_new("(isssn)", result, address, uuid, name,
2169 server_info->control_fd);
2170 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2171 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2179 static int __bt_get_object_path(GVariant *msg, char **path)
2181 g_variant_get(msg, "(o*)", path, NULL);
2183 return BLUETOOTH_ERROR_INTERNAL;
2185 return BLUETOOTH_ERROR_NONE;
2188 static void __bt_devices_list_free(void)
2190 bt_cache_info_t *cache_info;
2193 node = g_list_first(p_cache_list);
2195 while (node != NULL){
2196 cache_info = (bt_cache_info_t *)node->data;
2197 p_cache_list = g_list_remove(p_cache_list, cache_info);
2198 __bt_free_cache_info(cache_info);
2200 node = g_list_next(node);
2204 static int __bt_parse_event(GVariant *msg)
2208 char *interface_name= NULL;
2209 GVariant *inner_iter = NULL;
2211 g_variant_iter_init(&iter, msg);
2213 while ((child = g_variant_iter_next_value(&iter))) {
2214 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
2215 if (g_strcmp0(interface_name,
2216 BT_DEVICE_INTERFACE) == 0) {
2217 g_variant_unref(inner_iter);
2218 g_variant_unref(child);
2219 return BT_DEVICE_EVENT;
2220 } else if (g_strcmp0(interface_name,
2221 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2222 g_variant_unref(inner_iter);
2223 g_variant_unref(child);
2224 return BT_MEDIA_TRANSFER_EVENT;
2225 } else if (g_strcmp0(interface_name,
2226 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2227 g_variant_unref(inner_iter);
2228 g_variant_unref(child);
2229 return BT_AVRCP_CONTROL_EVENT;
2231 g_variant_unref(inner_iter);
2232 g_variant_unref(child);
2238 static void __bt_manager_event_filter(GDBusConnection *connection,
2239 const gchar *sender_name,
2240 const gchar *object_path,
2241 const gchar *interface_name,
2242 const gchar *signal_name,
2243 GVariant *parameters,
2246 bt_event_type_t bt_event = 0x00;
2247 int result = BLUETOOTH_ERROR_NONE;
2249 char *obj_path = NULL;
2250 GVariant *param = NULL;
2251 if (signal_name == NULL)
2253 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2254 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2256 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0)
2257 _bt_handle_adapter_added();
2259 bt_event = __bt_parse_event(value);
2260 if (bt_event == BT_DEVICE_EVENT) {
2261 bt_cache_info_t *cache_info;
2262 bt_remote_dev_info_t *dev_info;
2264 ret_if(_bt_is_discovering() == FALSE &&
2265 _bt_is_le_scanning() == FALSE);
2267 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2268 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2269 cache_info->dev_info = dev_info;
2271 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2272 BT_ERR("Fail to parse the properies");
2273 __bt_free_cache_info(cache_info);
2274 g_variant_unref(value);
2278 if (dev_info->addr_type != BDADDR_BREDR) {
2279 /* Whenever emit the property changed from bluez,
2280 some property doesn't reach to bt-service.
2281 So LE device is handled as AdvReport signal */
2282 __bt_free_cache_info(cache_info);
2283 g_variant_unref(value);
2287 if (dev_info->name == NULL)
2288 /* If Remote device name is NULL or still RNR is not done
2289 * then display address as name.
2291 dev_info->name = g_strdup(dev_info->address);
2293 GVariant *uuids = NULL;
2294 GVariantBuilder *builder = NULL;
2296 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2297 for (i=0; i < dev_info->uuid_count; i++) {
2298 g_variant_builder_add(builder, "s",
2299 dev_info->uuids[i]);
2301 uuids = g_variant_new("as", builder);
2302 g_variant_builder_unref(builder);
2303 GVariant *manufacturer_data = NULL;
2304 manufacturer_data = g_variant_new_from_data(
2305 G_VARIANT_TYPE_BYTESTRING,
2306 dev_info->manufacturer_data,
2307 dev_info->manufacturer_data_len,
2309 param = g_variant_new("(isunsbub@asn@ay)", result,
2315 dev_info->connected,
2318 dev_info->manufacturer_data_len,
2320 _bt_send_event(BT_ADAPTER_EVENT,
2321 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2323 p_cache_list = g_list_append(p_cache_list, cache_info);
2324 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2325 BT_DBG("Device path : %s ", obj_path);
2326 _bt_set_control_device_path(obj_path);
2329 g_variant_unref(value);
2330 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2331 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2332 bt_event = BT_MEDIA_TRANSFER_EVENT;
2333 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2334 bt_event = BT_DEVICE_EVENT;
2335 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2336 bt_event = BT_AVRCP_CONTROL_EVENT;
2338 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2339 _bt_handle_adapter_event(parameters, signal_name);
2340 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2341 BT_INFO("Object Path %s", obj_path);
2342 _bt_remove_control_device_path(obj_path);
2345 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2348 char *previous = NULL;
2349 char *current = NULL;
2351 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2352 BT_ERR("Fail to get the owner info");
2356 if (*current != '\0') {
2366 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2367 BT_DBG("Bluetoothd is terminated");
2368 if (_bt_adapter_get_status() != BT_DEACTIVATING) {
2371 _bt_handle_adapter_removed();
2372 __bt_devices_list_free();
2375 _bt_obex_server_check_allocation(&value);
2377 if (value == TRUE) {
2378 /* Check if the obex server was terminated abnormally */
2379 _bt_obex_server_check_termination(name);
2382 _bt_rfcomm_server_check_existence(&value);
2384 if (value == TRUE) {
2385 /* The obex server was terminated abnormally */
2386 _bt_rfcomm_server_check_termination(name);
2389 /* Stop advertising started by terminated process */
2390 _bt_stop_advertising_by_terminated_process(name);
2392 _bt_stop_le_scan(name);
2396 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2397 const char *path = object_path;
2399 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2400 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2403 _bt_handle_property_changed_event(parameters, object_path);
2404 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2405 _bt_handle_adapter_event(parameters, signal_name);
2406 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2407 _bt_handle_input_event(parameters, object_path);
2408 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2409 _bt_handle_network_server_event(parameters, signal_name);
2410 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2411 _bt_handle_headset_event(parameters, object_path);
2412 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2413 _bt_handle_sink_event(parameters, object_path);
2414 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2415 _bt_handle_agent_event(parameters, signal_name);
2416 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2417 _bt_handle_device_event(parameters, signal_name, object_path);
2423 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2426 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2427 char *interface_name = NULL;
2429 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2430 retv_if(interface_name == NULL, FALSE);
2432 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2433 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2441 static void __bt_obexd_event_filter(GDBusConnection *connection,
2442 const gchar *sender_name,
2443 const gchar *object_path,
2444 const gchar *interface_name,
2445 const gchar *signal_name,
2446 GVariant *parameters,
2449 const char *member = signal_name;
2450 char *obj_path = NULL;
2451 ret_if(member == NULL);
2453 if (strcasecmp(member, "InterfacesAdded") == 0) {
2454 if (__bt_get_object_path(parameters, &obj_path)) {
2455 BT_ERR("Fail to get the path");
2458 BT_INFO("object_path = [%s]", object_path);
2460 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2461 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2462 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2467 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2468 BT_DBG("Obex_Server_Session_Transfer connected");
2469 _bt_obex_transfer_connected();
2472 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2473 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2474 if (__bt_get_object_path(parameters, &obj_path)) {
2475 BT_ERR("Fail to get the path");
2478 BT_INFO("object_path = [%s]", object_path);
2480 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2481 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2482 BT_DBG("Call PBAP Disconnected");
2483 _bt_obex_pbap_client_disconnect(obj_path);
2486 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2487 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2492 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2493 BT_DBG("Obex_Server_Session_Transfer disconnected");
2494 _bt_obex_transfer_disconnected();
2497 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2498 const char *path = object_path;
2500 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2501 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2502 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2503 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2504 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2508 _bt_handle_property_changed_event(parameters, path);
2514 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2518 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2519 char *interface_name = NULL;
2521 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2523 retv_if(interface_name == NULL, FALSE);
2525 if (strcasecmp(interface_name,
2526 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2537 static void __bt_opc_event_filter(GDBusConnection *connection,
2538 const gchar *sender_name,
2539 const gchar *object_path,
2540 const gchar *interface_name,
2541 const gchar *signal_name,
2542 GVariant *parameters,
2545 const char *member = signal_name;
2546 char *obj_path = NULL;
2547 if (strcasecmp(member, "InterfacesAdded") == 0) {
2548 BT_DBG("InterfacesAdded");
2549 }else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2551 if (__bt_get_object_path(parameters, &obj_path)) {
2552 BT_ERR("Fail to get the path");
2556 BT_DBG("object_path =%s",obj_path);
2558 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2559 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2560 || strstr(obj_path, "transfer") == NULL) {
2564 else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2565 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2566 BT_DBG("Going to call opc disconnected");
2567 _bt_opc_disconnected(obj_path);
2570 _bt_sending_files();
2572 }else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE){
2573 char *path = (char *)object_path;
2574 BT_INFO("object_path %s", path);
2575 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2576 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2577 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2581 _bt_opc_property_changed_event(parameters, path);
2587 int _bt_opp_client_event_init(void)
2589 GError *error = NULL;
2591 if (opc_obexd_conn == NULL) {
2592 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2594 if (!opc_obexd_conn) {
2596 BT_ERR("Unable to connect to dbus: %s", error->message);
2597 g_clear_error(&error);
2599 return BLUETOOTH_ERROR_INTERNAL;
2603 if (_bt_register_service_event(opc_obexd_conn,
2604 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2605 g_object_unref(opc_obexd_conn);
2606 opc_obexd_conn = NULL;
2607 return BLUETOOTH_ERROR_INTERNAL;
2610 return BLUETOOTH_ERROR_NONE;
2613 void _bt_opp_client_event_deinit(void)
2615 if (opc_obexd_conn) {
2616 _bt_unregister_service_event(opc_obexd_conn,
2617 BT_OPP_CLIENT_EVENT);
2618 g_object_unref(opc_obexd_conn);
2619 opc_obexd_conn = NULL;
2623 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2629 static int subs_interface_added_id = -1;
2630 static int subs_interface_removed_id = -1;
2631 static int subs_name_owner_id = -1;
2632 static int subs_property_id = -1;
2633 static int subs_adapter_id = -1;
2636 if (subs_interface_added_id == -1) {
2637 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2638 NULL, BT_MANAGER_INTERFACE,
2639 BT_INTERFACES_ADDED, NULL, NULL, 0,
2640 __bt_manager_event_filter,
2643 if (subs_interface_removed_id == -1) {
2644 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2645 NULL, BT_MANAGER_INTERFACE,
2646 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2647 __bt_manager_event_filter,
2650 if (subs_name_owner_id == -1) {
2651 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
2652 NULL, BT_FREEDESKTOP_INTERFACE,
2653 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
2654 __bt_manager_event_filter,
2657 if (subs_property_id == -1) {
2658 subs_property_id = g_dbus_connection_signal_subscribe(conn,
2659 NULL, BT_PROPERTIES_INTERFACE,
2660 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2661 __bt_manager_event_filter,
2664 if (subs_adapter_id == -1) {
2665 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
2666 NULL, BT_ADAPTER_INTERFACE,
2667 NULL, NULL, NULL, 0,
2668 __bt_manager_event_filter,
2672 if (subs_interface_added_id != -1) {
2673 g_dbus_connection_signal_unsubscribe(conn,
2674 subs_interface_added_id);
2675 subs_interface_added_id = -1;
2677 if (subs_interface_removed_id != -1) {
2678 g_dbus_connection_signal_unsubscribe(conn,
2679 subs_interface_removed_id);
2680 subs_interface_removed_id = -1;
2682 if (subs_name_owner_id != -1) {
2683 g_dbus_connection_signal_unsubscribe(conn,
2684 subs_name_owner_id);
2685 subs_name_owner_id = -1;
2687 if (subs_property_id != -1) {
2688 g_dbus_connection_signal_unsubscribe(conn,
2690 subs_property_id = -1;
2692 if (subs_adapter_id == -1) {
2693 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
2694 subs_adapter_id = -1;
2700 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
2706 static int subs_device_id = -1;
2709 if (subs_device_id == -1) {
2710 subs_device_id = g_dbus_connection_signal_subscribe(conn,
2711 NULL, BT_DEVICE_INTERFACE,
2712 NULL, NULL, NULL, 0,
2713 __bt_manager_event_filter,
2717 if (subs_device_id != -1) {
2718 g_dbus_connection_signal_unsubscribe(conn,
2720 subs_device_id = -1;
2726 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
2732 static int subs_input_id = -1;
2735 if (subs_input_id == -1) {
2736 subs_input_id = g_dbus_connection_signal_subscribe(conn,
2737 NULL, BT_INPUT_INTERFACE,
2738 NULL, NULL, NULL, 0,
2739 __bt_manager_event_filter,
2743 if (subs_input_id != -1) {
2744 g_dbus_connection_signal_unsubscribe(conn,
2752 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
2758 static int subs_serv_id = -1;
2759 static int subs_client_id = -1;
2762 if (subs_serv_id == -1) {
2763 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
2764 NULL, BT_NETWORK_SERVER_INTERFACE,
2765 NULL, NULL, NULL, 0,
2766 __bt_manager_event_filter,
2769 if (subs_client_id == -1) {
2770 subs_client_id = g_dbus_connection_signal_subscribe(conn,
2771 NULL, BT_NETWORK_CLIENT_INTERFACE,
2772 NULL, NULL, NULL, 0,
2773 __bt_manager_event_filter,
2777 if (subs_serv_id != -1) {
2778 g_dbus_connection_signal_unsubscribe(conn,
2782 if (subs_client_id != -1) {
2783 g_dbus_connection_signal_unsubscribe(conn,
2785 subs_client_id = -1;
2791 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
2797 static int subs_headset_id = -1;
2798 static int subs_sink_id = -1;
2801 if (subs_headset_id == -1) {
2802 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
2803 NULL, BT_HEADSET_INTERFACE,
2804 NULL, NULL, NULL, 0,
2805 __bt_manager_event_filter,
2808 if (subs_sink_id == -1) {
2809 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
2810 NULL, BT_SINK_INTERFACE,
2811 NULL, NULL, NULL, 0,
2812 __bt_manager_event_filter,
2816 if (subs_headset_id != -1) {
2817 g_dbus_connection_signal_unsubscribe(conn,
2819 subs_headset_id = -1;
2821 if (subs_sink_id != -1) {
2822 g_dbus_connection_signal_unsubscribe(conn,
2830 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
2836 static int subs_opp_server_interface_added_id = -1;
2837 static int subs_opp_server_interface_removed_id = -1;
2838 static int subs_opp_server_property_id = -1;
2842 if (subs_opp_server_interface_added_id == -1) {
2843 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2844 NULL, BT_MANAGER_INTERFACE,
2845 BT_INTERFACES_ADDED, NULL, NULL, 0,
2846 __bt_obexd_event_filter,
2849 if (subs_opp_server_interface_removed_id == -1) {
2850 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2851 NULL, BT_MANAGER_INTERFACE,
2852 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2853 __bt_obexd_event_filter,
2856 if (subs_opp_server_property_id == -1) {
2857 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
2858 NULL, BT_PROPERTIES_INTERFACE,
2859 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2860 __bt_obexd_event_filter,
2864 if (subs_opp_server_interface_added_id != -1) {
2865 g_dbus_connection_signal_unsubscribe(conn,
2866 subs_opp_server_interface_added_id);
2867 subs_opp_server_interface_added_id = -1;
2869 if (subs_opp_server_interface_removed_id != -1) {
2870 g_dbus_connection_signal_unsubscribe(conn,
2871 subs_opp_server_interface_removed_id);
2872 subs_opp_server_interface_removed_id = -1;
2874 if (subs_opp_server_property_id != -1) {
2875 g_dbus_connection_signal_unsubscribe(conn,
2876 subs_opp_server_property_id);
2877 subs_opp_server_property_id = -1;
2883 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
2889 static int subs_opp_client_interface_added_id = -1;
2890 static int subs_opp_client_interface_removed_id = -1;
2891 static int subs_opp_client_property_id = -1;
2895 if (subs_opp_client_interface_added_id == -1) {
2896 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2897 NULL, BT_MANAGER_INTERFACE,
2898 BT_INTERFACES_ADDED, NULL, NULL, 0,
2899 __bt_opc_event_filter,
2902 if (subs_opp_client_interface_removed_id == -1) {
2903 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2904 NULL, BT_MANAGER_INTERFACE,
2905 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2906 __bt_opc_event_filter,
2909 if (subs_opp_client_property_id == -1) {
2910 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
2911 NULL, BT_PROPERTIES_INTERFACE,
2912 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2913 __bt_opc_event_filter,
2917 if (subs_opp_client_interface_added_id != -1) {
2918 g_dbus_connection_signal_unsubscribe(conn,
2919 subs_opp_client_interface_added_id);
2920 subs_opp_client_interface_added_id = -1;
2922 if (subs_opp_client_interface_removed_id != -1) {
2923 g_dbus_connection_signal_unsubscribe(conn,
2924 subs_opp_client_interface_removed_id);
2925 subs_opp_client_interface_removed_id = -1;
2927 if (subs_opp_client_property_id != -1) {
2928 g_dbus_connection_signal_unsubscribe(conn,
2929 subs_opp_client_property_id);
2930 subs_opp_client_property_id = -1;
2936 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
2942 static int subs_a2dp_source_id = -1;
2943 static int subs_a2dp_sink_id = -1;
2946 if (subs_a2dp_source_id == -1) {
2947 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
2948 NULL, BT_A2DP_SOURCE_INTERFACE,
2949 NULL, NULL, NULL, 0,
2950 __bt_opc_event_filter,
2953 if (subs_a2dp_sink_id == -1) {
2954 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
2955 NULL, BT_SINK_INTERFACE,
2956 NULL, NULL, NULL, 0,
2957 __bt_opc_event_filter,
2961 if (subs_a2dp_source_id != -1) {
2962 g_dbus_connection_signal_unsubscribe(conn,
2963 subs_a2dp_source_id);
2964 subs_a2dp_source_id = -1;
2966 if (subs_a2dp_sink_id != -1) {
2967 g_dbus_connection_signal_unsubscribe(conn,
2969 subs_a2dp_sink_id = -1;
2975 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
2979 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2981 switch (event_type) {
2982 case BT_MANAGER_EVENT:
2983 _bt_register_manager_subscribe_signal(g_conn, TRUE);
2985 case BT_DEVICE_EVENT:
2986 _bt_register_device_subscribe_signal(g_conn, TRUE);
2989 _bt_register_input_subscribe_signal(g_conn, TRUE);
2991 case BT_NETWORK_EVENT:
2992 _bt_register_network_subscribe_signal(g_conn, TRUE);
2994 case BT_HEADSET_EVENT:
2995 _bt_register_audio_subscribe_signal(g_conn, TRUE);
2998 case BT_OPP_SERVER_EVENT:
2999 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3000 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3002 case BT_OPP_CLIENT_EVENT:
3003 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3004 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3006 case BT_A2DP_SOURCE_EVENT:
3007 BT_INFO("A2dp Source event");
3008 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3011 BT_ERR("Unknown event");
3012 return BLUETOOTH_ERROR_INTERNAL;
3015 return BLUETOOTH_ERROR_NONE;
3018 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3022 ret_if(g_conn == NULL);
3024 switch (event_type) {
3025 case BT_MANAGER_EVENT:
3026 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3027 _bt_register_device_subscribe_signal(g_conn, FALSE);
3028 _bt_register_input_subscribe_signal(g_conn, FALSE);
3029 _bt_register_network_subscribe_signal(g_conn, FALSE);
3030 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3032 case BT_OPP_SERVER_EVENT:
3033 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3035 case BT_OPP_CLIENT_EVENT:
3036 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3039 BT_ERR("Unknown event");
3046 static int __bt_init_manager_receiver(void)
3050 GError *error = NULL;
3052 if (manager_conn == NULL) {
3053 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3054 if (error != NULL) {
3055 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3056 g_clear_error(&error);
3058 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3061 if (_bt_register_service_event(manager_conn,
3062 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3064 if (_bt_register_service_event(manager_conn,
3065 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3068 if (_bt_register_service_event(manager_conn,
3069 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3072 if (_bt_register_service_event(manager_conn,
3073 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3076 if (_bt_register_service_event(manager_conn,
3077 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3079 return BLUETOOTH_ERROR_NONE;
3082 g_object_unref(manager_conn);
3083 manager_conn = NULL;
3088 return BLUETOOTH_ERROR_INTERNAL;
3091 static int __bt_init_obexd_receiver(void)
3095 GError *error = NULL;
3097 if (obexd_conn == NULL) {
3098 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3099 if (error != NULL) {
3100 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3101 g_clear_error(&error);
3103 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3106 if (_bt_register_service_event(obexd_conn,
3107 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3108 BT_ERR("Error while registering service event");
3109 g_object_unref(obexd_conn);
3111 return BLUETOOTH_ERROR_INTERNAL;
3116 return BLUETOOTH_ERROR_NONE;
3119 /* To receive the event from bluez */
3120 int _bt_init_service_event_receiver(void)
3126 result = __bt_init_manager_receiver();
3127 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3129 result = __bt_init_obexd_receiver();
3130 if (result != BLUETOOTH_ERROR_NONE)
3131 BT_ERR("Fail to init obexd receiver");
3135 return BLUETOOTH_ERROR_NONE;
3138 void _bt_deinit_service_event_receiver(void)
3142 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3144 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3147 g_object_unref(manager_conn);
3148 manager_conn = NULL;
3152 g_object_unref(obexd_conn);
3157 g_source_remove(event_id);