4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
28 #include <vconf-internal-bt-keys.h>
30 #include "bluetooth-api.h"
31 #include "bt-internal-types.h"
33 #include "bt-service-common.h"
34 #include "bt-service-event.h"
35 #include "bt-service-main.h"
36 #include "bt-service-adapter.h"
37 #include "bt-service-adapter-le.h"
38 #include "bt-service-device.h"
39 #include "bt-service-avrcp.h"
40 #include "bt-service-obex-server.h"
41 #include "bt-service-rfcomm-server.h"
42 #include "bt-service-audio.h"
43 #include "bt-service-agent.h"
44 #include "bt-service-pbap.h"
45 #include "bt-service-headset-connection.h"
46 #include "bt-service-avrcp-controller.h"
48 #include "bt-service-opp-client.h"
50 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
51 static GDBusConnection *manager_conn;
52 static GDBusConnection *obexd_conn;
53 static GDBusConnection *opc_obexd_conn;
55 static GList *p_cache_list = NULL;
57 static guint event_id;
58 guint nap_connected_device_count = 0;
59 static guint hid_connected_device_count = 0;
60 static GList *p_adv_ind_list;
63 bt_remote_dev_info_t *dev_info;
67 * obexd connection type
75 OBEX_PCSUITE = (1 << 6),
76 OBEX_SYNCEVOLUTION = (1 << 7),
78 } bluetooth_obex_connection_type_t;
80 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
81 void _bt_opc_property_changed_event(GVariant *msg, char *path);
82 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
83 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
84 void _bt_opp_client_event_deinit(void);
85 void _bt_handle_network_client_event(GVariant *msg_iter,
87 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
90 static void __bt_free_bt_le_adv_info_t(bt_le_adv_info_t *adv_info)
92 g_free(adv_info->addr);
93 g_free(adv_info->data);
97 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
100 bt_le_adv_info_t *adv_info = NULL;
101 GList *current = g_list_first((GList *)p_adv_ind_list);
102 while(current && current->data) {
103 adv_info = (bt_le_adv_info_t *)current->data;
104 retv_if(adv_info && !g_strcmp0(adv_info->addr, addr), adv_info);
105 current = g_list_next(current);
110 static void __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
113 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
114 BT_ERR("adv_info is already added");
115 __bt_free_bt_le_adv_info_t(adv_info);
118 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
121 static void __bt_del_adv_ind_info(char *addr)
124 ret_if(!p_adv_ind_list);
125 bt_le_adv_info_t *adv_info = NULL;
126 GList *current = g_list_first((GList *)p_adv_ind_list);
127 while(current && current->data) {
128 adv_info = (bt_le_adv_info_t *)current->data;
129 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
130 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
131 __bt_free_bt_le_adv_info_t(adv_info);
134 current = g_list_next(current);
138 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
140 ret_if(cache_info == NULL);
141 _bt_free_device_info(cache_info->dev_info);
145 static gboolean __bt_parse_device_properties(GVariant *item,
146 bt_remote_dev_info_t *dev_info)
155 g_variant_iter_init(&iter, item);
156 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
157 if (strcasecmp(key, "Address") == 0) {
158 dev_info->address = g_variant_dup_string(val, &len);
159 } else if (strcasecmp(key, "Class") == 0) {
160 dev_info->class = g_variant_get_uint32(val);
161 } else if (strcasecmp(key, "name") == 0) {
162 if (dev_info->name == NULL)
163 dev_info->name = g_variant_dup_string(val, &len);
164 } else if (strcasecmp(key, "Connected") == 0) {
165 dev_info->connected = g_variant_get_uint32(val);
166 } else if (strcasecmp(key, "paired") == 0) {
167 dev_info->paired = g_variant_get_boolean(val);
168 } else if (strcasecmp(key, "Trusted") == 0) {
169 dev_info->trust = g_variant_get_boolean(val);
170 } else if (strcasecmp(key, "RSSI") == 0) {
171 dev_info->rssi = g_variant_get_int16(val);
172 } else if (strcasecmp(key, "LastAddrType") == 0) {
173 dev_info->addr_type = g_variant_get_byte(val);
174 } else if (strcasecmp(key, "UUIDs") == 0) {
178 size = g_variant_get_size(val);
181 uuid_value = (char **)g_variant_get_strv(val, &size);
182 if (dev_info->uuids == NULL)
183 dev_info->uuids = g_malloc0(sizeof(char *) * size);
185 for (i = 0; uuid_value[i] != NULL; i++) {
186 dev_info->uuid_count++;
187 dev_info->uuids[i] = g_strdup(uuid_value[i]);
191 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
192 g_variant_get(val, "(i)", &dev_info->manufacturer_data_len);
193 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
194 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
195 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
198 if (dev_info->manufacturer_data_len == 0)
199 dev_info->manufacturer_data = g_strdup("");
200 } else if (strcasecmp(key, "ManufacturerData") == 0) {
202 GVariant *manufacturer_var;
203 g_variant_get(val, "@ay", &manufacturer_var);
204 len = g_variant_get_size(manufacturer_var);
206 char *manufacturer_data = (char *)g_variant_get_data(manufacturer_var);
207 dev_info->manufacturer_data = g_malloc0(len);
208 memcpy(dev_info->manufacturer_data, manufacturer_data,
211 g_variant_unref(manufacturer_var);
219 static gboolean __bt_parse_interface(GVariant *msg,
220 bt_remote_dev_info_t *dev_info)
223 GVariant *optional_param;
226 char *interface_name= NULL;
227 GVariant *inner_iter = NULL;
228 g_variant_get(msg, "(&o@a{sa{sv}})",
229 &path, &optional_param);
230 g_variant_iter_init(&iter, optional_param);
232 while ((child = g_variant_iter_next_value(&iter))) {
233 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
234 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
235 BT_DBG("Found a device: %s", path);
236 if (__bt_parse_device_properties(inner_iter,
237 dev_info) == FALSE) {
238 g_variant_unref(inner_iter);
239 g_variant_unref(child);
240 g_variant_unref(optional_param);
241 BT_ERR("Fail to parse the properies");
244 g_variant_unref(inner_iter);
245 g_variant_unref(child);
246 g_variant_unref(optional_param);
250 g_variant_unref(inner_iter);
251 g_variant_unref(child);
254 g_variant_unref(optional_param);
259 static int __bt_get_owner_info(GVariant *msg, char **name,
260 char **previous, char **current)
262 g_variant_get(msg, "(sss)", name, previous, current);
263 return BLUETOOTH_ERROR_NONE;
266 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
267 char **name, char **uuid)
269 g_variant_get(msg, "(sss)", address, name, uuid);
270 return BLUETOOTH_ERROR_NONE;
273 void __bt_set_device_values(gboolean connected, int state)
275 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
277 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) {
278 BT_ERR("vconf_get_int failed");
281 if (connected == TRUE)
282 bt_device_state |= state;
283 else if (bt_device_state & state)
284 bt_device_state ^= state;
286 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) {
287 BT_ERR("vconf_set_int failed");
291 gboolean _bt_discovery_finished_cb(gpointer user_data)
293 int result = BLUETOOTH_ERROR_NONE;
295 GVariant *param = NULL;
296 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
297 if (_bt_get_cancel_by_user() == TRUE) {
298 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
301 _bt_set_cancel_by_user(FALSE);
302 _bt_disable_all_scanner_status();
303 _bt_set_discovery_status(FALSE);
304 param = g_variant_new("(i)", result);
305 _bt_send_event(BT_ADAPTER_EVENT,
306 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
313 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
315 int result = BLUETOOTH_ERROR_NONE;
317 GVariant *param = NULL;
318 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
319 if (_bt_get_cancel_by_user() == TRUE) {
320 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
323 _bt_set_cancel_by_user(FALSE);
324 _bt_set_le_scan_status(FALSE);
325 param = g_variant_new("(i)", result);
326 _bt_send_event(BT_LE_ADAPTER_EVENT,
327 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
334 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
338 ret_if(address == NULL);
341 bt_cache_info_t *cache_info;
342 bt_remote_dev_info_t *dev_info;
344 node = g_list_first(p_cache_list);
346 while (node != NULL){
347 cache_info = (bt_cache_info_t *)node->data;
349 if (cache_info == NULL) {
350 node = g_list_next(node);
354 dev_info = cache_info->dev_info;
355 if (strcasecmp(dev_info->address,
357 BT_DBG("Device Found");
358 if (paired_status == TRUE)
359 cache_info->dev_info->paired = TRUE;
361 cache_info->dev_info->paired = FALSE;
364 node = g_list_next(node);
369 static void __bt_device_remote_connected_properties(
370 bt_remote_dev_info_t *remote_dev_info,
371 char *address, gboolean connected)
373 int result = BLUETOOTH_ERROR_NONE;
375 GVariant *param = NULL;
378 if (remote_dev_info->uuid_count > 0 ) {
379 for (i = 0; i<remote_dev_info->uuid_count; i++) {
380 char *uuid = remote_dev_info->uuids[i];
381 if (strcasecmp(uuid, HID_UUID) == 0){
382 int event = BLUETOOTH_EVENT_NONE;
384 event = (connected == TRUE) ?
385 BLUETOOTH_HID_CONNECTED :
386 BLUETOOTH_HID_DISCONNECTED;
387 param = g_variant_new("(is)", result,
389 _bt_send_event(BT_HID_EVENT, event,
399 void _bt_handle_adapter_event(GVariant *msg, const char *member)
403 int result = BLUETOOTH_ERROR_NONE;
404 GVariant *param = NULL;
405 ret_if(member == NULL);
407 if (strcasecmp(member, "DeviceCreated") == 0) {
408 char *object_path = NULL;
410 bt_remote_dev_info_t *remote_dev_info;
412 ret_if(_bt_is_device_creating() == FALSE);
414 /* Bonding from remote device */
415 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
417 g_variant_get(msg, "(&o)", &object_path);
418 _bt_convert_device_path_to_address((const char*)object_path, address);
420 remote_dev_info = _bt_get_remote_device_info(address);
421 if (remote_dev_info == NULL) {
426 _bt_free_device_info(remote_dev_info);
428 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
429 char *object_path = NULL;
431 bt_cache_info_t *cache_info;
432 bt_remote_dev_info_t *dev_info;
435 /* Bonding from remote device */
436 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
437 g_variant_get(msg, "(&o)", &object_path);
439 /* Fix : NULL_RETURNS */
443 _bt_convert_device_path_to_address((const char *)object_path, address);
445 node = g_list_first(p_cache_list);
447 while (node != NULL){
448 cache_info = (bt_cache_info_t *)node->data;
450 if (cache_info == NULL) {
451 node = g_list_next(node);
455 dev_info = cache_info->dev_info;
456 if (strcasecmp(dev_info->address,
458 p_cache_list = g_list_remove(p_cache_list,
460 __bt_free_cache_info(cache_info);
463 node = g_list_next(node);
466 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
467 BT_DBG("Advertising Enabled");
472 gboolean status = FALSE;
474 g_variant_get(msg, "(ib)", &slot_id, &status);
476 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
478 /* Send event to application */
479 _bt_set_advertising_status(slot_id, status);
481 sender = _bt_get_adv_slot_owner(slot_id);
482 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
485 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
487 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
488 param = g_variant_new("(ii)", result,
490 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
494 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
495 __bt_unregister_adv_slot_owner(slot_id);
496 } else if (strcasecmp(member, "RssiEnabled") == 0) {
497 BT_DBG("RSSI Enabled");
498 gboolean status = FALSE;
499 char *address = NULL;
501 g_variant_get(msg,"(sib)", &address, &link_type, &status);
503 BT_DBG("RSSI Enabled [%s %d]", address, status);
504 param = g_variant_new("(isib)", result,
505 address, link_type, status);
506 _bt_send_event(BT_DEVICE_EVENT,
507 BLUETOOTH_EVENT_RSSI_ENABLED,
510 } else if (strcasecmp(member, "RssiAlert") == 0) {
511 BT_DBG("RSSI Alert");
515 char *address = NULL;
516 g_variant_get(msg,"(siii)", &address, &link_type, &alert_type, &rssi_dbm);
518 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
519 address, alert_type, rssi_dbm);
520 param = g_variant_new("(isiii)", result,
521 address, link_type, alert_type, rssi_dbm);
522 _bt_send_event(BT_DEVICE_EVENT,
523 BLUETOOTH_EVENT_RSSI_ALERT,
526 } else if (strcasecmp(member, "RawRssi") == 0) {
530 char *address = NULL;
531 g_variant_get(msg,"(sii)", &address, &link_type, &rssi_dbm);
533 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
534 address, link_type, rssi_dbm);
535 param = g_variant_new("(isii)", result,
536 address, link_type, rssi_dbm);
537 _bt_send_event(BT_DEVICE_EVENT,
538 BLUETOOTH_EVENT_RAW_RSSI,
541 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
542 BT_ERR_C("Hardware error received from BLUEZ");
543 _bt_recover_adapter();
544 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
545 BT_ERR_C("Tx timeout error received from BLUEZ");
546 _bt_recover_adapter();
551 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
553 GDBusProxy *adapter_proxy;
555 int result = BLUETOOTH_ERROR_NONE;
556 GVariantIter value_iter;
557 GVariant *val = NULL;
559 char *property = NULL;
560 GVariant *param = NULL;
561 g_variant_iter_init (&value_iter, msg);
562 while ((g_variant_iter_loop (&value_iter,"{sv}", &property, &val))) {
563 BT_INFO("Property %s", property);
565 if (strcasecmp(property, "Discovering") == 0) {
566 gboolean discovering = FALSE;
567 g_variant_get(val, "b", &discovering);
568 /* Send event to application */
569 BT_DBG("Discovering %d", discovering);
570 if (discovering == TRUE) {
571 _bt_set_discovery_status(TRUE);
572 param = g_variant_new("(i)", result);
573 _bt_send_event(BT_ADAPTER_EVENT,
574 BLUETOOTH_EVENT_DISCOVERY_STARTED,
577 ret_if(event_id > 0);
579 adapter_proxy = _bt_get_adapter_proxy();
580 ret_if(adapter_proxy == NULL);
582 /* Need to stop searching */
583 g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
585 G_DBUS_CALL_FLAGS_NONE,
589 BT_ERR("Dbus Error : %s", err->message);
593 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
594 (GSourceFunc)_bt_discovery_finished_cb, NULL);
596 } else if (strcasecmp(property, "LEDiscovering") == 0) {
597 gboolean le_discovering = FALSE;
599 g_variant_get(val, "b", &le_discovering);
600 /* Send event to application */
601 if (le_discovering == TRUE) {
602 _bt_set_le_scan_status(TRUE);
603 param = g_variant_new("(i)", result);
604 _bt_send_event(BT_LE_ADAPTER_EVENT,
605 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
608 ret_if(event_id > 0);
610 adapter_proxy = _bt_get_adapter_proxy();
611 ret_if(adapter_proxy == NULL);
613 /* Need to stop searching */
614 g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
616 G_DBUS_CALL_FLAGS_NONE,
620 BT_ERR("Dbus Error %s", err->message);
624 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
625 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
627 } else if (strcasecmp(property, "Name") == 0) {
629 g_variant_get(val, "s", &name);
630 param = g_variant_new("(is)", result, name);
631 /* Send event to application */
632 _bt_send_event(BT_ADAPTER_EVENT,
633 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
636 } else if (strcasecmp(property, "Alias") == 0) {
638 g_variant_get(val, "s", &alias);
639 param = g_variant_new("(is)", result, alias);
640 /* Send event to application */
641 _bt_send_event(BT_ADAPTER_EVENT,
642 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
645 } else if (strcasecmp(property, "Discoverable") == 0) {
646 gboolean discoverable = FALSE;
648 g_variant_get(val, "b", &discoverable);
649 BT_DBG("discoverable %d", discoverable);
651 if (discoverable == FALSE) {
652 if (_bt_get_discoverable_timeout_property() > 0) {
654 adapter_proxy = _bt_get_adapter_properties_proxy();
655 ret_if(adapter_proxy == NULL);
656 g_dbus_proxy_call_sync(adapter_proxy, "Set",
657 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
658 "DiscoverableTimeout",
659 g_variant_new("i", time)),
660 G_DBUS_CALL_FLAGS_NONE,
665 BT_ERR("StopLEDiscovery Failed: %s", err->message);
670 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
672 /* Send event to application */
673 BT_INFO("[Connectable]");
674 param = g_variant_new("(in)", result, mode);
675 _bt_send_event(BT_ADAPTER_EVENT,
676 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
679 _bt_get_discoverable_mode(&mode);
681 /* Event will be sent by "DiscoverableTimeout" signal */
682 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
684 g_variant_unref(val);
688 /* Send event to application */
689 BT_INFO("[General Discoverable]");
690 param = g_variant_new("(in)", result, mode);
691 _bt_send_event(BT_ADAPTER_EVENT,
692 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
695 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
696 _bt_get_discoverable_mode(&mode);
698 /* Event was already sent by "Discoverable" signal */
699 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
700 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
702 g_variant_unref(val);
706 /* Send event to application */
707 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
708 _bt_get_discoverable_timeout_property());
709 param = g_variant_new("(in)", result, mode);
710 _bt_send_event(BT_ADAPTER_EVENT,
711 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
713 } else if (strcasecmp(property, "Powered") == 0) {
714 /* TODO: Need to check this operation!! */
715 gboolean powered = FALSE;
718 g_variant_get(val, "b" ,&powered);
719 BT_DBG("Powered = %d", powered);
720 if (powered == FALSE) {
722 _bt_handle_adapter_removed();
724 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
725 bt_state != VCONFKEY_BT_STATUS_OFF) {
726 _bt_disable_adapter();
729 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
730 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
731 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
736 _bt_handle_adapter_added();
739 } else if (strcasecmp(property, "Connectable") == 0) {
740 gboolean connectable = FALSE;
742 g_variant_get(val, "b", &connectable);
744 BT_DBG("Connectable property is changed : %d", connectable);
745 param = g_variant_new("(b)", connectable);
746 _bt_send_event(BT_ADAPTER_EVENT,
747 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
749 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
750 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
752 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
753 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
756 GVariantIter *iter = NULL;
757 g_variant_get(val, "as", &iter);
758 while (g_variant_iter_loop(iter, "s", &name)) {
759 BT_DBG("name = %s", name);
760 g_variant_iter_loop(iter, "s", &value);
761 BT_DBG("Value = %s", value);
762 if (FALSE == _bt_update_le_feature_support(name, value))
763 BT_INFO("Fail to update LE feature info");
766 g_variant_iter_free(iter);
768 BT_DBG("property : [%s]", property);
773 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
777 GVariantIter value_iter;
778 GVariant *child = NULL, *val = NULL;
779 char *property = NULL;
780 g_variant_iter_init (&value_iter, msg);
781 while ((child = g_variant_iter_next_value (&value_iter))) {
782 g_variant_get(child, "{sv}", &property, &val);
784 ret_if(property == NULL);
786 BT_DBG("property :%s", property);
788 if (strcasecmp(property, "Status") == 0) {
790 g_variant_get(val, "s", &status);
792 if (strcasecmp(status, "active") == 0){
793 _bt_obex_transfer_started(path);
794 } else if (strcasecmp(status, "complete") == 0) {
795 _bt_obex_transfer_completed(path, TRUE);
796 _bt_pbap_obex_transfer_completed(path, TRUE);
797 } else if (strcasecmp(status, "error") == 0){
798 _bt_obex_transfer_completed(path, FALSE);
799 _bt_pbap_obex_transfer_completed(path, FALSE);
802 } else if (strcasecmp(property, "Transferred") == 0) {
803 static int transferred = 0;
804 g_variant_get(val, "t", &transferred);
806 _bt_obex_transfer_progress(path,transferred);
809 g_variant_unref(val);
810 g_variant_unref(child);
815 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
820 int result = BLUETOOTH_ERROR_NONE;
821 GVariantIter value_iter;
823 char *property = NULL;
825 GVariant *param = NULL;
826 bt_remote_dev_info_t *remote_dev_info;
827 g_variant_iter_init (&value_iter, msg);
828 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
829 BT_DBG("Property %s", property);
830 if (strcasecmp(property, "Connected") == 0) {
833 g_variant_get(val, "i", &connected);
835 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
836 BLUETOOTH_EVENT_DEVICE_CONNECTED :
837 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
839 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
841 _bt_convert_device_path_to_address(path, address);
843 BT_DBG("connected: %d", connected);
844 BT_DBG("address: %s", address);
846 remote_dev_info = _bt_get_remote_device_info(address);
848 if (remote_dev_info != NULL) {
849 __bt_device_remote_connected_properties(
850 remote_dev_info, address,
851 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
853 _bt_free_device_info(remote_dev_info);
855 param = g_variant_new("(is)", result, address);
856 /* Send event to application */
857 _bt_send_event(BT_DEVICE_EVENT,
861 } else if (strcasecmp(property, "RSSI") == 0) {
862 bt_remote_dev_info_t *remote_dev_info;
864 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
866 _bt_convert_device_path_to_address(path, address);
867 BT_DBG("address: %s", address);
869 remote_dev_info = _bt_get_remote_device_info(address);
870 if (remote_dev_info == NULL) {
872 g_variant_unref(val);
876 BT_DBG("Address type %d", remote_dev_info->addr_type);
878 if (remote_dev_info && remote_dev_info->addr_type == 0) {
879 BT_DBG("Name %s", remote_dev_info->name);
881 GVariant *uuids = NULL;
882 GVariantBuilder *builder = NULL;
884 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
885 for (i=0; i < remote_dev_info->uuid_count; i++) {
886 g_variant_builder_add(builder, "s",
887 remote_dev_info->uuids[i]);
889 uuids = g_variant_new("as", builder);
890 g_variant_builder_unref(builder);
891 GVariant *manufacturer_data = NULL;
892 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
893 remote_dev_info->manufacturer_data,
894 remote_dev_info->manufacturer_data_len,
897 param = g_variant_new("(isunsbub@asn@ay)", result,
898 remote_dev_info->address,
899 remote_dev_info->class,
900 remote_dev_info->rssi,
901 remote_dev_info->name,
902 remote_dev_info->paired,
903 remote_dev_info->connected,
904 remote_dev_info->trust,
906 remote_dev_info->manufacturer_data_len,
909 _bt_send_event(BT_ADAPTER_EVENT,
910 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
914 _bt_free_device_info(remote_dev_info);
915 } else if (strcasecmp(property, "GattConnected") == 0) {
916 gboolean gatt_connected = FALSE;
918 g_variant_get(val, "b", &gatt_connected);
920 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
921 BLUETOOTH_EVENT_GATT_DISCONNECTED;
923 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
925 _bt_convert_device_path_to_address(path, address);
927 BT_DBG("gatt_connected: %d", gatt_connected);
928 BT_DBG("address: %s", address);
929 param = g_variant_new("(is)", result, address);
930 /* Send event to application */
931 _bt_send_event(BT_DEVICE_EVENT,
935 } else if (strcasecmp(property, "Paired") == 0) {
936 gboolean paired = FALSE;
937 bt_remote_dev_info_t *remote_dev_info;
938 g_variant_get(val, "b", &paired);
939 _bt_agent_set_canceled(FALSE);
940 /* BlueZ sends paired signal for each paired device */
941 /* during activation, We should ignore this, otherwise*/
942 /* application thinks that a new device got paired */
943 if (_bt_adapter_get_status() != BT_ACTIVATED) {
944 BT_DBG("BT is not activated, so ignore this");
946 g_variant_unref(val);
950 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
952 _bt_convert_device_path_to_address(path, address);
954 remote_dev_info = _bt_get_remote_device_info(address);
955 if (remote_dev_info == NULL) {
957 g_variant_unref(val);
962 if(paired == FALSE) {
963 BT_INFO("Unpaired: %s", address);
964 __bt_update_remote_cache_devinfo(address, FALSE);
965 param = g_variant_new("(is)", result, address);
966 _bt_send_event(BT_ADAPTER_EVENT,
967 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
970 BT_INFO("Paired: %s", address);
971 __bt_update_remote_cache_devinfo(address, TRUE);
973 if (_bt_is_device_creating() == TRUE) {
974 BT_DBG("Try to Pair by me");
975 _bt_free_device_info(remote_dev_info);
978 g_variant_unref(val);
981 GVariant *uuids = NULL;
982 GVariantBuilder *builder = NULL;
984 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
985 for (i=0; i < remote_dev_info->uuid_count; i++) {
986 g_variant_builder_add(builder, "s",
987 remote_dev_info->uuids[i]);
989 uuids = g_variant_new("as", builder);
990 g_variant_builder_unref(builder);
991 GVariant *manufacturer_data = NULL;
992 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
993 remote_dev_info->manufacturer_data,
994 remote_dev_info->manufacturer_data_len,
998 param = g_variant_new("(isunsbub@asn@ay)", result,
999 address, remote_dev_info->class,
1000 remote_dev_info->rssi,
1001 remote_dev_info->name,
1002 remote_dev_info->paired,
1003 remote_dev_info->connected,
1004 remote_dev_info->trust,
1006 remote_dev_info->manufacturer_data_len,
1008 _bt_send_event(BT_ADAPTER_EVENT,
1009 BLUETOOTH_EVENT_BONDING_FINISHED,
1012 _bt_free_device_info(remote_dev_info);
1014 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1015 gboolean paired = FALSE;
1016 bt_remote_dev_info_t *remote_dev_info;
1018 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1019 BT_DBG("BT is not activated, so ignore this");
1021 g_variant_unref(val);
1025 g_variant_get(val, "b", &paired);
1026 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1027 BT_DBG("LegacyPaired: %d", paired);
1028 _bt_convert_device_path_to_address(path, address);
1030 remote_dev_info = _bt_get_remote_device_info(address);
1031 if (remote_dev_info == NULL) {
1034 g_variant_unref(val);
1038 BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
1039 remote_dev_info->name);
1040 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1041 remote_dev_info->name, NULL, NULL, NULL);
1043 _bt_free_device_info(remote_dev_info);
1045 } else if (strcasecmp(property, "Trusted") == 0) {
1046 gboolean trusted = FALSE;
1048 g_variant_get(val, "b", &trusted);
1050 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1051 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1053 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1055 _bt_convert_device_path_to_address(path, address);
1057 BT_DBG("trusted: %d", trusted);
1058 BT_DBG("address: %s", address);
1059 param = g_variant_new("(is)", result, address);
1060 /* Send event to application */
1061 _bt_send_event(BT_DEVICE_EVENT,
1070 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1073 int result = BLUETOOTH_ERROR_NONE;
1074 GVariantIter value_iter;
1075 char *property = NULL;
1077 GVariant *val = NULL;
1078 GVariant *child = NULL;
1079 bt_remote_dev_info_t *remote_dev_info;
1080 GVariant *param = NULL;
1081 g_variant_iter_init (&value_iter, msg);
1082 while ((child = g_variant_iter_next_value (&value_iter))) {
1083 g_variant_get(child, "{sv}", &property, &val);
1084 BT_INFO("Property %s", property);
1085 if (strcasecmp(property, "Connected") == 0) {
1086 gboolean connected = FALSE;
1088 g_variant_get(val, "b", &connected);
1090 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1091 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1093 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1095 _bt_convert_device_path_to_address(path, address);
1097 BT_DBG("connected: %d", connected);
1098 BT_DBG("address: %s", address);
1100 remote_dev_info = _bt_get_remote_device_info(address);
1102 if (remote_dev_info != NULL) {
1103 __bt_device_remote_connected_properties(
1104 remote_dev_info, address, connected);
1105 _bt_free_device_info(remote_dev_info);
1107 param = g_variant_new("(is)", result, address);
1108 /* Send event to application */
1109 _bt_send_event(BT_AVRCP_EVENT,
1115 g_variant_unref(child);
1116 g_variant_unref(val);
1121 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1123 char *interface_name = NULL;
1124 GVariant *val = NULL;
1126 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val,NULL);
1128 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1129 __bt_adapter_property_changed_event(val,
1131 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1132 __bt_device_property_changed_event(val,object_path);
1133 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1134 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1135 __bt_obex_property_changed_event(val,
1137 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1138 __bt_media_control_changed_event(val,
1140 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1141 _bt_handle_avrcp_control_event(val,
1143 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1144 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1145 _bt_handle_network_client_event(val,
1147 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1148 __bt_gatt_char_property_changed_event(val,
1151 g_variant_unref(val);
1154 void __bt_opc_property_changed_event(GVariant *msg,
1157 GVariantIter value_iter;
1158 char *property = NULL;
1159 GVariant *val = NULL;
1160 GVariant *child = NULL;
1162 g_variant_iter_init (&value_iter, msg);
1163 while ((child = g_variant_iter_next_value (&value_iter))) {
1164 g_variant_get(child, "{sv}", &property, &val);
1165 ret_if(property == NULL);
1167 if (strcasecmp(property, "Status") == 0) {
1168 char *status = NULL;
1169 g_variant_get(val, "s", &status);
1170 BT_DBG("Status is %s", status);
1172 if(strcasecmp(status, "active") == 0){
1173 _bt_obex_client_started(path);
1174 }else if (strcasecmp(status, "complete") == 0) {
1175 _bt_obex_client_completed(path, TRUE);
1176 }else if (strcasecmp(status, "error") == 0){
1177 _bt_obex_client_completed(path, FALSE);
1180 } else if (strcasecmp(property, "Transferred") == 0) {
1181 static int transferred = 0;
1182 g_variant_get(val, "t", &transferred);
1184 _bt_obex_client_progress(path, transferred);
1186 BT_DBG("property : [%s]", property);
1189 g_variant_unref(child);
1190 g_variant_unref(val);
1194 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1196 char *interface_name = NULL;
1197 GVariant *value = NULL;
1198 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1199 BT_INFO("interface_name = %s", interface_name);
1200 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1201 __bt_opc_property_changed_event(value,
1204 BT_DBG("interface_name : [%s]", interface_name);
1206 g_variant_unref(value);
1210 void _bt_handle_input_event(GVariant *msg, const char *path)
1212 int result = BLUETOOTH_ERROR_NONE;
1213 gboolean property_flag = FALSE;
1214 GVariantIter value_iter;
1215 char *property = NULL;
1216 GVariant *child = NULL, *val = NULL;
1217 bt_remote_dev_info_t *remote_dev_info;
1218 GVariant *param = NULL;
1219 g_variant_iter_init (&value_iter, msg);
1220 while ((child = g_variant_iter_next_value (&value_iter))) {
1221 g_variant_get(child, "{sv}", &property, &val);
1223 ret_if(property == NULL);
1225 if (strcasecmp(property, "Connected") == 0) {
1226 int event = BLUETOOTH_EVENT_NONE;
1228 g_variant_get(val, "b", &property_flag);
1230 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1232 _bt_convert_device_path_to_address(path, address);
1234 event = (property_flag == TRUE) ?
1235 BLUETOOTH_HID_CONNECTED :
1236 BLUETOOTH_HID_DISCONNECTED;
1237 param = g_variant_new("(is)", result, address);
1238 _bt_send_event(BT_HID_EVENT, event,
1240 /* Check HID connection type (Keyboard or Mouse) and update the status */
1241 remote_dev_info = _bt_get_remote_device_info(address);
1243 if (property_flag == TRUE) {
1244 hid_connected_device_count++;
1245 __bt_set_device_values(TRUE,
1246 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1248 hid_connected_device_count--;
1249 if (hid_connected_device_count == 0)
1250 __bt_set_device_values(FALSE,
1251 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1254 if (remote_dev_info != NULL) {
1255 BT_DBG("HID device class [%x]", remote_dev_info->class);
1256 if (remote_dev_info->class &
1257 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1258 #ifdef ENABLE_TIZEN_2_4
1259 __bt_set_device_values(property_flag,
1260 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1265 if (remote_dev_info->class &
1266 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1267 #ifdef ENABLE_TIZEN_2_4
1268 __bt_set_device_values(property_flag,
1269 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1272 _bt_free_device_info(remote_dev_info);
1277 g_variant_unref(val);
1278 g_variant_unref(child);
1282 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1284 int result = BLUETOOTH_ERROR_NONE;
1285 char *address = NULL;
1286 char *device = NULL;
1287 GVariant *param = NULL;
1288 ret_if(member == NULL);
1289 if (strcasecmp(member, "PeerConnected") == 0) {
1290 g_variant_get(msg, "(ss)", &device, &address);
1292 __bt_set_device_values(TRUE,
1293 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1294 param = g_variant_new("(iss)", result, device, address);
1295 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1299 nap_connected_device_count++;
1300 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1301 g_variant_get(msg, "(ss)", &device, &address);
1302 nap_connected_device_count--;
1303 if (nap_connected_device_count == 0)
1304 __bt_set_device_values(FALSE,
1305 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1306 param = g_variant_new("(iss)", result, device, address);
1307 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1314 void _bt_handle_network_client_event(GVariant *msg,
1319 int result = BLUETOOTH_ERROR_NONE;
1320 gboolean property_flag = FALSE;
1321 char *property = NULL;
1322 GVariant *val = NULL;
1323 GVariantIter value_iter;
1324 GVariant *param = NULL;
1325 g_variant_iter_init (&value_iter, msg);
1326 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1327 if (strcasecmp(property, "Connected") == 0) {
1328 int event = BLUETOOTH_EVENT_NONE;
1331 g_variant_get(val, "b", &property_flag);
1332 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1334 _bt_convert_device_path_to_address(path, address);
1336 BT_DBG("property_flag %d", property_flag);
1337 if (property_flag == TRUE) {
1338 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1339 nap_connected_device_count++;
1340 __bt_set_device_values(TRUE,
1341 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1343 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1344 nap_connected_device_count--;
1345 if (nap_connected_device_count == 0)
1346 __bt_set_device_values(FALSE,
1347 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1349 param = g_variant_new("(is)", result, address);
1350 _bt_send_event(BT_NETWORK_EVENT, event,
1359 void __bt_gatt_char_property_changed_event(GVariant *msg,
1362 GVariantIter value_iter;
1363 char *property = NULL;
1364 char * char_handle = NULL;
1365 GVariant *val = NULL;
1366 int result = BLUETOOTH_ERROR_NONE;
1367 GVariant *param = NULL;
1368 g_variant_iter_init (&value_iter, msg);
1369 char_handle = g_strdup(path);
1370 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1371 BT_INFO("Property %s", property);
1373 ret_if(property == NULL);
1375 if (strcasecmp(property, "Notifying") == 0) {
1376 gboolean property_flag = FALSE;
1377 g_variant_get(val, "b", &property_flag);
1378 if (property_flag == TRUE)
1379 BT_DBG("notifying is enabled");
1381 BT_DBG("notifying is disabled");
1382 } else if (strcasecmp(property, "ChangedValue") == 0) {
1384 GByteArray *gp_byte_array = NULL;
1385 BT_INFO("Type '%s'\n", g_variant_get_type_string (val));
1388 gp_byte_array = g_byte_array_new();
1389 len = g_variant_get_size(val);
1390 BT_DBG("Len = %d", len);
1391 g_byte_array_append (gp_byte_array,
1392 (const guint8 *) g_variant_get_data(val), len);
1393 if (gp_byte_array->len != 0) {
1394 GVariant *byte_array = NULL;
1395 byte_array = g_variant_new_from_data(
1396 G_VARIANT_TYPE_BYTESTRING,
1397 gp_byte_array->data,
1400 param = g_variant_new("(is@ay)", result, char_handle,
1402 _bt_send_event(BT_DEVICE_EVENT,
1403 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
1406 g_byte_array_free(gp_byte_array, TRUE);
1410 g_free(char_handle);
1412 void _bt_handle_device_event(GVariant *msg, const char *member,const char *path)
1415 int result = BLUETOOTH_ERROR_NONE;
1418 const char *property = NULL;
1419 GVariant *param = NULL;
1420 ret_if(path == NULL);
1422 if (strcasecmp(member, "PropertyChanged") == 0) {
1424 g_variant_get(msg, "(s)", &property);
1426 ret_if(property == NULL);
1428 if (strcasecmp(property, "GattConnected") == 0) {
1429 gboolean connected = FALSE;
1431 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1432 _bt_convert_device_path_to_address(path, address);
1433 g_variant_get(msg, "(b)", &connected);
1435 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1436 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1437 param = g_variant_new("(is)", result, address);
1438 _bt_send_event(BT_DEVICE_EVENT,
1442 } else if (strcasecmp(property, "Paired") == 0) {
1443 gboolean paired = FALSE;
1444 bt_remote_dev_info_t *remote_dev_info;
1445 g_variant_get(msg, "(b)", &paired);
1447 ret_if(paired == FALSE);
1449 /* BlueZ sends paired signal for each paired device */
1450 /* during activation, We should ignore this, otherwise*/
1451 /* application thinks that a new device got paired */
1452 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1453 BT_DBG("BT is not activated, so ignore this");
1457 if (_bt_is_device_creating() == TRUE) {
1458 BT_DBG("Try to Pair by me");
1462 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1464 _bt_convert_device_path_to_address(path, address);
1466 remote_dev_info = _bt_get_remote_device_info(address);
1467 if (remote_dev_info == NULL) {
1471 GVariant *uuids = NULL;
1472 GVariantBuilder *builder = NULL;
1474 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1475 for (i=0; i < remote_dev_info->uuid_count; i++) {
1476 g_variant_builder_add(builder, "s",
1477 remote_dev_info->uuids[i]);
1479 uuids = g_variant_new("as", builder);
1480 g_variant_builder_unref(builder);
1481 GVariant *manufacturer_data = NULL;
1482 manufacturer_data = g_variant_new_from_data(
1483 G_VARIANT_TYPE_BYTESTRING,
1484 remote_dev_info->manufacturer_data,
1485 remote_dev_info->manufacturer_data_len,
1487 param = g_variant_new("(isunsbub@asn@ay)", result,
1489 remote_dev_info->class,
1490 remote_dev_info->rssi,
1491 remote_dev_info->name,
1492 remote_dev_info->paired,
1493 remote_dev_info->connected,
1494 remote_dev_info->trust,
1496 remote_dev_info->manufacturer_data_len,
1498 _bt_send_event(BT_ADAPTER_EVENT,
1499 BLUETOOTH_EVENT_BONDING_FINISHED,
1501 _bt_free_device_info(remote_dev_info);
1504 } else if (strcasecmp(property, "UUIDs") == 0) {
1505 /* Once we get the updated uuid information after
1506 * reverse service search, update it to application */
1508 bt_remote_dev_info_t *remote_dev_info;
1510 ret_if(_bt_is_device_creating() == TRUE);
1512 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1514 _bt_convert_device_path_to_address(path, address);
1516 remote_dev_info = _bt_get_remote_device_info(address);
1517 if (remote_dev_info == NULL) {
1522 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1523 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1524 GVariant *uuids = NULL;
1525 GVariantBuilder *builder = NULL;
1527 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1528 for (i=0; i < remote_dev_info->uuid_count; i++) {
1529 g_variant_builder_add(builder, "s",
1530 remote_dev_info->uuids[i]);
1532 uuids = g_variant_new("as", builder);
1533 g_variant_builder_unref(builder);
1534 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1535 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1538 param = g_variant_new("(isunsbub@asn@ay)", result,
1539 address, remote_dev_info->class,
1540 remote_dev_info->rssi,
1541 remote_dev_info->name,
1542 remote_dev_info->paired,
1543 remote_dev_info->connected,
1544 remote_dev_info->trust,
1546 remote_dev_info->manufacturer_data_len,
1548 _bt_send_event(BT_ADAPTER_EVENT,
1549 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1553 _bt_free_device_info(remote_dev_info);
1556 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1557 unsigned char addr_type = 0;
1559 g_variant_get(msg, "(y)", &addr_type);
1561 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1563 _bt_convert_device_path_to_address(path, address);
1564 dev_name = _bt_get_bonded_device_name(address);
1566 BT_INFO("Address : %s Type : %d", address, addr_type);
1567 BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1568 !addr_type ? dev_name : address);
1571 _bt_logging_connection(TRUE, addr_type);
1572 #ifdef ENABLE_TIZEN_2_4
1573 journal_bt_connected();
1575 param = g_variant_new("(isy)", result, address, addr_type);
1576 /*Send event to application*/
1577 _bt_send_event(BT_DEVICE_EVENT,
1578 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1581 } else if (strcasecmp(member, "Disconnected") == 0) {
1582 unsigned char disc_reason = 0;
1583 unsigned char addr_type = 0;
1584 gboolean sending = FALSE;
1586 g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
1588 result = disc_reason;
1590 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1592 _bt_convert_device_path_to_address(path, address);
1593 dev_name = _bt_get_bonded_device_name(address);
1594 #ifdef ENABLE_TIZEN_2_4
1595 journal_bt_disconnected();
1598 /* 0x00 BDADDR_BRDER
1599 0x01 BDADDR_LE_PUBLIC
1600 0x02 BDADDR_LE_RANDOM */
1601 BT_INFO("Address : %s Type : %d", address, addr_type);
1602 BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1603 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1604 !addr_type ? dev_name : address);
1607 _bt_headset_set_local_connection(FALSE);
1608 _bt_logging_connection(FALSE, addr_type);
1610 /*Check for any OPP transfer on the device and cancel
1613 _bt_obex_check_pending_transfer(address);
1614 _bt_opp_client_is_sending(&sending);
1616 _bt_opp_client_check_pending_transfer(address);
1617 param = g_variant_new("(isy)", result, address, addr_type);
1618 _bt_send_event(BT_DEVICE_EVENT,
1619 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1622 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1624 char *profile_uuid = NULL;
1625 bt_headset_wait_t *wait_list;
1627 g_variant_get(msg, "(si)", &profile_uuid, &state);
1629 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1631 _bt_convert_device_path_to_address(path, address);
1633 BT_DBG("Address: %s", address);
1634 BT_DBG("Profile UUID: %s", profile_uuid);
1635 BT_DBG("State: %d", state);
1637 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1638 (state == BT_PROFILE_STATE_CONNECTED)) {
1640 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1641 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1642 bluetooth_device_address_t device_address;
1644 bt_headset_wait_t *wait_list;
1646 __bt_set_device_values(TRUE,
1647 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1649 __bt_connection_manager_set_state(address, event);
1651 if (_bt_headset_get_local_connection() == FALSE)
1652 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1654 /* Connection Started from local device therefore no need to
1655 * intiate connection for pending profile */
1656 _bt_headset_set_local_connection(FALSE);
1658 param = g_variant_new("(is)", result, address);
1659 _bt_send_event(BT_HEADSET_EVENT, event,
1661 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1664 if (g_strcmp0(connected_address, address) != 0) {
1665 _bt_convert_addr_string_to_type(
1666 device_address.addr,
1668 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1669 &device_address, NULL);
1673 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1674 BT_STATE_CONNECTED, address);
1676 wait_list = _bt_get_audio_wait_data();
1677 if (wait_list != NULL &&
1678 (g_strcmp0(wait_list->address, address) == 0))
1679 _bt_rel_wait_data();
1681 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1682 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1684 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1686 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1688 g_free(profile_uuid);
1692 __bt_set_device_values(FALSE,
1693 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1695 __bt_connection_manager_set_state(address, event);
1696 param = g_variant_new("(is)", result, address);
1697 _bt_send_event(BT_HEADSET_EVENT, event,
1699 /* Remove data from the connected list */
1700 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1701 wait_list = _bt_get_audio_wait_data();
1703 if (wait_list == NULL) {
1705 g_free(profile_uuid);
1709 if (((wait_list->type == BT_AUDIO_ALL) &&
1710 (wait_list->ag_flag == TRUE)) ||
1711 (wait_list->type == BT_AUDIO_A2DP) ||
1712 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1713 bluetooth_device_address_t device_address;
1714 _bt_convert_addr_string_to_type(
1715 device_address.addr,
1716 wait_list->address);
1718 _bt_audio_connect(wait_list->req_id,
1721 wait_list->out_param1);
1723 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1725 if (state == BT_PROFILE_STATE_CONNECTED) {
1726 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1727 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1728 bluetooth_device_address_t device_address;
1730 param = g_variant_new("(is)", result, address);
1731 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1733 connected = _bt_is_headset_type_connected(
1737 if (g_strcmp0(connected_address,
1739 _bt_convert_addr_string_to_type(
1740 device_address.addr,
1742 _bt_audio_disconnect(0,
1744 &device_address, NULL);
1747 BT_DBG("device Path: %s", path);
1748 _bt_add_headset_to_list(BT_AVRCP,
1749 BT_STATE_CONNECTED, address);
1750 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1751 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1752 param = g_variant_new("(is)", result, address);
1753 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1755 /* Remove data from the connected list */
1756 _bt_remove_headset_from_list(BT_AVRCP, address);
1758 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1759 if (state == BT_PROFILE_STATE_CONNECTED) {
1760 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1761 BT_INFO("A2DP Source is connected");
1762 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1763 g_variant_new("(is)", result, address));
1764 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1765 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
1766 BT_INFO("A2DP Source Disconnected");
1767 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1768 g_variant_new("(is)", result, address));
1770 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
1771 ((state == BT_PROFILE_STATE_CONNECTED) ||
1772 (state == BT_PROFILE_STATE_DISCONNECTED))) {
1774 if (state == BT_PROFILE_STATE_CONNECTED)
1775 event = BLUETOOTH_HID_CONNECTED;
1777 event = BLUETOOTH_HID_DISCONNECTED;
1778 param = g_variant_new("(is)", result, address);
1779 _bt_send_event(BT_HID_EVENT, event,
1782 if (state == BT_PROFILE_STATE_CONNECTED)
1783 __bt_set_device_values(TRUE,
1784 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1786 __bt_set_device_values(FALSE,
1787 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1790 g_free(profile_uuid);
1791 } else if (strcasecmp(member, "AdvReport") == 0) {
1793 bt_remote_le_dev_info_t *le_dev_info = NULL;
1794 char *buffer = NULL;
1796 bt_le_adv_info_t *adv_info = NULL;
1797 GVariant *value = NULL;
1798 ret_if(_bt_is_le_scanning() == FALSE);
1800 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
1802 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
1803 &le_dev_info->addr_type,
1804 &le_dev_info->adv_type,
1806 &le_dev_info->adv_data_len,
1808 buffer_len = g_variant_get_size(value);
1810 buffer = (char *)g_variant_get_data(value);
1812 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
1814 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1815 _bt_send_scan_result_event(le_dev_info, NULL);
1816 _bt_free_le_device_info(le_dev_info);
1817 g_variant_unref(value);
1821 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
1822 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
1823 adv_info->addr = g_strdup(le_dev_info->address);
1824 adv_info->data_len = le_dev_info->adv_data_len;
1825 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
1826 memcpy(adv_info->data, le_dev_info->adv_data,
1827 le_dev_info->adv_data_len);
1829 __bt_add_adv_ind_info(adv_info);
1831 } else { /* SCAN_RSP */
1832 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
1834 _bt_send_scan_result_event(le_dev_info, adv_info);
1835 __bt_del_adv_ind_info(le_dev_info->address);
1838 _bt_free_le_device_info(le_dev_info);
1839 g_variant_unref(value);
1840 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
1846 g_variant_get(msg, "(qqqq)",
1847 tx_octets, tx_time, rx_octets, rx_time);
1849 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1850 _bt_convert_device_path_to_address(path, address);
1852 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
1853 rx_octets, rx_time);
1854 /* Send event to application */
1855 _bt_send_event(BT_DEVICE_EVENT,
1862 void __bt_set_audio_values(gboolean connected, char *address)
1865 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1867 /* Set the headset name */
1868 if (connected == TRUE) {
1869 name = _bt_get_bonded_device_name(address);
1871 name = g_strdup("");
1874 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
1876 BT_ERR("vconf_set_str failed");
1881 /* Set the headset state */
1882 if (vconf_get_int(VCONFKEY_BT_DEVICE,
1883 &bt_device_state) != 0) {
1884 BT_ERR("vconf_get_str failed");
1887 #ifdef TIZEN_SUPPORT_DUAL_HF
1888 if ((connected == TRUE) &&
1889 (FALSE == __bt_is_companion_device(address))) {
1890 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1891 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
1892 (FALSE == __bt_is_companion_device(address))) {
1893 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1896 if (connected == TRUE) {
1897 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1898 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
1899 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
1903 if (vconf_set_int(VCONFKEY_BT_DEVICE,
1904 bt_device_state) != 0) {
1905 BT_ERR("vconf_set_int failed");
1909 void _bt_handle_headset_event(GVariant *msg, const char *path)
1911 int result = BLUETOOTH_ERROR_NONE;
1912 gboolean property_flag = FALSE;
1913 char *property = NULL;
1914 GVariant *value = NULL;
1915 GVariant *param = NULL;
1916 g_variant_get(msg, "(sv)", &property, &value);
1918 ret_if(property == NULL);
1920 BT_DBG("Property = %s \n", property);
1921 /* We allow only 1 headset connection (HSP or HFP)*/
1922 if (strcasecmp(property, "Connected") == 0) {
1923 int event = BLUETOOTH_EVENT_NONE;
1924 bt_headset_wait_t *wait_list;
1926 g_variant_get(value, "b", &property_flag);
1928 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1930 /* Fix : NULL_RETURNS */
1931 if (address == NULL)
1934 _bt_convert_device_path_to_address(path, address);
1936 if (property_flag == TRUE) {
1937 event = BLUETOOTH_EVENT_AG_CONNECTED;
1938 if (_bt_headset_get_local_connection() == FALSE)
1939 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
1941 _bt_headset_set_local_connection(FALSE);
1945 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
1947 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
1948 if (previous_state == BT_STATE_DISCONNECTING)
1949 _bt_send_hf_local_term_event(address);
1951 /* Set the State machine here */
1952 __bt_connection_manager_set_state(address, event);
1953 __bt_set_audio_values(property_flag, address);
1954 param = g_variant_new("(is)", result, address);
1955 _bt_send_event(BT_HEADSET_EVENT, event,
1958 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
1959 /* Remove data from the connected list */
1960 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
1962 wait_list = _bt_get_audio_wait_data();
1963 if (wait_list == NULL) {
1968 bluetooth_device_address_t device_address;
1970 _bt_set_audio_wait_data_flag(TRUE);
1972 _bt_convert_addr_string_to_type(device_address.addr,
1973 wait_list->address);
1974 _bt_audio_connect(wait_list->req_id, wait_list->type,
1975 &device_address, wait_list->out_param1);
1976 _bt_rel_wait_data();
1977 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
1978 /* Add data to the connected list */
1979 _bt_add_headset_to_list(BT_AUDIO_HSP,
1980 BT_STATE_CONNECTED, address);
1982 wait_list = _bt_get_audio_wait_data();
1983 if (wait_list != NULL &&
1984 (g_strcmp0(wait_list->address, address) == 0))
1985 _bt_rel_wait_data();
1987 BT_INFO("Check A2DP pending connect");
1988 _bt_audio_check_pending_connect();
1991 } else if (strcasecmp(property, "State") == 0) {
1994 g_variant_get(value, "s", &state);
1996 /* This code assumes we support only 1 headset connection */
1997 /* Need to use the headset list, if we support multi-headsets */
1998 if (strcasecmp(state, "Playing") == 0) {
1999 BT_DBG("Playing: Sco Connected");
2000 } else if (strcasecmp(state, "connected") == 0 ||
2001 strcasecmp(state, "disconnected") == 0) {
2002 BT_DBG("connected/disconnected: Sco Disconnected");
2004 BT_ERR("Not handled state - %s", state);
2009 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2013 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2015 _bt_convert_device_path_to_address(path, address);
2017 g_variant_get(value, "i", &spkr_gain);
2018 param = g_variant_new("(isq)", result, address, spkr_gain);
2019 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2023 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2027 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2029 _bt_convert_device_path_to_address(path, address);
2031 g_variant_get(value, "i", &mic_gain);
2032 param = g_variant_new("(isq)", result, address, mic_gain);
2033 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2040 g_variant_unref(value);
2043 void _bt_handle_sink_event(GVariant *msg, const char *path)
2045 GVariantIter value_iter;
2046 char *property = NULL;
2048 bt_headset_wait_t *wait_list;
2050 GVariant *child = NULL;
2051 GVariant *val = NULL;
2052 GVariant *param = NULL;
2053 g_variant_iter_init (&value_iter, msg);
2054 while ((child = g_variant_iter_next_value (&value_iter))) {
2056 g_variant_get(child, "{sv}", &property, &val);
2058 ret_if(property == NULL);
2060 BT_DBG("Property = %s \n", property);
2063 if (strcasecmp(property, "State") == 0) {
2064 int result = BLUETOOTH_ERROR_NONE;
2067 g_variant_get(val, "s", &value);
2068 BT_DBG("value: %s", value);
2070 if (g_strcmp0(value, "disconnected") == 0) {
2073 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2075 _bt_convert_device_path_to_address(path, address);
2077 __bt_set_device_values(FALSE,
2078 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2079 param = g_variant_new("(is)", result, address);
2080 _bt_send_event(BT_HEADSET_EVENT,
2081 BLUETOOTH_EVENT_AV_DISCONNECTED,
2084 /* Remove data from the connected list */
2085 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2086 wait_list = _bt_get_audio_wait_data();
2087 if (wait_list == NULL) {
2090 g_variant_unref(val);
2091 g_variant_unref(child);
2096 if (((wait_list->type == BT_AUDIO_ALL) &&
2097 (wait_list->ag_flag == TRUE)) ||
2098 (wait_list->type == BT_AUDIO_A2DP) ||
2099 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2100 bluetooth_device_address_t device_address;
2101 _bt_convert_addr_string_to_type(
2102 device_address.addr,
2103 wait_list->address);
2105 _bt_audio_connect(wait_list->req_id,
2108 wait_list->out_param1);
2111 }else if (strcasecmp(value, "Connected") == 0) {
2113 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2114 bluetooth_device_address_t device_address;
2117 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2119 _bt_convert_device_path_to_address(path, address);
2121 __bt_set_device_values(TRUE,
2122 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2123 param = g_variant_new("(is)", result, address);
2124 _bt_send_event(BT_HEADSET_EVENT,
2125 BLUETOOTH_EVENT_AV_CONNECTED,
2127 /* Check for existing Media device to disconnect */
2128 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2131 /* Match connected device address */
2132 if (g_strcmp0(connected_address, address) != 0) {
2133 /* Convert BD adress from string type */
2134 _bt_convert_addr_string_to_type(
2135 device_address.addr,
2137 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2138 &device_address, NULL);
2142 /* Add data to the connected list */
2143 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2144 BT_STATE_CONNECTED, address);
2151 g_variant_unref(val);
2152 g_variant_unref(child);
2156 void _bt_handle_agent_event(GVariant *msg, const char *member)
2158 int result = BLUETOOTH_ERROR_NONE;
2159 char *address = NULL;
2162 GVariant *param = NULL;
2163 ret_if(member == NULL);
2165 if (strcasecmp(member, "ObexAuthorize") == 0) {
2166 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2167 param = g_variant_new("(iss)", result, address, name);
2168 _bt_send_event(BT_OPP_SERVER_EVENT,
2169 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2173 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2174 bt_rfcomm_server_info_t *server_info;
2176 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2178 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2179 ret_if(server_info == NULL);
2180 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2181 param = g_variant_new("(isssn)", result, address, uuid, name,
2182 server_info->control_fd);
2183 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2184 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2192 static int __bt_get_object_path(GVariant *msg, char **path)
2194 g_variant_get(msg, "(o*)", path, NULL);
2196 return BLUETOOTH_ERROR_INTERNAL;
2198 return BLUETOOTH_ERROR_NONE;
2201 static void __bt_devices_list_free(void)
2203 bt_cache_info_t *cache_info;
2206 node = g_list_first(p_cache_list);
2208 while (node != NULL){
2209 cache_info = (bt_cache_info_t *)node->data;
2210 p_cache_list = g_list_remove(p_cache_list, cache_info);
2211 __bt_free_cache_info(cache_info);
2213 node = g_list_next(node);
2217 static int __bt_parse_event(GVariant *msg)
2221 char *interface_name= NULL;
2222 GVariant *inner_iter = NULL;
2224 g_variant_iter_init(&iter, msg);
2226 while ((child = g_variant_iter_next_value(&iter))) {
2227 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
2228 if (g_strcmp0(interface_name,
2229 BT_DEVICE_INTERFACE) == 0) {
2230 g_variant_unref(inner_iter);
2231 g_variant_unref(child);
2232 return BT_DEVICE_EVENT;
2233 } else if (g_strcmp0(interface_name,
2234 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2235 g_variant_unref(inner_iter);
2236 g_variant_unref(child);
2237 return BT_MEDIA_TRANSFER_EVENT;
2238 } else if (g_strcmp0(interface_name,
2239 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2240 g_variant_unref(inner_iter);
2241 g_variant_unref(child);
2242 return BT_AVRCP_CONTROL_EVENT;
2244 g_variant_unref(inner_iter);
2245 g_variant_unref(child);
2251 static void __bt_manager_event_filter(GDBusConnection *connection,
2252 const gchar *sender_name,
2253 const gchar *object_path,
2254 const gchar *interface_name,
2255 const gchar *signal_name,
2256 GVariant *parameters,
2259 bt_event_type_t bt_event = 0x00;
2260 int result = BLUETOOTH_ERROR_NONE;
2262 char *obj_path = NULL;
2263 GVariant *param = NULL;
2264 if (signal_name == NULL)
2266 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2267 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2269 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0){
2270 #ifdef USB_BLUETOOTH
2271 BT_DBG("Enable Adapter");
2272 _bt_enable_adapter();
2274 _bt_handle_adapter_added();
2278 bt_event = __bt_parse_event(value);
2279 if (bt_event == BT_DEVICE_EVENT) {
2280 bt_cache_info_t *cache_info;
2281 bt_remote_dev_info_t *dev_info;
2283 ret_if(_bt_is_discovering() == FALSE &&
2284 _bt_is_le_scanning() == FALSE);
2286 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2287 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2288 cache_info->dev_info = dev_info;
2290 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2291 BT_ERR("Fail to parse the properies");
2292 __bt_free_cache_info(cache_info);
2293 g_variant_unref(value);
2297 if (dev_info->addr_type != BDADDR_BREDR) {
2298 /* Whenever emit the property changed from bluez,
2299 some property doesn't reach to bt-service.
2300 So LE device is handled as AdvReport signal */
2301 __bt_free_cache_info(cache_info);
2302 g_variant_unref(value);
2306 if (dev_info->name == NULL)
2307 /* If Remote device name is NULL or still RNR is not done
2308 * then display address as name.
2310 dev_info->name = g_strdup(dev_info->address);
2312 GVariant *uuids = NULL;
2313 GVariantBuilder *builder = NULL;
2315 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2316 for (i=0; i < dev_info->uuid_count; i++) {
2317 g_variant_builder_add(builder, "s",
2318 dev_info->uuids[i]);
2320 uuids = g_variant_new("as", builder);
2321 g_variant_builder_unref(builder);
2322 GVariant *manufacturer_data = NULL;
2323 manufacturer_data = g_variant_new_from_data(
2324 G_VARIANT_TYPE_BYTESTRING,
2325 dev_info->manufacturer_data,
2326 dev_info->manufacturer_data_len,
2328 param = g_variant_new("(isunsbub@asn@ay)", result,
2334 dev_info->connected,
2337 dev_info->manufacturer_data_len,
2339 _bt_send_event(BT_ADAPTER_EVENT,
2340 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2342 p_cache_list = g_list_append(p_cache_list, cache_info);
2343 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2344 BT_DBG("Device path : %s ", obj_path);
2345 _bt_set_control_device_path(obj_path);
2348 g_variant_unref(value);
2349 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2350 #ifdef USB_BLUETOOTH
2351 BT_DBG("InterfacesRemoved");
2352 _bt_handle_adapter_removed();
2355 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2356 bt_event = BT_MEDIA_TRANSFER_EVENT;
2357 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2358 bt_event = BT_DEVICE_EVENT;
2359 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2360 bt_event = BT_AVRCP_CONTROL_EVENT;
2362 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2363 _bt_handle_adapter_event(parameters, signal_name);
2364 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2365 BT_INFO("Object Path %s", obj_path);
2366 _bt_remove_control_device_path(obj_path);
2369 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2372 char *previous = NULL;
2373 char *current = NULL;
2375 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2376 BT_ERR("Fail to get the owner info");
2380 if (*current != '\0') {
2390 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2391 BT_DBG("Bluetoothd is terminated");
2392 if (_bt_adapter_get_status() != BT_DEACTIVATING) {
2395 _bt_handle_adapter_removed();
2396 __bt_devices_list_free();
2399 _bt_obex_server_check_allocation(&value);
2401 if (value == TRUE) {
2402 /* Check if the obex server was terminated abnormally */
2403 _bt_obex_server_check_termination(name);
2406 _bt_rfcomm_server_check_existence(&value);
2408 if (value == TRUE) {
2409 /* The obex server was terminated abnormally */
2410 _bt_rfcomm_server_check_termination(name);
2413 /* Stop advertising started by terminated process */
2414 _bt_stop_advertising_by_terminated_process(name);
2416 _bt_stop_le_scan(name);
2420 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2421 const char *path = object_path;
2423 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2424 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2427 _bt_handle_property_changed_event(parameters, object_path);
2428 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2429 _bt_handle_adapter_event(parameters, signal_name);
2430 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2431 _bt_handle_input_event(parameters, object_path);
2432 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2433 _bt_handle_network_server_event(parameters, signal_name);
2434 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2435 _bt_handle_headset_event(parameters, object_path);
2436 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2437 _bt_handle_sink_event(parameters, object_path);
2438 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2439 _bt_handle_agent_event(parameters, signal_name);
2440 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2441 _bt_handle_device_event(parameters, signal_name, object_path);
2447 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2450 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2451 char *interface_name = NULL;
2453 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2454 retv_if(interface_name == NULL, FALSE);
2456 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2457 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2465 static void __bt_obexd_event_filter(GDBusConnection *connection,
2466 const gchar *sender_name,
2467 const gchar *object_path,
2468 const gchar *interface_name,
2469 const gchar *signal_name,
2470 GVariant *parameters,
2473 const char *member = signal_name;
2474 char *obj_path = NULL;
2475 ret_if(member == NULL);
2477 if (strcasecmp(member, "InterfacesAdded") == 0) {
2478 if (__bt_get_object_path(parameters, &obj_path)) {
2479 BT_ERR("Fail to get the path");
2482 BT_INFO("object_path = [%s]", object_path);
2484 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2485 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2486 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2491 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2492 BT_DBG("Obex_Server_Session_Transfer connected");
2493 _bt_obex_transfer_connected();
2496 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2497 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2498 if (__bt_get_object_path(parameters, &obj_path)) {
2499 BT_ERR("Fail to get the path");
2502 BT_INFO("object_path = [%s]", object_path);
2504 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2505 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2506 BT_DBG("Call PBAP Disconnected");
2507 _bt_obex_pbap_client_disconnect(obj_path);
2510 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2511 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2516 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2517 BT_DBG("Obex_Server_Session_Transfer disconnected");
2518 _bt_obex_transfer_disconnected();
2521 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2522 const char *path = object_path;
2524 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2525 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2526 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2527 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2528 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2532 _bt_handle_property_changed_event(parameters, path);
2538 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2542 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2543 char *interface_name = NULL;
2545 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2547 retv_if(interface_name == NULL, FALSE);
2549 if (strcasecmp(interface_name,
2550 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2561 static void __bt_opc_event_filter(GDBusConnection *connection,
2562 const gchar *sender_name,
2563 const gchar *object_path,
2564 const gchar *interface_name,
2565 const gchar *signal_name,
2566 GVariant *parameters,
2569 const char *member = signal_name;
2570 char *obj_path = NULL;
2571 if (strcasecmp(member, "InterfacesAdded") == 0) {
2572 BT_DBG("InterfacesAdded");
2573 }else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2575 if (__bt_get_object_path(parameters, &obj_path)) {
2576 BT_ERR("Fail to get the path");
2580 BT_DBG("object_path =%s",obj_path);
2582 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2583 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2584 || strstr(obj_path, "transfer") == NULL) {
2588 else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2589 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2590 BT_DBG("Going to call opc disconnected");
2591 _bt_opc_disconnected(obj_path);
2594 _bt_sending_files();
2596 }else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE){
2597 char *path = (char *)object_path;
2598 BT_INFO("object_path %s", path);
2599 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2600 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2601 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2605 _bt_opc_property_changed_event(parameters, path);
2611 int _bt_opp_client_event_init(void)
2613 GError *error = NULL;
2615 if (opc_obexd_conn == NULL) {
2616 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2618 if (!opc_obexd_conn) {
2620 BT_ERR("Unable to connect to dbus: %s", error->message);
2621 g_clear_error(&error);
2623 return BLUETOOTH_ERROR_INTERNAL;
2627 if (_bt_register_service_event(opc_obexd_conn,
2628 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2629 g_object_unref(opc_obexd_conn);
2630 opc_obexd_conn = NULL;
2631 return BLUETOOTH_ERROR_INTERNAL;
2634 return BLUETOOTH_ERROR_NONE;
2637 void _bt_opp_client_event_deinit(void)
2639 if (opc_obexd_conn) {
2640 _bt_unregister_service_event(opc_obexd_conn,
2641 BT_OPP_CLIENT_EVENT);
2642 g_object_unref(opc_obexd_conn);
2643 opc_obexd_conn = NULL;
2647 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2653 static int subs_interface_added_id = -1;
2654 static int subs_interface_removed_id = -1;
2655 static int subs_name_owner_id = -1;
2656 static int subs_property_id = -1;
2657 static int subs_adapter_id = -1;
2660 if (subs_interface_added_id == -1) {
2661 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2662 NULL, BT_MANAGER_INTERFACE,
2663 BT_INTERFACES_ADDED, NULL, NULL, 0,
2664 __bt_manager_event_filter,
2667 if (subs_interface_removed_id == -1) {
2668 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2669 NULL, BT_MANAGER_INTERFACE,
2670 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2671 __bt_manager_event_filter,
2674 if (subs_name_owner_id == -1) {
2675 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
2676 NULL, BT_FREEDESKTOP_INTERFACE,
2677 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
2678 __bt_manager_event_filter,
2681 if (subs_property_id == -1) {
2682 subs_property_id = g_dbus_connection_signal_subscribe(conn,
2683 NULL, BT_PROPERTIES_INTERFACE,
2684 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2685 __bt_manager_event_filter,
2688 if (subs_adapter_id == -1) {
2689 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
2690 NULL, BT_ADAPTER_INTERFACE,
2691 NULL, NULL, NULL, 0,
2692 __bt_manager_event_filter,
2696 if (subs_interface_added_id != -1) {
2697 g_dbus_connection_signal_unsubscribe(conn,
2698 subs_interface_added_id);
2699 subs_interface_added_id = -1;
2701 if (subs_interface_removed_id != -1) {
2702 g_dbus_connection_signal_unsubscribe(conn,
2703 subs_interface_removed_id);
2704 subs_interface_removed_id = -1;
2706 if (subs_name_owner_id != -1) {
2707 g_dbus_connection_signal_unsubscribe(conn,
2708 subs_name_owner_id);
2709 subs_name_owner_id = -1;
2711 if (subs_property_id != -1) {
2712 g_dbus_connection_signal_unsubscribe(conn,
2714 subs_property_id = -1;
2716 if (subs_adapter_id == -1) {
2717 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
2718 subs_adapter_id = -1;
2724 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
2730 static int subs_device_id = -1;
2733 if (subs_device_id == -1) {
2734 subs_device_id = g_dbus_connection_signal_subscribe(conn,
2735 NULL, BT_DEVICE_INTERFACE,
2736 NULL, NULL, NULL, 0,
2737 __bt_manager_event_filter,
2741 if (subs_device_id != -1) {
2742 g_dbus_connection_signal_unsubscribe(conn,
2744 subs_device_id = -1;
2750 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
2756 static int subs_input_id = -1;
2759 if (subs_input_id == -1) {
2760 subs_input_id = g_dbus_connection_signal_subscribe(conn,
2761 NULL, BT_INPUT_INTERFACE,
2762 NULL, NULL, NULL, 0,
2763 __bt_manager_event_filter,
2767 if (subs_input_id != -1) {
2768 g_dbus_connection_signal_unsubscribe(conn,
2776 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
2782 static int subs_serv_id = -1;
2783 static int subs_client_id = -1;
2786 if (subs_serv_id == -1) {
2787 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
2788 NULL, BT_NETWORK_SERVER_INTERFACE,
2789 NULL, NULL, NULL, 0,
2790 __bt_manager_event_filter,
2793 if (subs_client_id == -1) {
2794 subs_client_id = g_dbus_connection_signal_subscribe(conn,
2795 NULL, BT_NETWORK_CLIENT_INTERFACE,
2796 NULL, NULL, NULL, 0,
2797 __bt_manager_event_filter,
2801 if (subs_serv_id != -1) {
2802 g_dbus_connection_signal_unsubscribe(conn,
2806 if (subs_client_id != -1) {
2807 g_dbus_connection_signal_unsubscribe(conn,
2809 subs_client_id = -1;
2815 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
2821 static int subs_headset_id = -1;
2822 static int subs_sink_id = -1;
2825 if (subs_headset_id == -1) {
2826 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
2827 NULL, BT_HEADSET_INTERFACE,
2828 NULL, NULL, NULL, 0,
2829 __bt_manager_event_filter,
2832 if (subs_sink_id == -1) {
2833 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
2834 NULL, BT_SINK_INTERFACE,
2835 NULL, NULL, NULL, 0,
2836 __bt_manager_event_filter,
2840 if (subs_headset_id != -1) {
2841 g_dbus_connection_signal_unsubscribe(conn,
2843 subs_headset_id = -1;
2845 if (subs_sink_id != -1) {
2846 g_dbus_connection_signal_unsubscribe(conn,
2854 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
2860 static int subs_opp_server_interface_added_id = -1;
2861 static int subs_opp_server_interface_removed_id = -1;
2862 static int subs_opp_server_property_id = -1;
2866 if (subs_opp_server_interface_added_id == -1) {
2867 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2868 NULL, BT_MANAGER_INTERFACE,
2869 BT_INTERFACES_ADDED, NULL, NULL, 0,
2870 __bt_obexd_event_filter,
2873 if (subs_opp_server_interface_removed_id == -1) {
2874 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2875 NULL, BT_MANAGER_INTERFACE,
2876 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2877 __bt_obexd_event_filter,
2880 if (subs_opp_server_property_id == -1) {
2881 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
2882 NULL, BT_PROPERTIES_INTERFACE,
2883 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2884 __bt_obexd_event_filter,
2888 if (subs_opp_server_interface_added_id != -1) {
2889 g_dbus_connection_signal_unsubscribe(conn,
2890 subs_opp_server_interface_added_id);
2891 subs_opp_server_interface_added_id = -1;
2893 if (subs_opp_server_interface_removed_id != -1) {
2894 g_dbus_connection_signal_unsubscribe(conn,
2895 subs_opp_server_interface_removed_id);
2896 subs_opp_server_interface_removed_id = -1;
2898 if (subs_opp_server_property_id != -1) {
2899 g_dbus_connection_signal_unsubscribe(conn,
2900 subs_opp_server_property_id);
2901 subs_opp_server_property_id = -1;
2907 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
2913 static int subs_opp_client_interface_added_id = -1;
2914 static int subs_opp_client_interface_removed_id = -1;
2915 static int subs_opp_client_property_id = -1;
2919 if (subs_opp_client_interface_added_id == -1) {
2920 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2921 NULL, BT_MANAGER_INTERFACE,
2922 BT_INTERFACES_ADDED, NULL, NULL, 0,
2923 __bt_opc_event_filter,
2926 if (subs_opp_client_interface_removed_id == -1) {
2927 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2928 NULL, BT_MANAGER_INTERFACE,
2929 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2930 __bt_opc_event_filter,
2933 if (subs_opp_client_property_id == -1) {
2934 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
2935 NULL, BT_PROPERTIES_INTERFACE,
2936 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2937 __bt_opc_event_filter,
2941 if (subs_opp_client_interface_added_id != -1) {
2942 g_dbus_connection_signal_unsubscribe(conn,
2943 subs_opp_client_interface_added_id);
2944 subs_opp_client_interface_added_id = -1;
2946 if (subs_opp_client_interface_removed_id != -1) {
2947 g_dbus_connection_signal_unsubscribe(conn,
2948 subs_opp_client_interface_removed_id);
2949 subs_opp_client_interface_removed_id = -1;
2951 if (subs_opp_client_property_id != -1) {
2952 g_dbus_connection_signal_unsubscribe(conn,
2953 subs_opp_client_property_id);
2954 subs_opp_client_property_id = -1;
2960 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
2966 static int subs_a2dp_source_id = -1;
2967 static int subs_a2dp_sink_id = -1;
2970 if (subs_a2dp_source_id == -1) {
2971 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
2972 NULL, BT_A2DP_SOURCE_INTERFACE,
2973 NULL, NULL, NULL, 0,
2974 __bt_opc_event_filter,
2977 if (subs_a2dp_sink_id == -1) {
2978 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
2979 NULL, BT_SINK_INTERFACE,
2980 NULL, NULL, NULL, 0,
2981 __bt_opc_event_filter,
2985 if (subs_a2dp_source_id != -1) {
2986 g_dbus_connection_signal_unsubscribe(conn,
2987 subs_a2dp_source_id);
2988 subs_a2dp_source_id = -1;
2990 if (subs_a2dp_sink_id != -1) {
2991 g_dbus_connection_signal_unsubscribe(conn,
2993 subs_a2dp_sink_id = -1;
2999 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3003 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3005 switch (event_type) {
3006 case BT_MANAGER_EVENT:
3007 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3009 case BT_DEVICE_EVENT:
3010 _bt_register_device_subscribe_signal(g_conn, TRUE);
3013 _bt_register_input_subscribe_signal(g_conn, TRUE);
3015 case BT_NETWORK_EVENT:
3016 _bt_register_network_subscribe_signal(g_conn, TRUE);
3018 case BT_HEADSET_EVENT:
3019 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3022 case BT_OPP_SERVER_EVENT:
3023 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3024 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3026 case BT_OPP_CLIENT_EVENT:
3027 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3028 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3030 case BT_A2DP_SOURCE_EVENT:
3031 BT_INFO("A2dp Source event");
3032 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3035 BT_ERR("Unknown event");
3036 return BLUETOOTH_ERROR_INTERNAL;
3039 return BLUETOOTH_ERROR_NONE;
3042 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3046 ret_if(g_conn == NULL);
3048 switch (event_type) {
3049 case BT_MANAGER_EVENT:
3050 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3051 _bt_register_device_subscribe_signal(g_conn, FALSE);
3052 _bt_register_input_subscribe_signal(g_conn, FALSE);
3053 _bt_register_network_subscribe_signal(g_conn, FALSE);
3054 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3056 case BT_OPP_SERVER_EVENT:
3057 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3059 case BT_OPP_CLIENT_EVENT:
3060 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3063 BT_ERR("Unknown event");
3070 static int __bt_init_manager_receiver(void)
3074 GError *error = NULL;
3076 if (manager_conn == NULL) {
3077 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3078 if (error != NULL) {
3079 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3080 g_clear_error(&error);
3082 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3085 if (_bt_register_service_event(manager_conn,
3086 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3088 if (_bt_register_service_event(manager_conn,
3089 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3092 if (_bt_register_service_event(manager_conn,
3093 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3096 if (_bt_register_service_event(manager_conn,
3097 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3100 if (_bt_register_service_event(manager_conn,
3101 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3103 return BLUETOOTH_ERROR_NONE;
3106 g_object_unref(manager_conn);
3107 manager_conn = NULL;
3112 return BLUETOOTH_ERROR_INTERNAL;
3115 static int __bt_init_obexd_receiver(void)
3118 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3119 GError *error = NULL;
3121 if (obexd_conn == NULL) {
3122 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3123 if (error != NULL) {
3124 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3125 g_clear_error(&error);
3127 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3130 if (_bt_register_service_event(obexd_conn,
3131 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3132 BT_ERR("Error while registering service event");
3133 g_object_unref(obexd_conn);
3135 return BLUETOOTH_ERROR_INTERNAL;
3140 return BLUETOOTH_ERROR_NONE;
3143 /* To receive the event from bluez */
3144 int _bt_init_service_event_receiver(void)
3150 result = __bt_init_manager_receiver();
3151 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3153 result = __bt_init_obexd_receiver();
3154 if (result != BLUETOOTH_ERROR_NONE)
3155 BT_ERR("Fail to init obexd receiver");
3159 return BLUETOOTH_ERROR_NONE;
3162 void _bt_deinit_service_event_receiver(void)
3166 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3168 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3171 g_object_unref(manager_conn);
3172 manager_conn = NULL;
3176 g_object_unref(obexd_conn);
3181 g_source_remove(event_id);