2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <vconf-internal-bt-keys.h>
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
27 #include "bt-service-common.h"
28 #include "bt-service-event.h"
29 #include "bt-service-main.h"
30 #include "bt-service-adapter.h"
31 #include "bt-service-adapter-le.h"
32 #include "bt-service-device.h"
33 #include "bt-service-avrcp.h"
34 #include "bt-service-obex-server.h"
35 #include "bt-service-rfcomm-server.h"
36 #include "bt-service-audio.h"
37 #include "bt-service-agent.h"
38 #include "bt-service-pbap.h"
39 #include "bt-service-headset-connection.h"
40 #include "bt-service-avrcp-controller.h"
42 #include "bt-service-opp-client.h"
44 #ifdef TIZEN_DPM_ENABLE
45 #include "bt-service-dpm.h"
48 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
49 static GDBusConnection *manager_conn;
50 static GDBusConnection *obexd_conn;
51 static GDBusConnection *opc_obexd_conn;
53 static GList *p_cache_list = NULL;
55 static guint event_id;
56 guint nap_connected_device_count = 0;
57 static guint hid_connected_device_count = 0;
58 static GList *p_adv_ind_list;
61 bt_remote_dev_info_t *dev_info;
65 * obexd connection type
73 OBEX_PCSUITE = (1 << 6),
74 OBEX_SYNCEVOLUTION = (1 << 7),
76 } bluetooth_obex_connection_type_t;
78 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
79 void _bt_opc_property_changed_event(GVariant *msg, char *path);
80 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
81 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
82 void _bt_opp_client_event_deinit(void);
83 void _bt_handle_network_client_event(GVariant *msg_iter,
85 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
88 static void __bt_free_bt_le_adv_info_t(bt_le_adv_info_t *adv_info)
90 g_free(adv_info->addr);
91 g_free(adv_info->data);
95 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
98 bt_le_adv_info_t *adv_info = NULL;
99 GList *current = g_list_first((GList *)p_adv_ind_list);
100 while(current && current->data) {
101 adv_info = (bt_le_adv_info_t *)current->data;
102 retv_if(adv_info && !g_strcmp0(adv_info->addr, addr), adv_info);
103 current = g_list_next(current);
108 static void __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
111 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
112 BT_ERR("adv_info is already added");
113 __bt_free_bt_le_adv_info_t(adv_info);
116 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
119 static void __bt_del_adv_ind_info(char *addr)
122 ret_if(!p_adv_ind_list);
123 bt_le_adv_info_t *adv_info = NULL;
124 GList *current = g_list_first((GList *)p_adv_ind_list);
125 while(current && current->data) {
126 adv_info = (bt_le_adv_info_t *)current->data;
127 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
128 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
129 __bt_free_bt_le_adv_info_t(adv_info);
132 current = g_list_next(current);
136 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
138 ret_if(cache_info == NULL);
139 _bt_free_device_info(cache_info->dev_info);
143 static gboolean __bt_parse_device_properties(GVariant *item,
144 bt_remote_dev_info_t *dev_info)
153 g_variant_iter_init(&iter, item);
154 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
155 if (strcasecmp(key, "Address") == 0) {
156 dev_info->address = g_variant_dup_string(val, &len);
157 } else if (strcasecmp(key, "Class") == 0) {
158 dev_info->class = g_variant_get_uint32(val);
159 } else if (strcasecmp(key, "name") == 0) {
160 if (dev_info->name == NULL)
161 dev_info->name = g_variant_dup_string(val, &len);
162 } else if (strcasecmp(key, "Connected") == 0) {
163 dev_info->connected = g_variant_get_uint32(val);
164 } else if (strcasecmp(key, "paired") == 0) {
165 dev_info->paired = g_variant_get_boolean(val);
166 } else if (strcasecmp(key, "Trusted") == 0) {
167 dev_info->trust = g_variant_get_boolean(val);
168 } else if (strcasecmp(key, "RSSI") == 0) {
169 dev_info->rssi = g_variant_get_int16(val);
170 } else if (strcasecmp(key, "LastAddrType") == 0) {
171 dev_info->addr_type = g_variant_get_byte(val);
172 } else if (strcasecmp(key, "UUIDs") == 0) {
176 size = g_variant_get_size(val);
179 uuid_value = (char **)g_variant_get_strv(val, &size);
180 if (dev_info->uuids == NULL)
181 dev_info->uuids = g_malloc0(sizeof(char *) * size);
183 for (i = 0; uuid_value[i] != NULL; i++) {
184 dev_info->uuid_count++;
185 dev_info->uuids[i] = g_strdup(uuid_value[i]);
189 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
190 g_variant_get(val, "(i)", &dev_info->manufacturer_data_len);
191 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
192 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
193 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
196 if (dev_info->manufacturer_data_len == 0)
197 dev_info->manufacturer_data = g_strdup("");
198 } else if (strcasecmp(key, "ManufacturerData") == 0) {
200 GVariant *manufacturer_var;
201 g_variant_get(val, "@ay", &manufacturer_var);
202 len = g_variant_get_size(manufacturer_var);
204 char *manufacturer_data = (char *)g_variant_get_data(manufacturer_var);
205 dev_info->manufacturer_data = g_malloc0(len);
206 if (dev_info->manufacturer_data)
207 memcpy(dev_info->manufacturer_data, manufacturer_data,
210 g_variant_unref(manufacturer_var);
218 static gboolean __bt_parse_interface(GVariant *msg,
219 bt_remote_dev_info_t *dev_info)
222 GVariant *optional_param;
225 char *interface_name= NULL;
226 GVariant *inner_iter = NULL;
227 g_variant_get(msg, "(&o@a{sa{sv}})",
228 &path, &optional_param);
229 g_variant_iter_init(&iter, optional_param);
231 while ((child = g_variant_iter_next_value(&iter))) {
232 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
233 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
234 BT_DBG("Found a device: %s", path);
235 if (__bt_parse_device_properties(inner_iter,
236 dev_info) == FALSE) {
237 g_variant_unref(inner_iter);
238 g_variant_unref(child);
239 g_variant_unref(optional_param);
240 BT_ERR("Fail to parse the properies");
243 g_variant_unref(inner_iter);
244 g_variant_unref(child);
245 g_variant_unref(optional_param);
249 g_variant_unref(inner_iter);
250 g_variant_unref(child);
253 g_variant_unref(optional_param);
258 static int __bt_get_owner_info(GVariant *msg, char **name,
259 char **previous, char **current)
261 g_variant_get(msg, "(sss)", name, previous, current);
262 return BLUETOOTH_ERROR_NONE;
265 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
266 char **name, char **uuid)
268 g_variant_get(msg, "(sss)", address, name, uuid);
269 return BLUETOOTH_ERROR_NONE;
272 void __bt_set_device_values(gboolean connected, int state)
274 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
276 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) {
277 BT_ERR("vconf_get_int failed");
280 if (connected == TRUE)
281 bt_device_state |= state;
282 else if (bt_device_state & state)
283 bt_device_state ^= state;
285 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) {
286 BT_ERR("vconf_set_int failed");
290 gboolean _bt_discovery_finished_cb(gpointer user_data)
292 int result = BLUETOOTH_ERROR_NONE;
294 GVariant *param = NULL;
295 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
296 if (_bt_get_cancel_by_user() == TRUE) {
297 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
300 _bt_set_cancel_by_user(FALSE);
301 _bt_set_discovery_status(FALSE);
302 param = g_variant_new("(i)", result);
303 _bt_send_event(BT_ADAPTER_EVENT,
304 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
311 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
313 int result = BLUETOOTH_ERROR_NONE;
315 GVariant *param = NULL;
316 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
317 if (_bt_get_cancel_by_user() == TRUE) {
318 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
321 _bt_set_cancel_by_user(FALSE);
322 _bt_disable_all_scanner_status();
323 _bt_set_le_scan_status(FALSE);
324 param = g_variant_new("(i)", result);
325 _bt_send_event(BT_LE_ADAPTER_EVENT,
326 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
333 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
337 ret_if(address == NULL);
340 bt_cache_info_t *cache_info;
341 bt_remote_dev_info_t *dev_info;
343 node = g_list_first(p_cache_list);
345 while (node != NULL){
346 cache_info = (bt_cache_info_t *)node->data;
348 if (cache_info == NULL) {
349 node = g_list_next(node);
353 dev_info = cache_info->dev_info;
354 if (strcasecmp(dev_info->address,
356 BT_DBG("Device Found");
357 if (paired_status == TRUE)
358 cache_info->dev_info->paired = TRUE;
360 cache_info->dev_info->paired = FALSE;
363 node = g_list_next(node);
368 static void __bt_device_remote_connected_properties(
369 bt_remote_dev_info_t *remote_dev_info,
370 char *address, gboolean connected)
372 int result = BLUETOOTH_ERROR_NONE;
374 GVariant *param = NULL;
377 if (remote_dev_info->uuid_count > 0 ) {
378 for (i = 0; i<remote_dev_info->uuid_count; i++) {
379 char *uuid = remote_dev_info->uuids[i];
380 if (strcasecmp(uuid, HID_UUID) == 0){
381 int event = BLUETOOTH_EVENT_NONE;
383 event = (connected == TRUE) ?
384 BLUETOOTH_HID_CONNECTED :
385 BLUETOOTH_HID_DISCONNECTED;
386 param = g_variant_new("(is)", result,
388 _bt_send_event(BT_HID_EVENT, event,
398 void _bt_handle_adapter_event(GVariant *msg, const char *member)
402 int result = BLUETOOTH_ERROR_NONE;
403 GVariant *param = NULL;
404 ret_if(member == NULL);
406 if (strcasecmp(member, "DeviceCreated") == 0) {
407 char *object_path = NULL;
409 bt_remote_dev_info_t *remote_dev_info;
411 ret_if(_bt_is_device_creating() == FALSE);
413 /* Bonding from remote device */
414 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
416 g_variant_get(msg, "(&o)", &object_path);
417 _bt_convert_device_path_to_address((const char*)object_path, address);
419 remote_dev_info = _bt_get_remote_device_info(address);
420 if (remote_dev_info == NULL) {
425 _bt_free_device_info(remote_dev_info);
427 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
428 char *object_path = NULL;
430 bt_cache_info_t *cache_info;
431 bt_remote_dev_info_t *dev_info;
434 /* Bonding from remote device */
435 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
436 g_variant_get(msg, "(&o)", &object_path);
438 /* Fix : NULL_RETURNS */
442 _bt_convert_device_path_to_address((const char *)object_path, address);
444 node = g_list_first(p_cache_list);
446 while (node != NULL){
447 cache_info = (bt_cache_info_t *)node->data;
449 if (cache_info == NULL) {
450 node = g_list_next(node);
454 dev_info = cache_info->dev_info;
455 if (strcasecmp(dev_info->address,
457 p_cache_list = g_list_remove(p_cache_list,
459 __bt_free_cache_info(cache_info);
462 node = g_list_next(node);
465 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
466 BT_DBG("Advertising Enabled");
470 gboolean status = FALSE;
472 g_variant_get(msg, "(ib)", &slot_id, &status);
474 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
476 /* Send event to application */
477 _bt_set_advertising_status(slot_id, status);
479 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
482 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
484 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
485 param = g_variant_new("(ii)", result,
490 sender = _bt_get_adv_slot_owner(slot_id);
491 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
495 _bt_send_event(BT_ADAPTER_EVENT, event, param);
498 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
499 _bt_unregister_adv_slot_owner(slot_id);
500 } else if (strcasecmp(member, "RssiEnabled") == 0) {
501 BT_DBG("RSSI Enabled");
502 gboolean status = FALSE;
503 char *address = NULL;
505 g_variant_get(msg,"(sib)", &address, &link_type, &status);
507 BT_DBG("RSSI Enabled [%s %d]", address, status);
508 param = g_variant_new("(isib)", result,
509 address, link_type, status);
510 _bt_send_event(BT_DEVICE_EVENT,
511 BLUETOOTH_EVENT_RSSI_ENABLED,
514 } else if (strcasecmp(member, "RssiAlert") == 0) {
515 BT_DBG("RSSI Alert");
519 char *address = NULL;
520 g_variant_get(msg,"(siii)", &address, &link_type, &alert_type, &rssi_dbm);
522 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
523 address, alert_type, rssi_dbm);
524 param = g_variant_new("(isiii)", result,
525 address, link_type, alert_type, rssi_dbm);
526 _bt_send_event(BT_DEVICE_EVENT,
527 BLUETOOTH_EVENT_RSSI_ALERT,
530 } else if (strcasecmp(member, "RawRssi") == 0) {
534 char *address = NULL;
535 g_variant_get(msg,"(sii)", &address, &link_type, &rssi_dbm);
537 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
538 address, link_type, rssi_dbm);
539 param = g_variant_new("(isii)", result,
540 address, link_type, rssi_dbm);
541 _bt_send_event(BT_DEVICE_EVENT,
542 BLUETOOTH_EVENT_RAW_RSSI,
545 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
546 BT_ERR_C("Hardware error received from BLUEZ");
547 _bt_recover_adapter();
548 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
549 BT_ERR_C("Tx timeout error received from BLUEZ");
550 _bt_recover_adapter();
555 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
557 GDBusProxy *adapter_proxy;
559 int result = BLUETOOTH_ERROR_NONE;
560 GVariantIter value_iter;
561 GVariant *val = NULL;
563 char *property = NULL;
564 GVariant *param = NULL;
565 g_variant_iter_init (&value_iter, msg);
566 while ((g_variant_iter_loop (&value_iter,"{sv}", &property, &val))) {
567 BT_INFO("Property %s", property);
569 if (strcasecmp(property, "Discovering") == 0) {
570 gboolean discovering = FALSE;
571 g_variant_get(val, "b", &discovering);
572 /* Send event to application */
573 BT_DBG("Discovering %d", discovering);
574 if (discovering == TRUE) {
575 _bt_set_discovery_status(TRUE);
576 param = g_variant_new("(i)", result);
577 _bt_send_event(BT_ADAPTER_EVENT,
578 BLUETOOTH_EVENT_DISCOVERY_STARTED,
581 ret_if(event_id > 0);
583 adapter_proxy = _bt_get_adapter_proxy();
584 ret_if(adapter_proxy == NULL);
586 /* Need to stop searching */
587 g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
589 G_DBUS_CALL_FLAGS_NONE,
593 BT_ERR("Dbus Error : %s", err->message);
597 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
598 (GSourceFunc)_bt_discovery_finished_cb, NULL);
600 } else if (strcasecmp(property, "LEDiscovering") == 0) {
601 gboolean le_discovering = FALSE;
603 g_variant_get(val, "b", &le_discovering);
604 /* Send event to application */
605 if (le_discovering == TRUE) {
606 _bt_set_le_scan_status(TRUE);
607 param = g_variant_new("(i)", result);
608 _bt_send_event(BT_LE_ADAPTER_EVENT,
609 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
612 ret_if(event_id > 0);
614 adapter_proxy = _bt_get_adapter_proxy();
615 ret_if(adapter_proxy == NULL);
617 /* Need to stop searching */
618 g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
620 G_DBUS_CALL_FLAGS_NONE,
624 BT_ERR("Dbus Error %s", err->message);
628 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
629 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
631 } else if (strcasecmp(property, "Name") == 0) {
633 g_variant_get(val, "s", &name);
634 param = g_variant_new("(is)", result, name);
635 /* Send event to application */
636 _bt_send_event(BT_ADAPTER_EVENT,
637 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
640 } else if (strcasecmp(property, "Alias") == 0) {
642 g_variant_get(val, "s", &alias);
643 param = g_variant_new("(is)", result, alias);
644 /* Send event to application */
645 _bt_send_event(BT_ADAPTER_EVENT,
646 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
649 } else if (strcasecmp(property, "Discoverable") == 0) {
650 gboolean discoverable = FALSE;
652 g_variant_get(val, "b", &discoverable);
653 BT_DBG("discoverable %d", discoverable);
655 if (discoverable == FALSE) {
656 if (_bt_get_discoverable_timeout_property() > 0) {
658 adapter_proxy = _bt_get_adapter_properties_proxy();
659 ret_if(adapter_proxy == NULL);
660 g_dbus_proxy_call_sync(adapter_proxy, "Set",
661 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
662 "DiscoverableTimeout",
663 g_variant_new("i", time)),
664 G_DBUS_CALL_FLAGS_NONE,
669 BT_ERR("StopLEDiscovery Failed: %s", err->message);
674 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
676 /* Send event to application */
677 BT_INFO("[Connectable]");
678 param = g_variant_new("(in)", result, mode);
679 _bt_send_event(BT_ADAPTER_EVENT,
680 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
683 _bt_get_discoverable_mode(&mode);
685 /* Event will be sent by "DiscoverableTimeout" signal */
686 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
688 g_variant_unref(val);
692 /* Send event to application */
693 BT_INFO("[General Discoverable]");
694 param = g_variant_new("(in)", result, mode);
695 _bt_send_event(BT_ADAPTER_EVENT,
696 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
699 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
700 _bt_get_discoverable_mode(&mode);
702 /* Event was already sent by "Discoverable" signal */
703 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
704 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
706 g_variant_unref(val);
710 /* Send event to application */
711 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
712 _bt_get_discoverable_timeout_property());
713 param = g_variant_new("(in)", result, mode);
714 _bt_send_event(BT_ADAPTER_EVENT,
715 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
717 } else if (strcasecmp(property, "Powered") == 0) {
718 /* TODO: Need to check this operation!! */
719 gboolean powered = FALSE;
722 g_variant_get(val, "b" ,&powered);
723 BT_DBG("Powered = %d", powered);
724 if (powered == FALSE) {
726 _bt_handle_adapter_removed();
728 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
729 bt_state != VCONFKEY_BT_STATUS_OFF) {
730 _bt_disable_adapter();
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);
740 _bt_handle_adapter_added();
743 } else if (strcasecmp(property, "Connectable") == 0) {
744 gboolean connectable = FALSE;
746 g_variant_get(val, "b", &connectable);
748 BT_DBG("Connectable property is changed : %d", connectable);
749 param = g_variant_new("(b)", connectable);
750 _bt_send_event(BT_ADAPTER_EVENT,
751 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
753 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
754 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
756 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
757 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
760 GVariantIter *iter = NULL;
761 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");
770 g_variant_iter_free(iter);
772 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
773 gboolean ipsp_initialized = FALSE;
775 g_variant_get(val, "b", &ipsp_initialized);
776 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
777 param = g_variant_new("(b)", ipsp_initialized);
779 /* Send event to application */
780 _bt_send_event(BT_ADAPTER_EVENT,
781 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
787 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
791 GVariantIter value_iter;
792 GVariant *child = NULL, *val = NULL;
793 char *property = NULL;
794 g_variant_iter_init (&value_iter, msg);
795 while ((child = g_variant_iter_next_value (&value_iter))) {
796 g_variant_get(child, "{sv}", &property, &val);
798 ret_if(property == NULL);
800 BT_DBG("property :%s", property);
802 if (strcasecmp(property, "Status") == 0) {
804 g_variant_get(val, "s", &status);
806 if (strcasecmp(status, "active") == 0){
807 _bt_obex_transfer_started(path);
808 } else if (strcasecmp(status, "complete") == 0) {
809 _bt_obex_transfer_completed(path, TRUE);
810 _bt_pbap_obex_transfer_completed(path, TRUE);
811 } else if (strcasecmp(status, "error") == 0){
812 _bt_obex_transfer_completed(path, FALSE);
813 _bt_pbap_obex_transfer_completed(path, FALSE);
816 } else if (strcasecmp(property, "Transferred") == 0) {
817 static int transferred = 0;
818 g_variant_get(val, "t", &transferred);
820 _bt_obex_transfer_progress(path,transferred);
823 g_variant_unref(val);
824 g_variant_unref(child);
829 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
834 int result = BLUETOOTH_ERROR_NONE;
835 GVariantIter value_iter;
837 char *property = NULL;
839 GVariant *param = NULL;
840 bt_remote_dev_info_t *remote_dev_info;
841 g_variant_iter_init (&value_iter, msg);
842 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
843 BT_DBG("Property %s", property);
844 if (strcasecmp(property, "Connected") == 0) {
847 g_variant_get(val, "i", &connected);
849 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
850 BLUETOOTH_EVENT_DEVICE_CONNECTED :
851 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
853 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
855 _bt_convert_device_path_to_address(path, address);
857 BT_DBG("connected: %d", connected);
858 BT_DBG("address: %s", address);
860 remote_dev_info = _bt_get_remote_device_info(address);
862 if (remote_dev_info != NULL) {
863 __bt_device_remote_connected_properties(
864 remote_dev_info, address,
865 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
867 _bt_free_device_info(remote_dev_info);
869 param = g_variant_new("(is)", result, address);
870 /* Send event to application */
871 _bt_send_event(BT_DEVICE_EVENT,
875 } else if (strcasecmp(property, "RSSI") == 0) {
876 bt_remote_dev_info_t *remote_dev_info;
878 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
880 _bt_convert_device_path_to_address(path, address);
881 BT_DBG("address: %s", address);
883 remote_dev_info = _bt_get_remote_device_info(address);
884 if (remote_dev_info == NULL) {
886 g_variant_unref(val);
890 BT_DBG("Address type %d", remote_dev_info->addr_type);
892 if (remote_dev_info->addr_type == 0) {
893 BT_DBG("Name %s", remote_dev_info->name);
895 #ifdef TIZEN_DPM_ENABLE
896 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
898 bluetooth_device_class_t device_class;
899 _bt_divide_device_class(&device_class, remote_dev_info->class);
901 if (device_class.major_class ==
902 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
903 _bt_free_device_info(remote_dev_info);
905 g_variant_unref(val);
912 GVariant *uuids = NULL;
913 GVariantBuilder *builder = NULL;
915 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
916 for (i=0; i < remote_dev_info->uuid_count; i++) {
917 g_variant_builder_add(builder, "s",
918 remote_dev_info->uuids[i]);
920 uuids = g_variant_new("as", builder);
921 g_variant_builder_unref(builder);
922 GVariant *manufacturer_data = NULL;
923 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
924 remote_dev_info->manufacturer_data,
925 remote_dev_info->manufacturer_data_len,
928 param = g_variant_new("(isunsbub@asn@ay)", result,
929 remote_dev_info->address,
930 remote_dev_info->class,
931 remote_dev_info->rssi,
932 remote_dev_info->name,
933 remote_dev_info->paired,
934 remote_dev_info->connected,
935 remote_dev_info->trust,
937 remote_dev_info->manufacturer_data_len,
940 _bt_send_event(BT_ADAPTER_EVENT,
941 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
945 _bt_free_device_info(remote_dev_info);
946 } else if (strcasecmp(property, "GattConnected") == 0) {
947 gboolean gatt_connected = FALSE;
949 g_variant_get(val, "b", &gatt_connected);
951 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
952 BLUETOOTH_EVENT_GATT_DISCONNECTED;
954 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
956 _bt_convert_device_path_to_address(path, address);
958 BT_DBG("gatt_connected: %d", gatt_connected);
959 BT_DBG("address: %s", address);
960 param = g_variant_new("(is)", result, address);
961 /* Send event to application */
962 _bt_send_event(BT_DEVICE_EVENT,
966 } else if (strcasecmp(property, "Paired") == 0) {
967 gboolean paired = FALSE;
968 bt_remote_dev_info_t *remote_dev_info;
969 g_variant_get(val, "b", &paired);
970 _bt_agent_set_canceled(FALSE);
971 /* BlueZ sends paired signal for each paired device */
972 /* during activation, We should ignore this, otherwise*/
973 /* application thinks that a new device got paired */
974 if (_bt_adapter_get_status() != BT_ACTIVATED) {
975 BT_DBG("BT is not activated, so ignore this");
977 g_variant_unref(val);
981 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
983 _bt_convert_device_path_to_address(path, address);
985 remote_dev_info = _bt_get_remote_device_info(address);
986 if (remote_dev_info == NULL) {
988 g_variant_unref(val);
993 if(paired == FALSE) {
994 BT_INFO("Unpaired: %s", address);
995 __bt_update_remote_cache_devinfo(address, FALSE);
996 param = g_variant_new("(is)", result, address);
997 _bt_send_event(BT_ADAPTER_EVENT,
998 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1001 BT_INFO("Paired: %s", address);
1002 __bt_update_remote_cache_devinfo(address, TRUE);
1004 if (_bt_is_device_creating() == TRUE) {
1005 BT_DBG("Try to Pair by me");
1006 _bt_free_device_info(remote_dev_info);
1009 g_variant_unref(val);
1012 GVariant *uuids = NULL;
1013 GVariantBuilder *builder = NULL;
1015 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1016 for (i=0; i < remote_dev_info->uuid_count; i++) {
1017 g_variant_builder_add(builder, "s",
1018 remote_dev_info->uuids[i]);
1020 uuids = g_variant_new("as", builder);
1021 g_variant_builder_unref(builder);
1022 GVariant *manufacturer_data = NULL;
1023 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1024 remote_dev_info->manufacturer_data,
1025 remote_dev_info->manufacturer_data_len,
1029 param = g_variant_new("(isunsbub@asn@ay)", result,
1030 address, remote_dev_info->class,
1031 remote_dev_info->rssi,
1032 remote_dev_info->name,
1033 remote_dev_info->paired,
1034 remote_dev_info->connected,
1035 remote_dev_info->trust,
1037 remote_dev_info->manufacturer_data_len,
1039 _bt_send_event(BT_ADAPTER_EVENT,
1040 BLUETOOTH_EVENT_BONDING_FINISHED,
1043 _bt_free_device_info(remote_dev_info);
1045 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1046 gboolean paired = FALSE;
1047 bt_remote_dev_info_t *remote_dev_info;
1049 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1050 BT_DBG("BT is not activated, so ignore this");
1052 g_variant_unref(val);
1056 g_variant_get(val, "b", &paired);
1057 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1058 BT_DBG("LegacyPaired: %d", paired);
1059 _bt_convert_device_path_to_address(path, address);
1061 remote_dev_info = _bt_get_remote_device_info(address);
1062 if (remote_dev_info == NULL) {
1065 g_variant_unref(val);
1069 BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
1070 remote_dev_info->name);
1071 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1072 remote_dev_info->name, NULL, NULL, NULL);
1074 _bt_free_device_info(remote_dev_info);
1076 } else if (strcasecmp(property, "Trusted") == 0) {
1077 gboolean trusted = FALSE;
1079 g_variant_get(val, "b", &trusted);
1081 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1082 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1084 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1086 _bt_convert_device_path_to_address(path, address);
1088 BT_DBG("trusted: %d", trusted);
1089 BT_DBG("address: %s", address);
1090 param = g_variant_new("(is)", result, address);
1091 /* Send event to application */
1092 _bt_send_event(BT_DEVICE_EVENT,
1096 } else if (strcasecmp(property, "IpspConnected") == 0) {
1097 gboolean connected = FALSE;
1099 g_variant_get(val, "b", &connected);
1102 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1103 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1105 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1107 _bt_convert_device_path_to_address(path, address);
1109 BT_DBG("Ipspconnected: %d", connected);
1110 BT_DBG("address: %s", address);
1111 param = g_variant_new("(is)", result, address);
1113 /* Send event to application */
1114 _bt_send_event(BT_DEVICE_EVENT,
1123 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1126 int result = BLUETOOTH_ERROR_NONE;
1127 GVariantIter value_iter;
1128 char *property = NULL;
1130 GVariant *val = NULL;
1131 GVariant *child = NULL;
1132 bt_remote_dev_info_t *remote_dev_info;
1133 GVariant *param = NULL;
1134 g_variant_iter_init (&value_iter, msg);
1135 while ((child = g_variant_iter_next_value (&value_iter))) {
1136 g_variant_get(child, "{sv}", &property, &val);
1137 BT_INFO("Property %s", property);
1138 if (strcasecmp(property, "Connected") == 0) {
1139 gboolean connected = FALSE;
1141 g_variant_get(val, "b", &connected);
1143 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1144 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1146 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1148 _bt_convert_device_path_to_address(path, address);
1150 BT_DBG("connected: %d", connected);
1151 BT_DBG("address: %s", address);
1153 remote_dev_info = _bt_get_remote_device_info(address);
1155 if (remote_dev_info != NULL) {
1156 __bt_device_remote_connected_properties(
1157 remote_dev_info, address, connected);
1158 _bt_free_device_info(remote_dev_info);
1160 param = g_variant_new("(is)", result, address);
1161 /* Send event to application */
1162 _bt_send_event(BT_AVRCP_EVENT,
1168 g_variant_unref(child);
1169 g_variant_unref(val);
1174 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1176 char *interface_name = NULL;
1177 GVariant *val = NULL;
1179 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val,NULL);
1181 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1182 __bt_adapter_property_changed_event(val,
1184 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1185 __bt_device_property_changed_event(val,object_path);
1186 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1187 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1188 __bt_obex_property_changed_event(val,
1190 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1191 __bt_media_control_changed_event(val,
1193 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1194 _bt_handle_avrcp_control_event(val,
1196 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1197 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1198 _bt_handle_network_client_event(val,
1200 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1201 __bt_gatt_char_property_changed_event(val,
1204 g_variant_unref(val);
1207 void __bt_opc_property_changed_event(GVariant *msg,
1210 GVariantIter value_iter;
1211 char *property = NULL;
1212 GVariant *val = NULL;
1213 GVariant *child = NULL;
1215 g_variant_iter_init (&value_iter, msg);
1216 while ((child = g_variant_iter_next_value (&value_iter))) {
1217 g_variant_get(child, "{sv}", &property, &val);
1218 ret_if(property == NULL);
1220 if (strcasecmp(property, "Status") == 0) {
1221 char *status = NULL;
1222 g_variant_get(val, "s", &status);
1223 BT_DBG("Status is %s", status);
1225 if(strcasecmp(status, "active") == 0){
1226 _bt_obex_client_started(path);
1227 }else if (strcasecmp(status, "complete") == 0) {
1228 _bt_obex_client_completed(path, TRUE);
1229 }else if (strcasecmp(status, "error") == 0){
1230 _bt_obex_client_completed(path, FALSE);
1233 } else if (strcasecmp(property, "Transferred") == 0) {
1234 static int transferred = 0;
1235 g_variant_get(val, "t", &transferred);
1237 _bt_obex_client_progress(path, transferred);
1239 BT_DBG("property : [%s]", property);
1242 g_variant_unref(child);
1243 g_variant_unref(val);
1247 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1249 char *interface_name = NULL;
1250 GVariant *value = NULL;
1251 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1252 BT_INFO("interface_name = %s", interface_name);
1253 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1254 __bt_opc_property_changed_event(value,
1257 BT_DBG("interface_name : [%s]", interface_name);
1259 g_variant_unref(value);
1263 void _bt_handle_input_event(GVariant *msg, const char *path)
1265 int result = BLUETOOTH_ERROR_NONE;
1266 gboolean property_flag = FALSE;
1267 GVariantIter value_iter;
1268 char *property = NULL;
1269 GVariant *child = NULL, *val = NULL;
1270 bt_remote_dev_info_t *remote_dev_info;
1271 GVariant *param = NULL;
1272 g_variant_iter_init (&value_iter, msg);
1273 while ((child = g_variant_iter_next_value (&value_iter))) {
1274 g_variant_get(child, "{sv}", &property, &val);
1276 ret_if(property == NULL);
1278 if (strcasecmp(property, "Connected") == 0) {
1279 int event = BLUETOOTH_EVENT_NONE;
1281 g_variant_get(val, "b", &property_flag);
1283 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1285 _bt_convert_device_path_to_address(path, address);
1287 event = (property_flag == TRUE) ?
1288 BLUETOOTH_HID_CONNECTED :
1289 BLUETOOTH_HID_DISCONNECTED;
1290 param = g_variant_new("(is)", result, address);
1291 _bt_send_event(BT_HID_EVENT, event,
1293 /* Check HID connection type (Keyboard or Mouse) and update the status */
1294 remote_dev_info = _bt_get_remote_device_info(address);
1296 if (property_flag == TRUE) {
1297 hid_connected_device_count++;
1298 __bt_set_device_values(TRUE,
1299 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1301 hid_connected_device_count--;
1302 if (hid_connected_device_count == 0)
1303 __bt_set_device_values(FALSE,
1304 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1307 if (remote_dev_info != NULL) {
1308 BT_DBG("HID device class [%x]", remote_dev_info->class);
1309 if (remote_dev_info->class &
1310 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1311 #ifdef ENABLE_TIZEN_2_4
1312 __bt_set_device_values(property_flag,
1313 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1318 if (remote_dev_info->class &
1319 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1320 #ifdef ENABLE_TIZEN_2_4
1321 __bt_set_device_values(property_flag,
1322 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1325 _bt_free_device_info(remote_dev_info);
1330 g_variant_unref(val);
1331 g_variant_unref(child);
1335 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1337 int result = BLUETOOTH_ERROR_NONE;
1338 char *address = NULL;
1339 char *device = NULL;
1340 GVariant *param = NULL;
1341 ret_if(member == NULL);
1342 if (strcasecmp(member, "PeerConnected") == 0) {
1343 g_variant_get(msg, "(ss)", &device, &address);
1345 __bt_set_device_values(TRUE,
1346 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1347 param = g_variant_new("(iss)", result, device, address);
1348 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1352 nap_connected_device_count++;
1353 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1354 g_variant_get(msg, "(ss)", &device, &address);
1355 nap_connected_device_count--;
1356 if (nap_connected_device_count == 0)
1357 __bt_set_device_values(FALSE,
1358 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1359 param = g_variant_new("(iss)", result, device, address);
1360 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1367 void _bt_handle_network_client_event(GVariant *msg,
1372 int result = BLUETOOTH_ERROR_NONE;
1373 gboolean property_flag = FALSE;
1374 char *property = NULL;
1375 GVariant *val = NULL;
1376 GVariantIter value_iter;
1377 GVariant *param = NULL;
1378 g_variant_iter_init (&value_iter, msg);
1379 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1380 if (strcasecmp(property, "Connected") == 0) {
1381 int event = BLUETOOTH_EVENT_NONE;
1384 g_variant_get(val, "b", &property_flag);
1385 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1387 _bt_convert_device_path_to_address(path, address);
1389 BT_DBG("property_flag %d", property_flag);
1390 if (property_flag == TRUE) {
1391 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1392 nap_connected_device_count++;
1393 __bt_set_device_values(TRUE,
1394 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1396 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1397 nap_connected_device_count--;
1398 if (nap_connected_device_count == 0)
1399 __bt_set_device_values(FALSE,
1400 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1402 param = g_variant_new("(is)", result, address);
1403 _bt_send_event(BT_NETWORK_EVENT, event,
1412 void __bt_gatt_char_property_changed_event(GVariant *msg,
1415 GVariantIter value_iter;
1416 char *property = NULL;
1417 char * char_handle = NULL;
1418 GVariant *val = NULL;
1419 int result = BLUETOOTH_ERROR_NONE;
1420 GVariant *param = NULL;
1421 g_variant_iter_init (&value_iter, msg);
1422 char_handle = g_strdup(path);
1423 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1424 BT_INFO("Property %s", property);
1426 ret_if(property == NULL);
1428 if (strcasecmp(property, "Notifying") == 0) {
1429 gboolean property_flag = FALSE;
1430 g_variant_get(val, "b", &property_flag);
1431 if (property_flag == TRUE)
1432 BT_DBG("notifying is enabled");
1434 BT_DBG("notifying is disabled");
1435 } else if (strcasecmp(property, "ChangedValue") == 0) {
1437 GByteArray *gp_byte_array = NULL;
1438 BT_INFO("Type '%s'\n", g_variant_get_type_string (val));
1441 gp_byte_array = g_byte_array_new();
1442 len = g_variant_get_size(val);
1443 BT_DBG("Len = %d", len);
1444 g_byte_array_append (gp_byte_array,
1445 (const guint8 *) g_variant_get_data(val), len);
1446 if (gp_byte_array->len != 0) {
1447 GVariant *byte_array = NULL;
1448 byte_array = g_variant_new_from_data(
1449 G_VARIANT_TYPE_BYTESTRING,
1450 gp_byte_array->data,
1453 param = g_variant_new("(is@ay)", result, char_handle,
1456 /* Send event only registered client */
1457 _bt_send_char_value_changed_event(param);
1459 g_byte_array_free(gp_byte_array, TRUE);
1463 g_free(char_handle);
1466 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1468 ret_if(path == NULL);
1470 if (strcasecmp(member, "GattValueChanged") == 0) {
1473 /*** Debug only ***/
1474 GVariant *value = NULL;
1476 char *buffer = NULL;
1478 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1479 value_len = g_variant_get_size(value);
1480 if (value_len > 0) {
1481 char buf[8 * 5 + 1] = { 0 };
1484 buffer = (char *)g_variant_get_data(value);
1485 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1487 for (i = 0; i < to; i++)
1488 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1490 BT_DBG("GATT Val[%d] %s", value_len, buf);
1492 g_variant_unref(value);
1496 /* Send event only registered client */
1497 _bt_send_char_value_changed_event(msg);
1502 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1505 int result = BLUETOOTH_ERROR_NONE;
1508 const char *property = NULL;
1509 GVariant *param = NULL;
1510 ret_if(path == NULL);
1512 if (strcasecmp(member, "PropertyChanged") == 0) {
1514 g_variant_get(msg, "(s)", &property);
1516 ret_if(property == NULL);
1518 if (strcasecmp(property, "GattConnected") == 0) {
1519 gboolean connected = FALSE;
1521 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1522 ret_if(address == NULL);
1524 _bt_convert_device_path_to_address(path, address);
1525 g_variant_get(msg, "(b)", &connected);
1527 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1528 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1529 param = g_variant_new("(is)", result, address);
1530 _bt_send_event(BT_DEVICE_EVENT,
1534 } else if (strcasecmp(property, "Paired") == 0) {
1535 gboolean paired = FALSE;
1536 bt_remote_dev_info_t *remote_dev_info;
1537 g_variant_get(msg, "(b)", &paired);
1539 ret_if(paired == FALSE);
1541 /* BlueZ sends paired signal for each paired device */
1542 /* during activation, We should ignore this, otherwise*/
1543 /* application thinks that a new device got paired */
1544 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1545 BT_DBG("BT is not activated, so ignore this");
1549 if (_bt_is_device_creating() == TRUE) {
1550 BT_DBG("Try to Pair by me");
1554 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1555 ret_if(address == NULL);
1557 _bt_convert_device_path_to_address(path, address);
1559 remote_dev_info = _bt_get_remote_device_info(address);
1560 if (remote_dev_info == NULL) {
1564 GVariant *uuids = NULL;
1565 GVariantBuilder *builder = NULL;
1567 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1568 for (i=0; i < remote_dev_info->uuid_count; i++) {
1569 g_variant_builder_add(builder, "s",
1570 remote_dev_info->uuids[i]);
1572 uuids = g_variant_new("as", builder);
1573 g_variant_builder_unref(builder);
1574 GVariant *manufacturer_data = NULL;
1575 manufacturer_data = g_variant_new_from_data(
1576 G_VARIANT_TYPE_BYTESTRING,
1577 remote_dev_info->manufacturer_data,
1578 remote_dev_info->manufacturer_data_len,
1580 param = g_variant_new("(isunsbub@asn@ay)", result,
1582 remote_dev_info->class,
1583 remote_dev_info->rssi,
1584 remote_dev_info->name,
1585 remote_dev_info->paired,
1586 remote_dev_info->connected,
1587 remote_dev_info->trust,
1589 remote_dev_info->manufacturer_data_len,
1591 _bt_send_event(BT_ADAPTER_EVENT,
1592 BLUETOOTH_EVENT_BONDING_FINISHED,
1594 _bt_free_device_info(remote_dev_info);
1597 } else if (strcasecmp(property, "UUIDs") == 0) {
1598 /* Once we get the updated uuid information after
1599 * reverse service search, update it to application */
1601 bt_remote_dev_info_t *remote_dev_info;
1603 ret_if(_bt_is_device_creating() == TRUE);
1605 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1606 ret_if(address == NULL);
1608 _bt_convert_device_path_to_address(path, address);
1610 remote_dev_info = _bt_get_remote_device_info(address);
1611 if (remote_dev_info == NULL) {
1616 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1617 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1618 GVariant *uuids = NULL;
1619 GVariantBuilder *builder = NULL;
1621 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1622 for (i=0; i < remote_dev_info->uuid_count; i++) {
1623 g_variant_builder_add(builder, "s",
1624 remote_dev_info->uuids[i]);
1626 uuids = g_variant_new("as", builder);
1627 g_variant_builder_unref(builder);
1628 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1629 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1632 param = g_variant_new("(isunsbub@asn@ay)", result,
1633 address, remote_dev_info->class,
1634 remote_dev_info->rssi,
1635 remote_dev_info->name,
1636 remote_dev_info->paired,
1637 remote_dev_info->connected,
1638 remote_dev_info->trust,
1640 remote_dev_info->manufacturer_data_len,
1642 _bt_send_event(BT_ADAPTER_EVENT,
1643 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1647 _bt_free_device_info(remote_dev_info);
1650 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1651 unsigned char addr_type = 0;
1653 g_variant_get(msg, "(y)", &addr_type);
1655 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1656 ret_if(address == NULL);
1658 _bt_convert_device_path_to_address(path, address);
1659 dev_name = _bt_get_bonded_device_name(address);
1661 BT_INFO("Address : %s Type : %d", address, addr_type);
1662 BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1663 !addr_type ? dev_name : address);
1666 _bt_logging_connection(TRUE, addr_type);
1667 #ifdef ENABLE_TIZEN_2_4
1668 journal_bt_connected();
1670 param = g_variant_new("(isy)", result, address, addr_type);
1671 /*Send event to application*/
1672 _bt_send_event(BT_DEVICE_EVENT,
1673 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1676 } else if (strcasecmp(member, "Disconnected") == 0) {
1677 unsigned char disc_reason = 0;
1678 unsigned char addr_type = 0;
1679 gboolean sending = FALSE;
1681 g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
1683 result = disc_reason;
1685 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1686 ret_if(address == NULL);
1688 _bt_convert_device_path_to_address(path, address);
1689 dev_name = _bt_get_bonded_device_name(address);
1690 #ifdef ENABLE_TIZEN_2_4
1691 journal_bt_disconnected();
1694 /* 0x00 BDADDR_BRDER
1695 0x01 BDADDR_LE_PUBLIC
1696 0x02 BDADDR_LE_RANDOM */
1697 BT_INFO("Address : %s Type : %d", address, addr_type);
1698 BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1699 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1700 !addr_type ? dev_name : address);
1703 _bt_headset_set_local_connection(FALSE);
1704 _bt_logging_connection(FALSE, addr_type);
1706 /*Check for any OPP transfer on the device and cancel
1709 _bt_obex_check_pending_transfer(address);
1710 _bt_opp_client_is_sending(&sending);
1712 _bt_opp_client_check_pending_transfer(address);
1713 param = g_variant_new("(isy)", result, address, addr_type);
1714 _bt_send_event(BT_DEVICE_EVENT,
1715 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1718 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1720 char *profile_uuid = NULL;
1721 bt_headset_wait_t *wait_list;
1723 g_variant_get(msg, "(si)", &profile_uuid, &state);
1725 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1726 ret_if(address == NULL);
1728 _bt_convert_device_path_to_address(path, address);
1730 BT_DBG("Address: %s", address);
1731 BT_DBG("Profile UUID: %s", profile_uuid);
1732 BT_DBG("State: %d", state);
1734 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1735 (state == BT_PROFILE_STATE_CONNECTED)) {
1737 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1738 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1739 bluetooth_device_address_t device_address;
1741 bt_headset_wait_t *wait_list;
1743 __bt_set_device_values(TRUE,
1744 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1746 __bt_connection_manager_set_state(address, event);
1748 if (_bt_headset_get_local_connection() == FALSE)
1749 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1751 /* Connection Started from local device therefore no need to
1752 * intiate connection for pending profile */
1753 _bt_headset_set_local_connection(FALSE);
1755 param = g_variant_new("(is)", result, address);
1756 _bt_send_event(BT_HEADSET_EVENT, event,
1758 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1761 if (g_strcmp0(connected_address, address) != 0) {
1762 _bt_convert_addr_string_to_type(
1763 device_address.addr,
1765 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1766 &device_address, NULL);
1770 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1771 BT_STATE_CONNECTED, address);
1773 wait_list = _bt_get_audio_wait_data();
1774 if (wait_list != NULL &&
1775 (g_strcmp0(wait_list->address, address) == 0))
1776 _bt_rel_wait_data();
1778 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1779 (state == BT_PROFILE_STATE_DISCONNECTED)) {
1781 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
1783 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
1785 g_free(profile_uuid);
1789 __bt_set_device_values(FALSE,
1790 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1792 __bt_connection_manager_set_state(address, event);
1793 param = g_variant_new("(is)", result, address);
1794 _bt_send_event(BT_HEADSET_EVENT, event,
1796 /* Remove data from the connected list */
1797 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
1798 wait_list = _bt_get_audio_wait_data();
1800 if (wait_list == NULL) {
1802 g_free(profile_uuid);
1806 if (((wait_list->type == BT_AUDIO_ALL) &&
1807 (wait_list->ag_flag == TRUE)) ||
1808 (wait_list->type == BT_AUDIO_A2DP) ||
1809 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
1810 bluetooth_device_address_t device_address;
1811 _bt_convert_addr_string_to_type(
1812 device_address.addr,
1813 wait_list->address);
1815 _bt_audio_connect(wait_list->req_id,
1818 wait_list->out_param1);
1820 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
1822 if (state == BT_PROFILE_STATE_CONNECTED) {
1823 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
1824 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1825 bluetooth_device_address_t device_address;
1827 param = g_variant_new("(is)", result, address);
1828 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1830 connected = _bt_is_headset_type_connected(
1834 if (g_strcmp0(connected_address,
1836 _bt_convert_addr_string_to_type(
1837 device_address.addr,
1839 _bt_audio_disconnect(0,
1841 &device_address, NULL);
1844 BT_DBG("device Path: %s", path);
1845 _bt_add_headset_to_list(BT_AVRCP,
1846 BT_STATE_CONNECTED, address);
1847 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1848 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
1849 param = g_variant_new("(is)", result, address);
1850 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
1852 /* Remove data from the connected list */
1853 _bt_remove_headset_from_list(BT_AVRCP, address);
1855 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
1856 if (state == BT_PROFILE_STATE_CONNECTED) {
1857 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
1858 BT_INFO("A2DP Source is connected");
1859 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1860 g_variant_new("(is)", result, address));
1861 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1862 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
1863 BT_INFO("A2DP Source Disconnected");
1864 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
1865 g_variant_new("(is)", result, address));
1867 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
1868 ((state == BT_PROFILE_STATE_CONNECTED) ||
1869 (state == BT_PROFILE_STATE_DISCONNECTED))) {
1871 if (state == BT_PROFILE_STATE_CONNECTED)
1872 event = BLUETOOTH_HID_CONNECTED;
1874 event = BLUETOOTH_HID_DISCONNECTED;
1875 param = g_variant_new("(is)", result, address);
1876 _bt_send_event(BT_HID_EVENT, event,
1879 if (state == BT_PROFILE_STATE_CONNECTED)
1880 __bt_set_device_values(TRUE,
1881 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1883 __bt_set_device_values(FALSE,
1884 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1887 g_free(profile_uuid);
1888 } else if (strcasecmp(member, "AdvReport") == 0) {
1890 bt_remote_le_dev_info_t *le_dev_info = NULL;
1891 char *buffer = NULL;
1893 bt_le_adv_info_t *adv_info = NULL;
1894 GVariant *value = NULL;
1895 ret_if(_bt_is_le_scanning() == FALSE);
1897 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
1898 if (le_dev_info == NULL)
1901 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
1902 &le_dev_info->addr_type,
1903 &le_dev_info->adv_type,
1905 &le_dev_info->adv_data_len,
1907 buffer_len = g_variant_get_size(value);
1909 buffer = (char *)g_variant_get_data(value);
1911 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
1912 if (le_dev_info->adv_data == NULL &&
1913 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
1914 _bt_free_le_device_info(le_dev_info);
1915 g_variant_unref(value);
1919 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1920 _bt_send_scan_result_event(le_dev_info, NULL);
1921 _bt_free_le_device_info(le_dev_info);
1922 g_variant_unref(value);
1926 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
1927 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
1928 if (adv_info == NULL) {
1929 _bt_free_le_device_info(le_dev_info);
1930 g_variant_unref(value);
1934 adv_info->addr = g_strdup(le_dev_info->address);
1935 adv_info->data_len = le_dev_info->adv_data_len;
1936 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
1937 if (adv_info->data) {
1938 memcpy(adv_info->data, le_dev_info->adv_data,
1939 le_dev_info->adv_data_len);
1941 __bt_add_adv_ind_info(adv_info);
1944 } else { /* SCAN_RSP */
1945 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
1947 _bt_send_scan_result_event(le_dev_info, adv_info);
1948 __bt_del_adv_ind_info(le_dev_info->address);
1951 _bt_free_le_device_info(le_dev_info);
1952 g_variant_unref(value);
1953 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
1959 g_variant_get(msg, "(qqqq)",
1960 tx_octets, tx_time, rx_octets, rx_time);
1962 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1963 _bt_convert_device_path_to_address(path, address);
1965 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
1966 rx_octets, rx_time);
1967 /* Send event to application */
1968 _bt_send_event(BT_DEVICE_EVENT, event, param);
1974 void __bt_set_audio_values(gboolean connected, char *address)
1977 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1979 /* Set the headset name */
1980 if (connected == TRUE) {
1981 name = _bt_get_bonded_device_name(address);
1983 name = g_strdup("");
1986 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
1988 BT_ERR("vconf_set_str failed");
1993 /* Set the headset state */
1994 if (vconf_get_int(VCONFKEY_BT_DEVICE,
1995 &bt_device_state) != 0) {
1996 BT_ERR("vconf_get_str failed");
1999 #ifdef TIZEN_SUPPORT_DUAL_HF
2000 if ((connected == TRUE) &&
2001 (FALSE == __bt_is_companion_device(address))) {
2002 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2003 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2004 (FALSE == __bt_is_companion_device(address))) {
2005 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2008 if (connected == TRUE) {
2009 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2010 } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
2011 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2015 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2016 bt_device_state) != 0) {
2017 BT_ERR("vconf_set_int failed");
2021 void _bt_handle_headset_event(GVariant *msg, const char *path)
2023 int result = BLUETOOTH_ERROR_NONE;
2024 gboolean property_flag = FALSE;
2025 char *property = NULL;
2026 GVariant *value = NULL;
2027 GVariant *param = NULL;
2028 g_variant_get(msg, "(sv)", &property, &value);
2030 ret_if(property == NULL);
2032 BT_DBG("Property = %s \n", property);
2033 /* We allow only 1 headset connection (HSP or HFP)*/
2034 if (strcasecmp(property, "Connected") == 0) {
2035 int event = BLUETOOTH_EVENT_NONE;
2036 bt_headset_wait_t *wait_list;
2038 g_variant_get(value, "b", &property_flag);
2040 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2042 /* Fix : NULL_RETURNS */
2043 if (address == NULL)
2046 _bt_convert_device_path_to_address(path, address);
2048 if (property_flag == TRUE) {
2049 event = BLUETOOTH_EVENT_AG_CONNECTED;
2050 if (_bt_headset_get_local_connection() == FALSE)
2051 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2053 _bt_headset_set_local_connection(FALSE);
2057 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2059 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2060 if (previous_state == BT_STATE_DISCONNECTING)
2061 _bt_send_hf_local_term_event(address);
2063 /* Set the State machine here */
2064 __bt_connection_manager_set_state(address, event);
2065 __bt_set_audio_values(property_flag, address);
2066 param = g_variant_new("(is)", result, address);
2067 _bt_send_event(BT_HEADSET_EVENT, event,
2070 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2071 /* Remove data from the connected list */
2072 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2074 wait_list = _bt_get_audio_wait_data();
2075 if (wait_list == NULL) {
2080 bluetooth_device_address_t device_address;
2082 _bt_set_audio_wait_data_flag(TRUE);
2084 _bt_convert_addr_string_to_type(device_address.addr,
2085 wait_list->address);
2086 _bt_audio_connect(wait_list->req_id, wait_list->type,
2087 &device_address, wait_list->out_param1);
2088 _bt_rel_wait_data();
2089 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2090 /* Add data to the connected list */
2091 _bt_add_headset_to_list(BT_AUDIO_HSP,
2092 BT_STATE_CONNECTED, address);
2094 wait_list = _bt_get_audio_wait_data();
2095 if (wait_list != NULL &&
2096 (g_strcmp0(wait_list->address, address) == 0))
2097 _bt_rel_wait_data();
2099 BT_INFO("Check A2DP pending connect");
2100 _bt_audio_check_pending_connect();
2103 } else if (strcasecmp(property, "State") == 0) {
2106 g_variant_get(value, "s", &state);
2108 /* This code assumes we support only 1 headset connection */
2109 /* Need to use the headset list, if we support multi-headsets */
2110 if (strcasecmp(state, "Playing") == 0) {
2111 BT_DBG("Playing: Sco Connected");
2112 } else if (strcasecmp(state, "connected") == 0 ||
2113 strcasecmp(state, "disconnected") == 0) {
2114 BT_DBG("connected/disconnected: Sco Disconnected");
2116 BT_ERR("Not handled state - %s", state);
2121 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2125 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2127 _bt_convert_device_path_to_address(path, address);
2129 g_variant_get(value, "i", &spkr_gain);
2130 param = g_variant_new("(isq)", result, address, spkr_gain);
2131 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2135 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2139 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2141 _bt_convert_device_path_to_address(path, address);
2143 g_variant_get(value, "i", &mic_gain);
2144 param = g_variant_new("(isq)", result, address, mic_gain);
2145 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2152 g_variant_unref(value);
2155 void _bt_handle_sink_event(GVariant *msg, const char *path)
2157 GVariantIter value_iter;
2158 char *property = NULL;
2160 bt_headset_wait_t *wait_list;
2162 GVariant *child = NULL;
2163 GVariant *val = NULL;
2164 GVariant *param = NULL;
2165 g_variant_iter_init (&value_iter, msg);
2166 while ((child = g_variant_iter_next_value (&value_iter))) {
2168 g_variant_get(child, "{sv}", &property, &val);
2170 ret_if(property == NULL);
2172 BT_DBG("Property = %s \n", property);
2175 if (strcasecmp(property, "State") == 0) {
2176 int result = BLUETOOTH_ERROR_NONE;
2179 g_variant_get(val, "s", &value);
2180 BT_DBG("value: %s", value);
2182 if (g_strcmp0(value, "disconnected") == 0) {
2185 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2187 _bt_convert_device_path_to_address(path, address);
2189 __bt_set_device_values(FALSE,
2190 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2191 param = g_variant_new("(is)", result, address);
2192 _bt_send_event(BT_HEADSET_EVENT,
2193 BLUETOOTH_EVENT_AV_DISCONNECTED,
2196 /* Remove data from the connected list */
2197 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2198 wait_list = _bt_get_audio_wait_data();
2199 if (wait_list == NULL) {
2202 g_variant_unref(val);
2203 g_variant_unref(child);
2208 if (((wait_list->type == BT_AUDIO_ALL) &&
2209 (wait_list->ag_flag == TRUE)) ||
2210 (wait_list->type == BT_AUDIO_A2DP) ||
2211 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2212 bluetooth_device_address_t device_address;
2213 _bt_convert_addr_string_to_type(
2214 device_address.addr,
2215 wait_list->address);
2217 _bt_audio_connect(wait_list->req_id,
2220 wait_list->out_param1);
2223 }else if (strcasecmp(value, "Connected") == 0) {
2225 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2226 bluetooth_device_address_t device_address;
2229 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2231 _bt_convert_device_path_to_address(path, address);
2233 __bt_set_device_values(TRUE,
2234 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2235 param = g_variant_new("(is)", result, address);
2236 _bt_send_event(BT_HEADSET_EVENT,
2237 BLUETOOTH_EVENT_AV_CONNECTED,
2239 /* Check for existing Media device to disconnect */
2240 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2243 /* Match connected device address */
2244 if (g_strcmp0(connected_address, address) != 0) {
2245 /* Convert BD adress from string type */
2246 _bt_convert_addr_string_to_type(
2247 device_address.addr,
2249 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2250 &device_address, NULL);
2254 /* Add data to the connected list */
2255 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2256 BT_STATE_CONNECTED, address);
2263 g_variant_unref(val);
2264 g_variant_unref(child);
2268 void _bt_handle_agent_event(GVariant *msg, const char *member)
2270 int result = BLUETOOTH_ERROR_NONE;
2271 char *address = NULL;
2274 GVariant *param = NULL;
2275 ret_if(member == NULL);
2277 if (strcasecmp(member, "ObexAuthorize") == 0) {
2278 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2279 param = g_variant_new("(iss)", result, address, name);
2280 _bt_send_event(BT_OPP_SERVER_EVENT,
2281 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2285 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2286 bt_rfcomm_server_info_t *server_info;
2288 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2290 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2291 ret_if(server_info == NULL);
2292 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2293 param = g_variant_new("(isssn)", result, address, uuid, name,
2294 server_info->control_fd);
2295 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2296 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2304 static int __bt_get_object_path(GVariant *msg, char **path)
2306 g_variant_get(msg, "(o*)", path, NULL);
2308 return BLUETOOTH_ERROR_INTERNAL;
2310 return BLUETOOTH_ERROR_NONE;
2313 static void __bt_devices_list_free(void)
2315 bt_cache_info_t *cache_info;
2318 node = g_list_first(p_cache_list);
2320 while (node != NULL){
2321 cache_info = (bt_cache_info_t *)node->data;
2322 p_cache_list = g_list_remove(p_cache_list, cache_info);
2323 __bt_free_cache_info(cache_info);
2325 node = g_list_next(node);
2329 static int __bt_parse_event(GVariant *msg)
2333 char *interface_name= NULL;
2334 GVariant *inner_iter = NULL;
2336 g_variant_iter_init(&iter, msg);
2338 while ((child = g_variant_iter_next_value(&iter))) {
2339 g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter);
2340 if (g_strcmp0(interface_name,
2341 BT_DEVICE_INTERFACE) == 0) {
2342 g_variant_unref(inner_iter);
2343 g_variant_unref(child);
2344 return BT_DEVICE_EVENT;
2345 } else if (g_strcmp0(interface_name,
2346 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2347 g_variant_unref(inner_iter);
2348 g_variant_unref(child);
2349 return BT_MEDIA_TRANSFER_EVENT;
2350 } else if (g_strcmp0(interface_name,
2351 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2352 g_variant_unref(inner_iter);
2353 g_variant_unref(child);
2354 return BT_AVRCP_CONTROL_EVENT;
2356 g_variant_unref(inner_iter);
2357 g_variant_unref(child);
2363 static void __bt_manager_event_filter(GDBusConnection *connection,
2364 const gchar *sender_name,
2365 const gchar *object_path,
2366 const gchar *interface_name,
2367 const gchar *signal_name,
2368 GVariant *parameters,
2371 bt_event_type_t bt_event = 0x00;
2372 int result = BLUETOOTH_ERROR_NONE;
2374 char *obj_path = NULL;
2375 GVariant *param = NULL;
2376 if (signal_name == NULL)
2378 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2379 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2381 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2382 #ifdef USB_BLUETOOTH
2383 BT_DBG("Enable Adapter");
2384 _bt_enable_adapter();
2386 _bt_handle_adapter_added();
2390 bt_event = __bt_parse_event(value);
2391 if (bt_event == BT_DEVICE_EVENT) {
2392 bt_cache_info_t *cache_info;
2393 bt_remote_dev_info_t *dev_info;
2395 ret_if(_bt_is_discovering() == FALSE &&
2396 _bt_is_le_scanning() == FALSE);
2398 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2399 ret_if(cache_info == NULL);
2401 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2402 if (dev_info == NULL) {
2403 __bt_free_cache_info(cache_info);
2407 cache_info->dev_info = dev_info;
2409 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2410 BT_ERR("Fail to parse the properies");
2411 __bt_free_cache_info(cache_info);
2412 g_variant_unref(value);
2416 if (dev_info->addr_type != BDADDR_BREDR) {
2417 /* Whenever emit the property changed from bluez,
2418 some property doesn't reach to bt-service.
2419 So LE device is handled as AdvReport signal */
2420 __bt_free_cache_info(cache_info);
2421 g_variant_unref(value);
2425 if (dev_info->name == NULL)
2426 /* If Remote device name is NULL or still RNR is not done
2427 * then display address as name.
2429 dev_info->name = g_strdup(dev_info->address);
2431 #ifdef TIZEN_DPM_ENABLE
2432 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
2434 bluetooth_device_class_t device_class;
2435 _bt_divide_device_class(&device_class, dev_info->class);
2436 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2438 if (device_class.major_class ==
2439 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2440 __bt_free_cache_info(cache_info);
2441 g_variant_unref(value);
2447 GVariant *uuids = NULL;
2448 GVariantBuilder *builder = NULL;
2450 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2451 for (i=0; i < dev_info->uuid_count; i++) {
2452 g_variant_builder_add(builder, "s",
2453 dev_info->uuids[i]);
2455 uuids = g_variant_new("as", builder);
2456 g_variant_builder_unref(builder);
2457 GVariant *manufacturer_data = NULL;
2458 manufacturer_data = g_variant_new_from_data(
2459 G_VARIANT_TYPE_BYTESTRING,
2460 dev_info->manufacturer_data,
2461 dev_info->manufacturer_data_len,
2463 param = g_variant_new("(isunsbub@asn@ay)", result,
2469 dev_info->connected,
2472 dev_info->manufacturer_data_len,
2474 _bt_send_event(BT_ADAPTER_EVENT,
2475 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2477 p_cache_list = g_list_append(p_cache_list, cache_info);
2478 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2479 BT_DBG("Device path : %s ", obj_path);
2480 _bt_set_control_device_path(obj_path);
2483 g_variant_unref(value);
2484 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2485 #ifdef USB_BLUETOOTH
2486 BT_DBG("InterfacesRemoved");
2487 _bt_handle_adapter_removed();
2489 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
2490 bt_event = BT_MEDIA_TRANSFER_EVENT;
2491 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2492 bt_event = BT_DEVICE_EVENT;
2493 } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
2494 bt_event = BT_AVRCP_CONTROL_EVENT;
2496 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2497 _bt_handle_adapter_event(parameters, signal_name);
2498 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2499 BT_INFO("Object Path %s", obj_path);
2500 _bt_remove_control_device_path(obj_path);
2503 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2506 char *previous = NULL;
2507 char *current = NULL;
2509 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2510 BT_ERR("Fail to get the owner info");
2514 if (*current != '\0') {
2523 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2524 BT_DBG("Bluetoothd is terminated");
2525 if (_bt_adapter_get_status() == BT_ACTIVATED)
2528 _bt_handle_adapter_removed();
2529 __bt_devices_list_free();
2532 _bt_obex_server_check_allocation(&value);
2534 if (value == TRUE) {
2535 /* Check if the obex server was terminated abnormally */
2536 _bt_obex_server_check_termination(name);
2539 _bt_rfcomm_server_check_existence(&value);
2541 if (value == TRUE) {
2542 /* The obex server was terminated abnormally */
2543 _bt_rfcomm_server_check_termination(name);
2546 /* Stop advertising started by terminated process */
2547 _bt_stop_advertising_by_terminated_process(name);
2549 _bt_stop_le_scan(name);
2553 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2554 const char *path = object_path;
2556 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2557 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2560 _bt_handle_property_changed_event(parameters, object_path);
2561 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2562 _bt_handle_adapter_event(parameters, signal_name);
2563 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2564 _bt_handle_input_event(parameters, object_path);
2565 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2566 _bt_handle_network_server_event(parameters, signal_name);
2567 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2568 _bt_handle_headset_event(parameters, object_path);
2569 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2570 _bt_handle_sink_event(parameters, object_path);
2571 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2572 _bt_handle_agent_event(parameters, signal_name);
2573 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2574 _bt_handle_device_event(parameters, signal_name, object_path);
2575 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2576 _bt_handle_gatt_event(parameters, signal_name, object_path);
2582 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2585 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2586 char *interface_name = NULL;
2588 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2589 retv_if(interface_name == NULL, FALSE);
2591 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2592 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2600 static void __bt_obexd_event_filter(GDBusConnection *connection,
2601 const gchar *sender_name,
2602 const gchar *object_path,
2603 const gchar *interface_name,
2604 const gchar *signal_name,
2605 GVariant *parameters,
2608 const char *member = signal_name;
2609 char *obj_path = NULL;
2610 ret_if(member == NULL);
2612 if (strcasecmp(member, "InterfacesAdded") == 0) {
2613 if (__bt_get_object_path(parameters, &obj_path)) {
2614 BT_ERR("Fail to get the path");
2617 BT_INFO("object_path = [%s]", object_path);
2619 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2620 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2621 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2626 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2627 BT_DBG("Obex_Server_Session_Transfer connected");
2628 _bt_obex_transfer_connected();
2631 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2632 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2633 if (__bt_get_object_path(parameters, &obj_path)) {
2634 BT_ERR("Fail to get the path");
2637 BT_INFO("object_path = [%s]", object_path);
2639 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2640 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2641 BT_DBG("Call PBAP Disconnected");
2642 _bt_obex_pbap_client_disconnect(obj_path);
2645 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2646 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2651 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2652 BT_DBG("Obex_Server_Session_Transfer disconnected");
2653 _bt_obex_transfer_disconnected();
2656 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2657 const char *path = object_path;
2659 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2660 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2661 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2662 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2663 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2667 _bt_handle_property_changed_event(parameters, path);
2673 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2677 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2678 char *interface_name = NULL;
2680 g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL);
2682 retv_if(interface_name == NULL, FALSE);
2684 if (strcasecmp(interface_name,
2685 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2696 static void __bt_opc_event_filter(GDBusConnection *connection,
2697 const gchar *sender_name,
2698 const gchar *object_path,
2699 const gchar *interface_name,
2700 const gchar *signal_name,
2701 GVariant *parameters,
2704 const char *member = signal_name;
2705 char *obj_path = NULL;
2706 if (strcasecmp(member, "InterfacesAdded") == 0) {
2707 BT_DBG("InterfacesAdded");
2708 }else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2710 if (__bt_get_object_path(parameters, &obj_path)) {
2711 BT_ERR("Fail to get the path");
2715 BT_DBG("object_path =%s",obj_path);
2717 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2718 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
2719 || strstr(obj_path, "transfer") == NULL) {
2723 else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2724 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2725 BT_DBG("Going to call opc disconnected");
2726 _bt_opc_disconnected(obj_path);
2729 _bt_sending_files();
2731 }else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE){
2732 char *path = (char *)object_path;
2733 BT_INFO("object_path %s", path);
2734 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2735 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2736 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
2740 _bt_opc_property_changed_event(parameters, path);
2746 int _bt_opp_client_event_init(void)
2748 GError *error = NULL;
2750 if (opc_obexd_conn == NULL) {
2751 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
2753 if (!opc_obexd_conn) {
2755 BT_ERR("Unable to connect to dbus: %s", error->message);
2756 g_clear_error(&error);
2758 return BLUETOOTH_ERROR_INTERNAL;
2762 if (_bt_register_service_event(opc_obexd_conn,
2763 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
2764 g_object_unref(opc_obexd_conn);
2765 opc_obexd_conn = NULL;
2766 return BLUETOOTH_ERROR_INTERNAL;
2769 return BLUETOOTH_ERROR_NONE;
2772 void _bt_opp_client_event_deinit(void)
2774 if (opc_obexd_conn) {
2775 _bt_unregister_service_event(opc_obexd_conn,
2776 BT_OPP_CLIENT_EVENT);
2777 g_object_unref(opc_obexd_conn);
2778 opc_obexd_conn = NULL;
2782 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
2788 static int subs_interface_added_id = -1;
2789 static int subs_interface_removed_id = -1;
2790 static int subs_name_owner_id = -1;
2791 static int subs_property_id = -1;
2792 static int subs_adapter_id = -1;
2793 static int subs_gatt_id = -1;
2796 if (subs_interface_added_id == -1) {
2797 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
2798 NULL, BT_MANAGER_INTERFACE,
2799 BT_INTERFACES_ADDED, NULL, NULL, 0,
2800 __bt_manager_event_filter,
2803 if (subs_interface_removed_id == -1) {
2804 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
2805 NULL, BT_MANAGER_INTERFACE,
2806 BT_INTERFACES_REMOVED, NULL, NULL, 0,
2807 __bt_manager_event_filter,
2810 if (subs_name_owner_id == -1) {
2811 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
2812 NULL, BT_FREEDESKTOP_INTERFACE,
2813 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
2814 __bt_manager_event_filter,
2817 if (subs_property_id == -1) {
2818 subs_property_id = g_dbus_connection_signal_subscribe(conn,
2819 NULL, BT_PROPERTIES_INTERFACE,
2820 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
2821 __bt_manager_event_filter,
2824 if (subs_adapter_id == -1) {
2825 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
2826 NULL, BT_ADAPTER_INTERFACE,
2827 NULL, NULL, NULL, 0,
2828 __bt_manager_event_filter,
2831 if (subs_gatt_id == -1) {
2832 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
2833 NULL, BT_GATT_CHAR_INTERFACE,
2834 NULL, NULL, NULL, 0,
2835 __bt_manager_event_filter,
2839 if (subs_interface_added_id != -1) {
2840 g_dbus_connection_signal_unsubscribe(conn,
2841 subs_interface_added_id);
2842 subs_interface_added_id = -1;
2844 if (subs_interface_removed_id != -1) {
2845 g_dbus_connection_signal_unsubscribe(conn,
2846 subs_interface_removed_id);
2847 subs_interface_removed_id = -1;
2849 if (subs_name_owner_id != -1) {
2850 g_dbus_connection_signal_unsubscribe(conn,
2851 subs_name_owner_id);
2852 subs_name_owner_id = -1;
2854 if (subs_property_id != -1) {
2855 g_dbus_connection_signal_unsubscribe(conn,
2857 subs_property_id = -1;
2859 if (subs_adapter_id != -1) {
2860 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
2861 subs_adapter_id = -1;
2863 if (subs_gatt_id != -1) {
2864 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
2871 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
2877 static int subs_device_id = -1;
2880 if (subs_device_id == -1) {
2881 subs_device_id = g_dbus_connection_signal_subscribe(conn,
2882 NULL, BT_DEVICE_INTERFACE,
2883 NULL, NULL, NULL, 0,
2884 __bt_manager_event_filter,
2888 if (subs_device_id != -1) {
2889 g_dbus_connection_signal_unsubscribe(conn,
2891 subs_device_id = -1;
2897 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
2903 static int subs_input_id = -1;
2906 if (subs_input_id == -1) {
2907 subs_input_id = g_dbus_connection_signal_subscribe(conn,
2908 NULL, BT_INPUT_INTERFACE,
2909 NULL, NULL, NULL, 0,
2910 __bt_manager_event_filter,
2914 if (subs_input_id != -1) {
2915 g_dbus_connection_signal_unsubscribe(conn,
2923 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
2929 static int subs_serv_id = -1;
2930 static int subs_client_id = -1;
2933 if (subs_serv_id == -1) {
2934 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
2935 NULL, BT_NETWORK_SERVER_INTERFACE,
2936 NULL, NULL, NULL, 0,
2937 __bt_manager_event_filter,
2940 if (subs_client_id == -1) {
2941 subs_client_id = g_dbus_connection_signal_subscribe(conn,
2942 NULL, BT_NETWORK_CLIENT_INTERFACE,
2943 NULL, NULL, NULL, 0,
2944 __bt_manager_event_filter,
2948 if (subs_serv_id != -1) {
2949 g_dbus_connection_signal_unsubscribe(conn,
2953 if (subs_client_id != -1) {
2954 g_dbus_connection_signal_unsubscribe(conn,
2956 subs_client_id = -1;
2962 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
2968 static int subs_headset_id = -1;
2969 static int subs_sink_id = -1;
2972 if (subs_headset_id == -1) {
2973 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
2974 NULL, BT_HEADSET_INTERFACE,
2975 NULL, NULL, NULL, 0,
2976 __bt_manager_event_filter,
2979 if (subs_sink_id == -1) {
2980 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
2981 NULL, BT_SINK_INTERFACE,
2982 NULL, NULL, NULL, 0,
2983 __bt_manager_event_filter,
2987 if (subs_headset_id != -1) {
2988 g_dbus_connection_signal_unsubscribe(conn,
2990 subs_headset_id = -1;
2992 if (subs_sink_id != -1) {
2993 g_dbus_connection_signal_unsubscribe(conn,
3001 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3007 static int subs_opp_server_interface_added_id = -1;
3008 static int subs_opp_server_interface_removed_id = -1;
3009 static int subs_opp_server_property_id = -1;
3013 if (subs_opp_server_interface_added_id == -1) {
3014 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3015 NULL, BT_MANAGER_INTERFACE,
3016 BT_INTERFACES_ADDED, NULL, NULL, 0,
3017 __bt_obexd_event_filter,
3020 if (subs_opp_server_interface_removed_id == -1) {
3021 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3022 NULL, BT_MANAGER_INTERFACE,
3023 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3024 __bt_obexd_event_filter,
3027 if (subs_opp_server_property_id == -1) {
3028 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3029 NULL, BT_PROPERTIES_INTERFACE,
3030 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3031 __bt_obexd_event_filter,
3035 if (subs_opp_server_interface_added_id != -1) {
3036 g_dbus_connection_signal_unsubscribe(conn,
3037 subs_opp_server_interface_added_id);
3038 subs_opp_server_interface_added_id = -1;
3040 if (subs_opp_server_interface_removed_id != -1) {
3041 g_dbus_connection_signal_unsubscribe(conn,
3042 subs_opp_server_interface_removed_id);
3043 subs_opp_server_interface_removed_id = -1;
3045 if (subs_opp_server_property_id != -1) {
3046 g_dbus_connection_signal_unsubscribe(conn,
3047 subs_opp_server_property_id);
3048 subs_opp_server_property_id = -1;
3054 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3060 static int subs_opp_client_interface_added_id = -1;
3061 static int subs_opp_client_interface_removed_id = -1;
3062 static int subs_opp_client_property_id = -1;
3066 if (subs_opp_client_interface_added_id == -1) {
3067 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3068 NULL, BT_MANAGER_INTERFACE,
3069 BT_INTERFACES_ADDED, NULL, NULL, 0,
3070 __bt_opc_event_filter,
3073 if (subs_opp_client_interface_removed_id == -1) {
3074 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3075 NULL, BT_MANAGER_INTERFACE,
3076 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3077 __bt_opc_event_filter,
3080 if (subs_opp_client_property_id == -1) {
3081 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3082 NULL, BT_PROPERTIES_INTERFACE,
3083 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3084 __bt_opc_event_filter,
3088 if (subs_opp_client_interface_added_id != -1) {
3089 g_dbus_connection_signal_unsubscribe(conn,
3090 subs_opp_client_interface_added_id);
3091 subs_opp_client_interface_added_id = -1;
3093 if (subs_opp_client_interface_removed_id != -1) {
3094 g_dbus_connection_signal_unsubscribe(conn,
3095 subs_opp_client_interface_removed_id);
3096 subs_opp_client_interface_removed_id = -1;
3098 if (subs_opp_client_property_id != -1) {
3099 g_dbus_connection_signal_unsubscribe(conn,
3100 subs_opp_client_property_id);
3101 subs_opp_client_property_id = -1;
3107 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3113 static int subs_a2dp_source_id = -1;
3114 static int subs_a2dp_sink_id = -1;
3117 if (subs_a2dp_source_id == -1) {
3118 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3119 NULL, BT_A2DP_SOURCE_INTERFACE,
3120 NULL, NULL, NULL, 0,
3121 __bt_opc_event_filter,
3124 if (subs_a2dp_sink_id == -1) {
3125 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3126 NULL, BT_SINK_INTERFACE,
3127 NULL, NULL, NULL, 0,
3128 __bt_opc_event_filter,
3132 if (subs_a2dp_source_id != -1) {
3133 g_dbus_connection_signal_unsubscribe(conn,
3134 subs_a2dp_source_id);
3135 subs_a2dp_source_id = -1;
3137 if (subs_a2dp_sink_id != -1) {
3138 g_dbus_connection_signal_unsubscribe(conn,
3140 subs_a2dp_sink_id = -1;
3146 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3150 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3152 switch (event_type) {
3153 case BT_MANAGER_EVENT:
3154 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3156 case BT_DEVICE_EVENT:
3157 _bt_register_device_subscribe_signal(g_conn, TRUE);
3160 _bt_register_input_subscribe_signal(g_conn, TRUE);
3162 case BT_NETWORK_EVENT:
3163 _bt_register_network_subscribe_signal(g_conn, TRUE);
3165 case BT_HEADSET_EVENT:
3166 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3169 case BT_OPP_SERVER_EVENT:
3170 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3171 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3173 case BT_OPP_CLIENT_EVENT:
3174 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3175 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3177 case BT_A2DP_SOURCE_EVENT:
3178 BT_INFO("A2dp Source event");
3179 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3182 BT_ERR("Unknown event");
3183 return BLUETOOTH_ERROR_INTERNAL;
3186 return BLUETOOTH_ERROR_NONE;
3189 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3193 ret_if(g_conn == NULL);
3195 switch (event_type) {
3196 case BT_MANAGER_EVENT:
3197 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3198 _bt_register_device_subscribe_signal(g_conn, FALSE);
3199 _bt_register_input_subscribe_signal(g_conn, FALSE);
3200 _bt_register_network_subscribe_signal(g_conn, FALSE);
3201 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3203 case BT_OPP_SERVER_EVENT:
3204 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3206 case BT_OPP_CLIENT_EVENT:
3207 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3210 BT_ERR("Unknown event");
3217 static int __bt_init_manager_receiver(void)
3221 GError *error = NULL;
3223 if (manager_conn == NULL) {
3224 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3225 if (error != NULL) {
3226 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3227 g_clear_error(&error);
3229 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3232 if (_bt_register_service_event(manager_conn,
3233 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3235 if (_bt_register_service_event(manager_conn,
3236 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3239 if (_bt_register_service_event(manager_conn,
3240 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3243 if (_bt_register_service_event(manager_conn,
3244 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3247 if (_bt_register_service_event(manager_conn,
3248 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3250 return BLUETOOTH_ERROR_NONE;
3253 g_object_unref(manager_conn);
3254 manager_conn = NULL;
3259 return BLUETOOTH_ERROR_INTERNAL;
3262 static int __bt_init_obexd_receiver(void)
3265 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3266 GError *error = NULL;
3268 if (obexd_conn == NULL) {
3269 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3270 if (error != NULL) {
3271 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3272 g_clear_error(&error);
3274 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3277 if (_bt_register_service_event(obexd_conn,
3278 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3279 BT_ERR("Error while registering service event");
3280 g_object_unref(obexd_conn);
3282 return BLUETOOTH_ERROR_INTERNAL;
3287 return BLUETOOTH_ERROR_NONE;
3290 /* To receive the event from bluez */
3291 int _bt_init_service_event_receiver(void)
3297 result = __bt_init_manager_receiver();
3298 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3300 result = __bt_init_obexd_receiver();
3301 if (result != BLUETOOTH_ERROR_NONE)
3302 BT_ERR("Fail to init obexd receiver");
3306 return BLUETOOTH_ERROR_NONE;
3309 void _bt_deinit_service_event_receiver(void)
3313 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3315 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3318 g_object_unref(manager_conn);
3319 manager_conn = NULL;
3323 g_object_unref(obexd_conn);
3328 g_source_remove(event_id);