/*
- * bluetooth-frwk
- *
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
*
*/
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus.h>
#include <glib.h>
#include <string.h>
#include <dlog.h>
#include "bt-service-event.h"
#include "bt-service-main.h"
#include "bt-service-adapter.h"
+#include "bt-service-adapter-le.h"
#include "bt-service-device.h"
+#include "bt-service-avrcp.h"
#include "bt-service-obex-server.h"
#include "bt-service-rfcomm-server.h"
-#include "bt-service-opp-client.h"
#include "bt-service-audio.h"
+#include "bt-service-agent.h"
+#include "bt-service-pbap.h"
+#include "bt-service-headset-connection.h"
+#include "bt-service-avrcp-controller.h"
+#include "bt-service-hid.h"
+#include "bt-service-proximity.h"
+
+#include "bt-service-opp-client.h"
-static DBusGConnection *manager_conn = NULL;
-static DBusGConnection *obexd_conn = NULL;
-static DBusGConnection *opc_obexd_conn = NULL;
-static GList *g_list = NULL;
+#ifdef TIZEN_FEATURE_BT_DPM
+#include "bt-service-dpm.h"
+#endif
+
+#define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
+static GDBusConnection *manager_conn;
+static GDBusConnection *obexd_conn;
+static GDBusConnection *opc_obexd_conn;
+
+static GList *p_cache_list = NULL;
static guint event_id;
+static guint le_scan_event_id = 0;
+static guint session_reinit_timer;
+guint nap_connected_device_count = 0;
+static guint hid_connected_device_count = 0;
+static GList *p_adv_ind_list = NULL;
-static bt_remote_dev_info_t *__bt_parse_device_properties(DBusMessageIter *item_iter)
-{
- DBusMessageIter value_iter;
- char *value;
+typedef struct {
bt_remote_dev_info_t *dev_info;
+} bt_cache_info_t;
- dbus_message_iter_recurse(item_iter, &value_iter);
+/**
+ * obexd connection type
+ */
+typedef enum {
+ OBEX_OPP = (1 << 1),
+ OBEX_FTP = (1 << 2),
+ OBEX_BIP = (1 << 3),
+ OBEX_PBAP = (1 << 4),
+ OBEX_IRMC = (1 << 5),
+ OBEX_PCSUITE = (1 << 6),
+ OBEX_SYNCEVOLUTION = (1 << 7),
+ OBEX_MAS = (1 << 8),
+} bluetooth_obex_connection_type_t;
+
+void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
+void _bt_opc_property_changed_event(GVariant *msg, char *path);
+int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
+void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
+void _bt_opp_client_event_deinit(void);
+void _bt_handle_network_client_event(GVariant *msg_iter,
+ const char *path);
+void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
+ const char *path);
+
+static void __bt_free_bt_le_adv_info_t(gpointer data)
+{
+ bt_le_adv_info_t *adv_info = data;
- if (dbus_message_iter_get_arg_type(&value_iter) != DBUS_TYPE_DICT_ENTRY) {
- BT_DBG("No entry");
- return NULL;
- }
+ if (adv_info->timer_id)
+ g_source_remove(adv_info->timer_id);
+ adv_info->timer_id = 0;
- dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
+ g_free(adv_info->addr);
+ g_free(adv_info->data);
+ g_free(adv_info);
+}
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- char *key;
- DBusMessageIter dict_entry;
- DBusMessageIter iter_dict_val;
+static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
+{
+ retv_if(!addr, NULL);
+ bt_le_adv_info_t *adv_info = NULL;
+ GList *current = g_list_first((GList *)p_adv_ind_list);
+ while (current && current->data) {
+ adv_info = (bt_le_adv_info_t *)current->data;
+ if (adv_info && !g_strcmp0(adv_info->addr, addr))
+ return adv_info;
+ current = g_list_next(current);
+ }
+ return NULL;
+}
- dbus_message_iter_recurse(&value_iter, &dict_entry);
+static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
+{
+ retv_if(!adv_info, -1);
+ if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
+ __bt_free_bt_le_adv_info_t(adv_info);
+ return -1;
+ }
+ p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
- dbus_message_iter_get_basic(&dict_entry, &key);
+ return 0;
+}
- if (key == NULL) {
- dbus_message_iter_next(&value_iter);
- continue;
+static void __bt_del_adv_ind_info(char *addr)
+{
+ ret_if(!addr);
+ ret_if(!p_adv_ind_list);
+ bt_le_adv_info_t *adv_info = NULL;
+ GList *current = g_list_first((GList *)p_adv_ind_list);
+ while (current && current->data) {
+ adv_info = (bt_le_adv_info_t *)current->data;
+ if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
+ p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
+ __bt_free_bt_le_adv_info_t(adv_info);
+ return;
}
+ current = g_list_next(current);
+ }
+}
- if (!dbus_message_iter_next(&dict_entry)) {
- dbus_message_iter_next(&value_iter);
- continue;
- }
- dbus_message_iter_recurse(&dict_entry, &iter_dict_val);
+static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
+{
+ bt_remote_le_dev_info_t le_dev_info;
+ bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
+
+ memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
- if (strcasecmp(key, "Address") == 0) {
- const char *address = NULL;
- dbus_message_iter_get_basic(&iter_dict_val, &address);
- dev_info->address = g_strdup(address);
+ le_dev_info.address = adv_info->addr;
+ le_dev_info.addr_type = adv_info->addr_type;
+ le_dev_info.rssi = adv_info->rssi;
+ le_dev_info.adv_data = adv_info->data;
+ le_dev_info.adv_data_len = 0;
+ adv_info->timer_id = 0;
+
+ _bt_send_scan_result_event(&le_dev_info, adv_info);
+ __bt_del_adv_ind_info(adv_info->addr);
+
+ return FALSE;
+}
+
+static void __bt_free_cache_info(bt_cache_info_t *cache_info)
+{
+ ret_if(cache_info == NULL);
+ _bt_free_device_info(cache_info->dev_info);
+ g_free(cache_info);
+}
+
+static gboolean __bt_parse_device_properties(GVariant *item,
+ bt_remote_dev_info_t *dev_info)
+{
+ GVariantIter iter;
+ gchar *key;
+ GVariant *val;
+ gsize len = 0;
+ if (item == NULL)
+ return FALSE;
+
+ g_variant_iter_init(&iter, item);
+ while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
+ if (strcasecmp(key, "Address") == 0) {
+ dev_info->address = g_variant_dup_string(val, &len);
} else if (strcasecmp(key, "Class") == 0) {
- dbus_message_iter_get_basic(&iter_dict_val, &dev_info->class);
- } else if (strcasecmp(key, "Name") == 0) {
- dbus_message_iter_get_basic(&iter_dict_val, &value);
+ dev_info->class = g_variant_get_uint32(val);
+ } else if (strcasecmp(key, "name") == 0) {
if (dev_info->name == NULL)
- dev_info->name = g_strdup(value);
+ dev_info->name = g_variant_dup_string(val, &len);
} else if (strcasecmp(key, "Connected") == 0) {
- dbus_message_iter_get_basic(&iter_dict_val,
- &dev_info->connected);
- } else if (strcasecmp(key, "Paired") == 0) {
- dbus_message_iter_get_basic(&iter_dict_val,
- &dev_info->paired);
+ dev_info->connected = g_variant_get_byte(val);
+ } else if (strcasecmp(key, "paired") == 0) {
+ dev_info->paired = g_variant_get_boolean(val);
} else if (strcasecmp(key, "Trusted") == 0) {
- dbus_message_iter_get_basic(&iter_dict_val,
- &dev_info->trust);
+ dev_info->trust = g_variant_get_boolean(val);
} else if (strcasecmp(key, "RSSI") == 0) {
- dbus_message_iter_get_basic(&iter_dict_val,
- &dev_info->rssi);
+ dev_info->rssi = g_variant_get_int16(val);
+ } else if (strcasecmp(key, "LastAddrType") == 0) {
+ dev_info->addr_type = g_variant_get_byte(val);
} else if (strcasecmp(key, "UUIDs") == 0) {
- DBusMessageIter uuid_iter;
- DBusMessageIter tmp_iter;
+ char **uuid_value;
+ gsize size = 0;
int i = 0;
+ size = g_variant_get_size(val);
- dbus_message_iter_recurse(&iter_dict_val, &uuid_iter);
-
- tmp_iter = uuid_iter;
+ if (size > 0) {
+ uuid_value = (char **)g_variant_get_strv(val, &size);
+ if (dev_info->uuids == NULL)
+ dev_info->uuids = g_malloc0(sizeof(char *) * size);
- /* Store the uuid count */
- while (dbus_message_iter_get_arg_type(&tmp_iter) != DBUS_TYPE_INVALID) {
- dbus_message_iter_get_basic(&tmp_iter,
- &value);
-
- dev_info->uuid_count++;
- if (!dbus_message_iter_next(&tmp_iter))
- break;
+ for (i = 0; uuid_value[i] != NULL; i++) {
+ dev_info->uuid_count++;
+ dev_info->uuids[i] = g_strdup(uuid_value[i]);
+ }
+ g_free(uuid_value);
+ }
+ } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
+ g_variant_get(val, "q", &dev_info->manufacturer_data_len);
+ if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
+ BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
+ dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
}
- /* Store the uuids */
- if (dev_info->uuid_count > 0) {
- dev_info->uuids = g_new0(char *,
- dev_info->uuid_count + 1);
- } else {
- dbus_message_iter_next(&value_iter);
+ if (dev_info->manufacturer_data_len == 0)
+ dev_info->manufacturer_data = g_strdup("");
+ } else if (strcasecmp(key, "ManufacturerData") == 0) {
+ int i = 0;
+ int len = 0;
+ GVariantIter *value_iter;
+ guint8 m_value;
+
+ len = g_variant_get_size(val);
+ if (len <= 0)
continue;
- }
- while (dbus_message_iter_get_arg_type(&uuid_iter) != DBUS_TYPE_INVALID) {
- dbus_message_iter_get_basic(&uuid_iter,
- &value);
- dev_info->uuids[i] = g_strdup(value);
- i++;
- if (!dbus_message_iter_next(&uuid_iter)) {
- break;
- }
- }
+ dev_info->manufacturer_data = g_malloc0(len);
+ g_variant_get(val, "ay", &value_iter);
+ while (g_variant_iter_loop(value_iter, "y", &m_value))
+ dev_info->manufacturer_data[i++] = m_value;
+ g_variant_iter_free(value_iter);
}
-
- dbus_message_iter_next(&value_iter);
}
- return dev_info;
+ BT_DBG("-");
+ return TRUE;
}
-void __bt_parse_media_properties(DBusMessageIter *item_iter)
+static gboolean __bt_parse_interface(GVariant *msg,
+ bt_remote_dev_info_t *dev_info)
{
- DBusMessageIter value_iter;
- char *address = NULL;
- char *uuid = NULL;
- int result = BLUETOOTH_ERROR_NONE;
-
- dbus_message_iter_recurse(item_iter, &value_iter);
-
- if (dbus_message_iter_get_arg_type(&value_iter) !=
- DBUS_TYPE_DICT_ENTRY) {
- BT_DBG("No entry");
- return;
- }
-
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- char *key;
- DBusMessageIter dict_entry;
- DBusMessageIter iter_dict_val;
-
- dbus_message_iter_recurse(&value_iter, &dict_entry);
- dbus_message_iter_get_basic(&dict_entry, &key);
-
- if (key == NULL) {
- dbus_message_iter_next(&value_iter);
- continue;
- }
-
- if (!dbus_message_iter_next(&dict_entry)) {
- dbus_message_iter_next(&value_iter);
- continue;
- }
-
- dbus_message_iter_recurse(&dict_entry, &iter_dict_val);
-
- BT_DBG("key: %s", key);
-
- if (strcasecmp(key, "Device") == 0) {
- char *object_path = NULL;
-
- dbus_message_iter_get_basic(&iter_dict_val, &object_path);
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_device_path_to_address(object_path, address);
-
- }else if (strcasecmp(key, "UUID") == 0) {
- dbus_message_iter_get_basic(&iter_dict_val, &uuid);
- }
-
- dbus_message_iter_next(&value_iter);
- }
-
- if (address != NULL && uuid != NULL){
- int event = BLUETOOTH_EVENT_AV_CONNECTED;
- char connected_address[BT_ADDRESS_STRING_SIZE + 1];
- bluetooth_device_address_t device_address;
- gboolean connected;
-
- _bt_send_event(BT_HEADSET_EVENT, event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
-
- connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
- connected_address);
- if (connected) {
- if (g_strcmp0(connected_address, address) != 0) {
- _bt_convert_addr_string_to_type(
- device_address.addr,
- connected_address);
- _bt_audio_disconnect(0, BT_AUDIO_A2DP,
- &device_address, NULL);
+ char *path = NULL;
+ GVariant *optional_param = NULL;
+ GVariantIter iter;
+ GVariant *child;
+ char *interface_name = NULL;
+ GVariant *inner_iter = NULL;
+ g_variant_get(msg, "(&o@a{sa{sv}})",
+ &path, &optional_param);
+ g_variant_iter_init(&iter, optional_param);
+
+ retv_if(optional_param == NULL, FALSE);
+
+ while ((child = g_variant_iter_next_value(&iter))) {
+ g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
+ if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
+ BT_DBG("Found a device: %s", path);
+ if (__bt_parse_device_properties(inner_iter,
+ dev_info) == FALSE) {
+ g_variant_unref(inner_iter);
+ g_variant_unref(child);
+ g_variant_unref(optional_param);
+ BT_ERR("Fail to parse the properies");
+ return FALSE;
+ } else {
+ g_variant_unref(inner_iter);
+ g_variant_unref(child);
+ g_variant_unref(optional_param);
+ return TRUE;
}
}
+ g_variant_unref(inner_iter);
+ g_variant_unref(child);
+ }
- _bt_add_headset_to_list(BT_AUDIO_A2DP,
- BT_STATE_CONNECTED, address);
+ g_variant_unref(optional_param);
- g_free(address);
- }
+ return FALSE;
}
-static void __bt_parse_audio_properties(DBusMessage *msg)
+static int __bt_get_owner_info(GVariant *msg, char **name,
+ char **previous, char **current)
{
- DBusMessageIter msg_iter;
- DBusMessageIter value_iter;
-
- ret_if(dbus_message_iter_init(msg, &msg_iter) == FALSE);
-
- /* object array (oa) */
- ret_if(dbus_message_iter_next(&msg_iter) == FALSE);
- ret_if(dbus_message_iter_get_arg_type(&msg_iter) !=
- DBUS_TYPE_ARRAY);
-
- dbus_message_iter_recurse(&msg_iter, &value_iter);
-
- /* string array (sa) */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- char *interface_name = NULL;
- DBusMessageIter interface_iter;
-
- dbus_message_iter_recurse(&value_iter, &interface_iter);
+ g_variant_get(msg, "(sss)", name, previous, current);
+ return BLUETOOTH_ERROR_NONE;
+}
- ret_if(dbus_message_iter_get_arg_type(&interface_iter) !=
- DBUS_TYPE_STRING);
+static int __bt_get_agent_signal_info(GVariant *msg, char **address,
+ char **name, char **uuid)
+{
+ g_variant_get(msg, "(sss)", address, name, uuid);
+ return BLUETOOTH_ERROR_NONE;
+}
- dbus_message_iter_get_basic(&interface_iter, &interface_name);
+void __bt_set_device_values(gboolean connected, int state)
+{
+ int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
- ret_if(dbus_message_iter_next(&interface_iter) == FALSE);
+ if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
+ BT_ERR("vconf_get_int failed");
- ret_if(dbus_message_iter_get_arg_type(&interface_iter) !=
- DBUS_TYPE_ARRAY);
+ if (connected == TRUE)
+ bt_device_state |= state;
+ else if (bt_device_state & state)
+ bt_device_state ^= state;
- BT_DBG("interface: %s", interface_name);
+ if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
+ BT_ERR("vconf_set_int failed");
+}
- if (g_strcmp0(interface_name,
- "org.bluez.MediaTransport1") == 0) {
- __bt_parse_media_properties(&interface_iter);
- return;
- }
- dbus_message_iter_next(&value_iter);
+gboolean _bt_discovery_finished_cb(gpointer user_data)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ event_id = 0;
+ GVariant *param = NULL;
+ if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
+ if (_bt_get_cancel_by_user() == TRUE)
+ result = BLUETOOTH_ERROR_CANCEL_BY_USER;
+
+ _bt_set_cancel_by_user(FALSE);
+ _bt_set_discovery_status(FALSE);
+ param = g_variant_new("(i)", result);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_DISCOVERY_FINISHED,
+ param);
}
- return;
+ return FALSE;
}
-static int __bt_parse_event(DBusMessage *msg)
+static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
{
- DBusMessageIter msg_iter;
- DBusMessageIter value_iter;
-
- retv_if(dbus_message_iter_init(msg, &msg_iter) == FALSE, 0);
-
- /* object array (oa) */
- retv_if(dbus_message_iter_next(&msg_iter) == FALSE, 0);
- retv_if(dbus_message_iter_get_arg_type(&msg_iter) !=
- DBUS_TYPE_ARRAY, 0);
-
- dbus_message_iter_recurse(&msg_iter, &value_iter);
-
- /* string array (sa) */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- char *interface_name = NULL;
- DBusMessageIter interface_iter;
-
- dbus_message_iter_recurse(&value_iter, &interface_iter);
-
- retv_if(dbus_message_iter_get_arg_type(&interface_iter) !=
- DBUS_TYPE_STRING, 0);
-
- dbus_message_iter_get_basic(&interface_iter,
- &interface_name);
-
- retv_if(dbus_message_iter_next(&interface_iter) == FALSE,
- 0);
-
- retv_if(dbus_message_iter_get_arg_type(&interface_iter) !=
- DBUS_TYPE_ARRAY, 0);
+ int result = BLUETOOTH_ERROR_NONE;
+ le_scan_event_id = 0;
+ GVariant *param = NULL;
+ if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
+ if (_bt_get_cancel_by_user() == TRUE)
+ result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- BT_DBG("interface: %s", interface_name);
+ g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
+ p_adv_ind_list = NULL;
- if (g_strcmp0(interface_name,
- "org.bluez.Device1") == 0) {
- return BT_DEVICE_EVENT;
- }else if (g_strcmp0(interface_name,
- "org.bluez.MediaTransport1") == 0) {
- return BT_MEDIA_TRANSFER_EVENT;
- }
- dbus_message_iter_next(&value_iter);
+ _bt_set_cancel_by_user(FALSE);
+ _bt_disable_all_scanner_status();
+ _bt_set_le_scan_status(FALSE);
+ param = g_variant_new("(i)", result);
+ _bt_send_event(BT_LE_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
+ param);
}
- return 0;
+ return FALSE;
}
-static int __bt_parse_remove_event(DBusMessage *msg)
+void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
{
- DBusMessageIter msg_iter;
- DBusMessageIter value_iter;
-
- retv_if(dbus_message_iter_init(msg, &msg_iter) ==
- FALSE, 0);
+ BT_DBG("+");
- retv_if(dbus_message_iter_next(&msg_iter) == FALSE,
- 0);
- retv_if(dbus_message_iter_get_arg_type(&msg_iter) !=
- DBUS_TYPE_ARRAY, 0);
+ ret_if(address == NULL);
- dbus_message_iter_recurse(&msg_iter, &value_iter);
+ GList * node;
+ bt_cache_info_t *cache_info;
+ bt_remote_dev_info_t *dev_info;
- while (dbus_message_iter_get_arg_type(&value_iter)
- != DBUS_TYPE_INVALID) {
- char *key;
+ node = g_list_first(p_cache_list);
- dbus_message_iter_get_basic(&value_iter, &key);
+ while (node != NULL) {
+ cache_info = (bt_cache_info_t *)node->data;
- if (key == NULL) {
- dbus_message_iter_next(&value_iter);
+ if (cache_info == NULL) {
+ node = g_list_next(node);
continue;
}
- BT_DBG("key = %s", key);
-
- if (g_strcmp0(key, "org.bluez.MediaTransport1") == 0) {
- return BT_MEDIA_TRANSFER_EVENT;
- }else if (g_strcmp0(key, "org.bluez.Device1") == 0) {
- return BT_DEVICE_EVENT;
+ dev_info = cache_info->dev_info;
+ if (strcasecmp(dev_info->address,
+ address) == 0) {
+ BT_DBG("Device Found");
+ if (paired_status == TRUE)
+ cache_info->dev_info->paired = TRUE;
+ else
+ cache_info->dev_info->paired = FALSE;
+ break;
}
- dbus_message_iter_next(&value_iter);
+ node = g_list_next(node);
}
-
- return 0;
+ BT_DBG("-");
}
-gboolean _bt_parse_audio_remove_properties(DBusMessage *msg)
+static void __bt_device_remote_connected_properties(
+ bt_remote_dev_info_t *remote_dev_info,
+ char *address, gboolean connected)
{
- DBusMessageIter msg_iter;
- DBusMessageIter value_iter;
- char *object_path = NULL;
- char *address = NULL;
int result = BLUETOOTH_ERROR_NONE;
- bt_headset_wait_t *wait_list;
-
- retv_if(dbus_message_iter_init(msg, &msg_iter) == FALSE, FALSE);
-
- dbus_message_iter_get_basic(&msg_iter, &object_path);
- retv_if(object_path == NULL, FALSE);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_device_path_to_address(object_path, address);
-
- retv_if(dbus_message_iter_next(&msg_iter) == FALSE, FALSE);
- retv_if(dbus_message_iter_get_arg_type(&msg_iter) !=
- DBUS_TYPE_ARRAY, FALSE);
-
- dbus_message_iter_recurse(&msg_iter, &value_iter);
-
- while (dbus_message_iter_get_arg_type(&value_iter)
- != DBUS_TYPE_INVALID) {
- char *key;
-
- dbus_message_iter_get_basic(&value_iter, &key);
-
- if (key == NULL) {
- dbus_message_iter_next(&value_iter);
- continue;
- }
-
- BT_DBG("key = %s", key);
-
- if (g_strcmp0(key, "org.bluez.MediaTransport1") == 0) {
- int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
-
- _bt_send_event(BT_HEADSET_EVENT, event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
+ int i;
+ GVariant *param = NULL;
+ BT_DBG("+");
- /* Remove data from the connected list */
- _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
- wait_list = _bt_get_audio_wait_data();
+ if (remote_dev_info->uuid_count > 0) {
+ for (i = 0; i < remote_dev_info->uuid_count; i++) {
+ char *uuid = remote_dev_info->uuids[i];
+ if (strcasecmp(uuid, HID_UUID) == 0) {
+ int event = BLUETOOTH_EVENT_NONE;
- if (wait_list == NULL) {
- g_free(address);
- return TRUE;
+ event = (connected == TRUE) ?
+ BLUETOOTH_HID_CONNECTED :
+ BLUETOOTH_HID_DISCONNECTED;
+ param = g_variant_new("(is)", result,
+ address);
+ _bt_send_event(BT_HID_EVENT, event,
+ param);
+ break;
}
+ }
+ }
- if (((wait_list->type == BT_AUDIO_ALL) &&
- (wait_list->ag_flag == TRUE)) ||
- (wait_list->type == BT_AUDIO_A2DP) ||
- (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
- bluetooth_device_address_t device_address;
- _bt_convert_addr_string_to_type(
- device_address.addr,
- wait_list->address);
+ BT_DBG("-");
+}
- _bt_audio_connect(wait_list->req_id,
- wait_list->type,
- &device_address,
- wait_list->out_param1);
- }
+gboolean __bt_handle_is_flight_mode_enabled(void)
+{
+#ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
+ int is_flight_mode = 0;
+ int ret = -1;
- g_free(address);
- return TRUE;
- }
- dbus_message_iter_next(&value_iter);
- }
+ ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
+ if (ret != 0)
+ BT_ERR("vconf_get_bool failed");
- g_free(address);
+ return (is_flight_mode == 0) ? FALSE : TRUE;
+#else
return FALSE;
+#endif
}
-static bt_remote_dev_info_t *__bt_parse_interface(DBusMessage *msg)
+void _bt_handle_adapter_event(GVariant *msg, const char *member)
{
- DBusMessageIter msg_iter;
- DBusMessageIter value_iter;
- char *object_path = NULL;
- bt_remote_dev_info_t *dev_info = NULL;
+ BT_DBG("+");
- retv_if(dbus_message_iter_init(msg, &msg_iter) == FALSE, NULL);
+ int result = BLUETOOTH_ERROR_NONE;
+ GVariant *param = NULL;
+ ret_if(member == NULL);
- dbus_message_iter_get_basic(&msg_iter, &object_path);
- retv_if(object_path == NULL, NULL);
+ if (strcasecmp(member, "DeviceCreated") == 0) {
+ char *object_path = NULL;
+ char *address;
+ bt_remote_dev_info_t *remote_dev_info;
- /* object array (oa) */
- retv_if(dbus_message_iter_next(&msg_iter) == FALSE, NULL);
- retv_if(dbus_message_iter_get_arg_type(&msg_iter) !=
- DBUS_TYPE_ARRAY, NULL);
+ ret_if(_bt_is_device_creating() == FALSE);
- dbus_message_iter_recurse(&msg_iter, &value_iter);
+ /* Bonding from remote device */
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- /* string array (sa) */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- char *interface_name = NULL;
- DBusMessageIter interface_iter;
+ g_variant_get(msg, "(&o)", &object_path);
+ _bt_convert_device_path_to_address((const char*)object_path, address);
- dbus_message_iter_recurse(&value_iter, &interface_iter);
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
+ if (remote_dev_info == NULL) {
+ g_free(address);
+ return;
+ }
- retv_if(dbus_message_iter_get_arg_type(&interface_iter) !=
- DBUS_TYPE_STRING, NULL);
+ _bt_free_device_info(remote_dev_info);
+ g_free(address);
+ } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
+ char *object_path = NULL;
+ char *address;
+ bt_cache_info_t *cache_info;
+ bt_remote_dev_info_t *dev_info;
+ GList * node;
- dbus_message_iter_get_basic(&interface_iter, &interface_name);
+ /* Bonding from remote device */
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- retv_if(dbus_message_iter_next(&interface_iter) == FALSE, NULL);
+ g_variant_get(msg, "(&o)", &object_path);
- retv_if(dbus_message_iter_get_arg_type(&interface_iter) !=
- DBUS_TYPE_ARRAY, NULL);
+ _bt_convert_device_path_to_address((const char *)object_path, address);
- BT_DBG("interface: %s", interface_name);
+ node = g_list_first(p_cache_list);
- if (g_strcmp0(interface_name, "org.bluez.Device1") == 0) {
- BT_DBG("Found a device: %s", object_path);
+ while (node != NULL) {
+ cache_info = (bt_cache_info_t *)node->data;
- dev_info = __bt_parse_device_properties(&interface_iter);
+ if (cache_info == NULL) {
+ node = g_list_next(node);
+ continue;
+ }
- if (dev_info == NULL) {
- BT_ERR("Fail to parse the properies");
- return NULL;
+ dev_info = cache_info->dev_info;
+ if (strcasecmp(dev_info->address,
+ address) == 0) {
+ p_cache_list = g_list_remove(p_cache_list,
+ cache_info);
+ __bt_free_cache_info(cache_info);
+ break;
}
+ node = g_list_next(node);
}
+ g_free(address);
+ } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
+ BT_DBG("Advertising Enabled");
+ int slot_id;
+ int event;
+ int adv_handle;
+ gboolean status = FALSE;
- dbus_message_iter_next(&value_iter);
- }
+ g_variant_get(msg, "(ib)", &slot_id, &status);
+
+ BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
+
+ /* Send event to application */
+ _bt_set_advertising_status(slot_id, status);
- return dev_info;
+ adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
+
+ if (status)
+ event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
+ else
+ event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
+ param = g_variant_new("(ii)", result,
+ adv_handle);
+
+#if 0
+ const char *sender;
+ sender = _bt_get_adv_slot_owner(slot_id);
+ _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
+ event,
+ param);
+#else
+ _bt_send_event(BT_ADAPTER_EVENT, event, param);
+#endif
+
+ if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
+ _bt_unregister_adv_slot_owner(slot_id);
+ } else if (strcasecmp(member, "RssiEnabled") == 0) {
+ BT_DBG("RSSI Enabled");
+ gboolean status = FALSE;
+ char *address = NULL;
+ int link_type;
+ g_variant_get(msg, "(sib)", &address, &link_type, &status);
+
+ BT_DBG("RSSI Enabled [%s %d]", address, status);
+ param = g_variant_new("(isib)", result,
+ address, link_type, status);
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_RSSI_ENABLED,
+ param);
+ g_free(address);
+ } else if (strcasecmp(member, "RssiAlert") == 0) {
+ BT_DBG("RSSI Alert");
+ int alert_type;
+ int rssi_dbm;
+ int link_type;
+ char *address = NULL;
+ g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
+
+ BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
+ address, alert_type, rssi_dbm);
+ param = g_variant_new("(isiii)", result,
+ address, link_type, alert_type, rssi_dbm);
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_RSSI_ALERT,
+ param);
+ g_free(address);
+ } else if (strcasecmp(member, "RawRssi") == 0) {
+ BT_DBG("RSSI Raw");
+ int rssi_dbm;
+ int link_type;
+ char *address = NULL;
+ g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
+
+ BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
+ address, link_type, rssi_dbm);
+ param = g_variant_new("(isii)", result,
+ address, link_type, rssi_dbm);
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_RAW_RSSI,
+ param);
+ g_free(address);
+ } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
+ BT_ERR_C("Hardware error received from BLUEZ");
+/* Don't add the recovery logic into platform */
+#if 0
+ _bt_recover_adapter();
+#endif
+ } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
+ BT_ERR_C("Tx timeout error received from BLUEZ");
+/* Don't add the recovery logic into platform */
+#if 0
+ _bt_recover_adapter();
+#endif
+ }
+ BT_DBG("-");
}
-char *__bt_get_headset_name(char *address)
+static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
{
- bluetooth_device_address_t device_address = { {0} };
- bluetooth_device_info_t dev_info;
-
- retv_if(address == NULL, strdup(""));
+ GDBusProxy *adapter_proxy;
+ int mode = 0;
+ int result = BLUETOOTH_ERROR_NONE;
+ GVariantIter value_iter;
+ GVariant *val = NULL;
+ GVariant *ret = NULL;
+ GError *err = NULL;
+ char *property = NULL;
+ GVariant *param = NULL;
+ g_variant_iter_init(&value_iter, msg);
+ while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
+ BT_INFO("Property %s", property);
+
+ if (strcasecmp(property, "Discovering") == 0) {
+ gboolean discovering = FALSE;
+ g_variant_get(val, "b", &discovering);
+ /* Send event to application */
+ BT_DBG("Discovering %d", discovering);
+ if (discovering == TRUE) {
+ _bt_set_discovery_status(TRUE);
+ param = g_variant_new("(i)", result);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_DISCOVERY_STARTED,
+ param);
+ } else {
+ ret_if(event_id > 0);
- _bt_convert_addr_string_to_type(device_address.addr, address);
+ adapter_proxy = _bt_get_adapter_proxy();
+ ret_if(adapter_proxy == NULL);
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
+ /* Need to stop searching */
+ ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ &err);
+ if (err) {
+ BT_ERR("Dbus Error : %s", err->message);
+ g_clear_error(&err);
+ }
+ if (ret)
+ g_variant_unref(ret);
- _bt_get_bonded_device_info(&device_address, &dev_info);
+ event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
+ (GSourceFunc)_bt_discovery_finished_cb, NULL);
+ }
+ } else if (strcasecmp(property, "LEDiscovering") == 0) {
+ gboolean le_discovering = FALSE;
- return g_strdup(dev_info.device_name.name);
-}
+ g_variant_get(val, "b", &le_discovering);
+ /* Send event to application */
+ if (le_discovering == TRUE) {
+ _bt_set_le_scan_status(TRUE);
+ param = g_variant_new("(i)", result);
+ _bt_send_event(BT_LE_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
+ param);
+ } else {
+ ret_if(le_scan_event_id > 0);
-static int __bt_get_owner_info(DBusMessage *msg, char **name,
- char **previous, char **current)
-{
- DBusMessageIter item_iter;
+ adapter_proxy = _bt_get_adapter_proxy();
+ ret_if(adapter_proxy == NULL);
- dbus_message_iter_init(msg, &item_iter);
+ /* Need to stop searching */
+ ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ &err);
+ if (err) {
+ BT_ERR("Dbus Error %s", err->message);
+ g_clear_error(&err);
+ }
+ if (ret)
+ g_variant_unref(ret);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ le_scan_event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
+ (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
+ }
+ } else if (strcasecmp(property, "Name") == 0) {
+ char *name = NULL;
+ g_variant_get(val, "s", &name);
+ param = g_variant_new("(is)", result, name);
+ /* Send event to application */
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
+ param);
+ g_free(name);
+ } else if (strcasecmp(property, "Alias") == 0) {
+ char *alias = NULL;
+ g_variant_get(val, "s", &alias);
+ param = g_variant_new("(is)", result, alias);
+ /* Send event to application */
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
+ param);
+ g_free(alias);
+ } else if (strcasecmp(property, "Discoverable") == 0) {
+ gboolean discoverable = FALSE;
+
+ g_variant_get(val, "b", &discoverable);
+ BT_DBG("discoverable %d", discoverable);
+
+ if (discoverable == FALSE) {
+ if (_bt_get_discoverable_timeout_property() > 0) {
+ int time = 0;
+ adapter_proxy = _bt_get_adapter_properties_proxy();
+ ret_if(adapter_proxy == NULL);
+ ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
+ g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
+ "DiscoverableTimeout",
+ g_variant_new("i", time)),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_TIMEOUT, NULL,
+ &err);
+
+ if (err != NULL) {
+ BT_ERR("StopLEDiscovery Failed: %s", err->message);
+ g_error_free(err);
+ }
+ if (ret)
+ g_variant_unref(ret);
+ }
- dbus_message_iter_get_basic(&item_iter, name);
+ mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
- retv_if(*name == NULL, BLUETOOTH_ERROR_INTERNAL);
+ /* Send event to application */
+ BT_INFO("[Connectable]");
+ param = g_variant_new("(in)", result, mode);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+ param);
+ } else {
+ _bt_get_discoverable_mode(&mode);
- dbus_message_iter_next(&item_iter);
+ /* Event will be sent by "DiscoverableTimeout" signal */
+ if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
+ g_free(property);
+ g_variant_unref(val);
+ return;
+ }
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ /* Send event to application */
+ BT_INFO("[General Discoverable]");
+ param = g_variant_new("(in)", result, mode);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+ param);
+ }
+ } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
+ _bt_get_discoverable_mode(&mode);
- dbus_message_iter_get_basic(&item_iter, previous);
+ /* Event was already sent by "Discoverable" signal */
+ if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
+ mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
+ g_free(property);
+ g_variant_unref(val);
+ return;
+ }
- retv_if(*previous == NULL, BLUETOOTH_ERROR_INTERNAL);
+ /* Send event to application */
+ BT_INFO("[Limited Discoverable (Timeout %u secs)]",
+ _bt_get_discoverable_timeout_property());
+ param = g_variant_new("(in)", result, mode);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+ param);
+ } else if (strcasecmp(property, "Powered") == 0) {
+ /* TODO: Need to check this operation!! */
+ gboolean powered = FALSE;
+ int bt_state;
+
+ g_variant_get(val, "b", &powered);
+ BT_DBG("Powered = %d", powered);
+ if (powered == FALSE) {
+#ifdef TIZEN_FEATURE_BT_USB_DONGLE
+ _bt_handle_adapter_removed();
+#else
+ if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
+ bt_state != VCONFKEY_BT_STATUS_OFF) {
+ if (__bt_handle_is_flight_mode_enabled() == FALSE)
+ _bt_disable_adapter();
+ else
+ _bt_handle_adapter_removed();
+ }
+#endif
+ if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
+ bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
+ _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
+ }
+ } else {
+#ifdef TIZEN_FEATURE_BT_USB_DONGLE
+ _bt_handle_adapter_added();
+#endif
+ }
+ } else if (strcasecmp(property, "Connectable") == 0) {
+ gboolean connectable = FALSE;
- dbus_message_iter_next(&item_iter);
+ g_variant_get(val, "b", &connectable);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ BT_DBG("Connectable property is changed : %d", connectable);
+ param = g_variant_new("(b)", connectable);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
+ param);
+#if 0
+ if (_bt_adapter_get_status() == BT_DEACTIVATING &&
+ _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
+ connectable == 0)
+ _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+#endif
+ } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
+ char *name = NULL;
+ char *value = NULL;
+ GVariantIter *iter = NULL;
+ g_variant_get(val, "as", &iter);
+
+ ret_if(iter == NULL);
+
+ while (g_variant_iter_loop(iter, "s", &name)) {
+ BT_DBG("name = %s", name);
+ g_variant_iter_loop(iter, "s", &value);
+ BT_DBG("Value = %s", value);
+ if (FALSE == _bt_update_le_feature_support(name, value))
+ BT_INFO("Fail to update LE feature info");
+ }
- dbus_message_iter_get_basic(&item_iter, current);
+ g_variant_iter_free(iter);
+ } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
+ gboolean ipsp_initialized = FALSE;
- retv_if(*current == NULL, BLUETOOTH_ERROR_INTERNAL);
+ g_variant_get(val, "b", &ipsp_initialized);
+ BT_DBG("IPSP init state changed: %d", ipsp_initialized);
+ param = g_variant_new("(b)", ipsp_initialized);
- return BLUETOOTH_ERROR_NONE;
+ /* Send event to application */
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
+ param);
+ } else {
+ BT_DBG("property : [%s]", property);
+ }
+ }
}
-static int __bt_get_agent_signal_info(DBusMessage *msg, char **address,
- char **name, char **uuid)
+static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
{
- DBusMessageIter item_iter;
+ BT_DBG("+");
- dbus_message_iter_init(msg, &item_iter);
+ GVariantIter value_iter;
+ GVariant *child = NULL, *val = NULL;
+ char *property = NULL;
+ g_variant_iter_init(&value_iter, msg);
+ while ((child = g_variant_iter_next_value(&value_iter))) {
+ g_variant_get(child, "{sv}", &property, &val);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ ret_if(property == NULL);
- dbus_message_iter_get_basic(&item_iter, address);
+ BT_DBG("property :%s", property);
- dbus_message_iter_next(&item_iter);
+ if (strcasecmp(property, "Status") == 0) {
+ char *status;
+ g_variant_get(val, "s", &status);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return BLUETOOTH_ERROR_INTERNAL;
+ if (strcasecmp(status, "active") == 0) {
+ _bt_obex_transfer_started(path);
+ } else if (strcasecmp(status, "complete") == 0) {
+ _bt_obex_transfer_completed(path, TRUE);
+ _bt_pbap_obex_transfer_completed(path, TRUE);
+ } else if (strcasecmp(status, "error") == 0) {
+ _bt_obex_transfer_completed(path, FALSE);
+ _bt_pbap_obex_transfer_completed(path, FALSE);
+ }
+ g_free(status);
+ } else if (strcasecmp(property, "Transferred") == 0) {
+ guint64 transferred = 0;
+ /* As Transferred is expected guint64 so change int to guint64 and
+ * eariler transferred is static because of it can overwrite data
+ * on present on opc_obex_conn or obexd_conn as these are
+ * static memory are in sequential */
+ g_variant_get(val, "t", &transferred);
+
+ _bt_obex_transfer_progress(path, transferred);
+ }
+ g_free(property);
+ g_variant_unref(val);
+ g_variant_unref(child);
}
+ BT_DBG("-");
+}
- dbus_message_iter_get_basic(&item_iter, name);
+static void __bt_device_property_changed_event(GVariant *msg, const char *path)
+{
+ BT_DBG("+");
- dbus_message_iter_next(&item_iter);
+ int event;
+ int result = BLUETOOTH_ERROR_NONE;
+ GVariantIter value_iter;
+ GVariant *val;
+ char *property = NULL;
+ char *address;
+ GVariant *param = NULL;
+ bt_remote_dev_info_t *remote_dev_info;
+ g_variant_iter_init(&value_iter, msg);
+#ifdef TIZEN_FEATURE_BT_DPM
+ int desktop_state = DPM_BT_ERROR;
+#endif
+ while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
+ BT_DBG("Property %s", property);
+ if (strcasecmp(property, "Connected") == 0) {
+ guint connected = 0;
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ g_variant_get(val, "i", &connected);
- dbus_message_iter_get_basic(&item_iter, uuid);
+ event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
+ BLUETOOTH_EVENT_DEVICE_CONNECTED :
+ BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
- return BLUETOOTH_ERROR_NONE;
-}
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-gboolean _bt_stop_discovery_timeout_cb(gpointer user_data)
-{
- DBusGProxy *adapter_proxy;
+ _bt_convert_device_path_to_address(path, address);
- event_id = 0;
+ BT_DBG("connected: %d", connected);
+ BT_DBG("address: %s", address);
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, FALSE);
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
- /* Need to stop searching */
- dbus_g_proxy_call(adapter_proxy,
- "StopDiscovery",
- NULL,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ if (remote_dev_info != NULL) {
+ __bt_device_remote_connected_properties(
+ remote_dev_info, address,
+ connected != BLUETOOTH_CONNECTED_LINK_NONE ?
+ TRUE : FALSE);
+ _bt_free_device_info(remote_dev_info);
+ }
+ param = g_variant_new("(is)", result, address);
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ event,
+ param);
+ g_free(address);
+ } else if (strcasecmp(property, "RSSI") == 0) {
+ bt_remote_dev_info_t *remote_dev_info;
- return FALSE;
-}
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-void _bt_stop_discovery_timeout(void)
-{
- if (event_id > 0)
- return;
+ _bt_convert_device_path_to_address(path, address);
+ BT_DBG("address: %s", address);
- event_id = g_timeout_add(BT_STOP_DISCOVERY_TIMEOUT,
- (GSourceFunc)_bt_stop_discovery_timeout_cb, NULL);
-}
+ g_free(address);
-static gboolean __bt_discovery_finished()
-{
- int result = BLUETOOTH_ERROR_NONE;
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
+ if (remote_dev_info == NULL) {
+ g_free(property);
+ g_variant_unref(val);
+ return;
+ }
+ BT_DBG("Address type %d", remote_dev_info->addr_type);
+
+ if (remote_dev_info->addr_type == 0) {
+ BT_DBG("Name %s", remote_dev_info->name);
+
+#ifdef TIZEN_FEATURE_BT_DPM
+ _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
+ if (desktop_state == DPM_RESTRICTED) {
+ bluetooth_device_class_t device_class;
+ _bt_divide_device_class(&device_class, remote_dev_info->class);
+
+ if (device_class.major_class ==
+ BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
+ _bt_free_device_info(remote_dev_info);
+ g_free(property);
+ g_variant_unref(val);
+ return;
+ }
+ }
+#endif
+
+ GVariant *uuids = NULL;
+ GVariantBuilder *builder = NULL;
+ int i = 0;
+ builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+ for (i = 0; i < remote_dev_info->uuid_count; i++) {
+ g_variant_builder_add(builder, "s",
+ remote_dev_info->uuids[i]);
+ }
+ uuids = g_variant_new("as", builder);
+ g_variant_builder_unref(builder);
+ GVariant *manufacturer_data = NULL;
+ manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
+ remote_dev_info->manufacturer_data,
+ remote_dev_info->manufacturer_data_len,
+ TRUE,
+ NULL, NULL);
+ param = g_variant_new("(isunsbub@asn@ay)", result,
+ remote_dev_info->address,
+ remote_dev_info->class,
+ remote_dev_info->rssi,
+ remote_dev_info->name,
+ remote_dev_info->paired,
+ remote_dev_info->connected,
+ remote_dev_info->trust,
+ uuids,
+ remote_dev_info->manufacturer_data_len,
+ manufacturer_data);
- if (_bt_get_cancel_by_user() == TRUE) {
- result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- }
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
+ param);
+ }
+ _bt_free_device_info(remote_dev_info);
+ } else if (strcasecmp(property, "GattConnected") == 0) {
+ gboolean gatt_connected = FALSE;
- _bt_set_cancel_by_user(FALSE);
- _bt_set_discovery_status(FALSE);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERY_FINISHED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID);
+ g_variant_get(val, "b", &gatt_connected);
- return FALSE;
-}
+ event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
+ BLUETOOTH_EVENT_GATT_DISCONNECTED;
-void __bt_adapter_property_changed_event(DBusMessageIter *msg_iter, const char *path)
-{
- int mode = 0;
- int result = BLUETOOTH_ERROR_NONE;
- DBusMessageIter value_iter;
- DBusMessageIter dict_iter;
- DBusMessageIter item_iter;
- GValue timeout = { 0 };
- const char *property = NULL;
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- dbus_message_iter_recurse(msg_iter, &item_iter);
+ _bt_convert_device_path_to_address(path, address);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_DICT_ENTRY) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
+ BT_DBG("gatt_connected: %d", gatt_connected);
+ BT_DBG("address: %s", address);
+ param = g_variant_new("(is)", result, address);
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ event,
+ param);
+ g_free(address);
+ } else if (strcasecmp(property, "Paired") == 0) {
+ gboolean paired = FALSE;
+ bt_remote_dev_info_t *remote_dev_info;
+ g_variant_get(val, "b", &paired);
+ _bt_agent_set_canceled(FALSE);
+ /* BlueZ sends paired signal for each paired device */
+ /* during activation, We should ignore this, otherwise*/
+ /* application thinks that a new device got paired */
+ if (_bt_adapter_get_status() != BT_ACTIVATED) {
+ BT_DBG("BT is not activated, so ignore this");
+ g_free(property);
+ g_variant_unref(val);
+ return;
+ }
- dbus_message_iter_recurse(&item_iter, &dict_iter);
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- dbus_message_iter_get_basic(&dict_iter, &property);
- ret_if(property == NULL);
+ _bt_convert_device_path_to_address(path, address);
- ret_if(!dbus_message_iter_next(&dict_iter));
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
+ if (remote_dev_info == NULL) {
+ g_free(property);
+ g_variant_unref(val);
+ g_free(address);
+ return;
+ }
+
+ if (paired == FALSE) {
+ BT_INFO("Unpaired: %s", address);
+ __bt_update_remote_cache_devinfo(address, FALSE);
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
+ param);
+#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
+ {
+ char *last_connected = NULL;
+ last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
+ if (!g_strcmp0(address, last_connected))
+ _bt_audio_set_auto_connect_device_addr("");
+ if (last_connected)
+ free(last_connected);
+ }
+#endif
+ } else {
+ char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+ _bt_convert_addr_string_to_secure_string(secure_addr, address);
+ BT_INFO("### Paired: %s", secure_addr);
+ __bt_update_remote_cache_devinfo(address, TRUE);
+
+ if (_bt_is_device_creating() == TRUE) {
+ BT_DBG("Try to Pair by me");
+ _bt_free_device_info(remote_dev_info);
+ g_free(address);
+ g_free(property);
+ g_variant_unref(val);
+ return;
+ }
+ GVariant *uuids = NULL;
+ GVariantBuilder *builder = NULL;
+ int i = 0;
+ builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+ for (i = 0; i < remote_dev_info->uuid_count; i++) {
+ g_variant_builder_add(builder, "s",
+ remote_dev_info->uuids[i]);
+ }
+ uuids = g_variant_new("as", builder);
+ g_variant_builder_unref(builder);
+ GVariant *manufacturer_data = NULL;
+ manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
+ remote_dev_info->manufacturer_data,
+ remote_dev_info->manufacturer_data_len,
+ TRUE,
+ NULL, NULL);
+
+ param = g_variant_new("(isunsbub@asn@ay)", result,
+ address, remote_dev_info->class,
+ remote_dev_info->rssi,
+ remote_dev_info->name,
+ remote_dev_info->paired,
+ remote_dev_info->connected,
+ remote_dev_info->trust,
+ uuids,
+ remote_dev_info->manufacturer_data_len,
+ manufacturer_data);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_BONDING_FINISHED,
+ param);
+ }
+ _bt_free_device_info(remote_dev_info);
+ g_free(address);
+ } else if (strcasecmp(property, "LegacyPaired") == 0) {
+ gboolean paired = FALSE;
+ bt_remote_dev_info_t *remote_dev_info;
+ unsigned char auth_info[5] = {0, };
- if (strcasecmp(property, "Discovering") == 0) {
- gboolean discovering = FALSE;
+ if (_bt_adapter_get_status() != BT_ACTIVATED) {
+ BT_DBG("BT is not activated, so ignore this");
+ g_free(property);
+ g_variant_unref(val);
+ return;
+ }
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &discovering);
+ g_variant_get(val, "b", &paired);
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ BT_DBG("LegacyPaired: %d", paired);
+ _bt_convert_device_path_to_address(path, address);
- /* Send event to application */
- if (discovering == TRUE) {
- _bt_set_discovery_status(TRUE);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERY_STARTED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID);
- _bt_get_temp_remote_devinfo();
- } else {
- if (event_id > 0){
- g_source_remove(event_id);
- event_id = 0;
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
+ if (remote_dev_info == NULL) {
+ g_free(address);
+ g_free(property);
+ g_variant_unref(val);
+ return;
}
- __bt_discovery_finished();
- }
- } else if (strcasecmp(property, "Alias") == 0) {
- char *name = NULL;
+ if (remote_dev_info->is_alias_set == FALSE) {
+ /*minimum Size of the samsung specific manufacturer data is greater than 30 */
+ if ((remote_dev_info->manufacturer_data_len > 30) &&
+ (remote_dev_info->manufacturer_data[0] == 0x00) &&
+ (remote_dev_info->manufacturer_data[1] == 0x75)) {
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &name);
+ /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
+ 1 (discovery version) + 1 (associated service ID)
+ 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID);
- } else if (strcasecmp(property, "Powered") == 0) {
- gboolean power = FALSE;
+ memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
+ }
+ }
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &power);
+ BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
+ _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
+ remote_dev_info->name, auth_info, NULL, NULL, NULL);
- BT_DBG("power state changed: %d", power);
+ _bt_free_device_info(remote_dev_info);
+ g_free(address);
+ } else if (strcasecmp(property, "Trusted") == 0) {
+ gboolean trusted = FALSE;
- if (power == TRUE)
- _bt_set_enabled();
- else
- _bt_set_disabled();
+ g_variant_get(val, "b", &trusted);
- } else if (strcasecmp(property, "Discoverable") == 0) {
- gboolean discoverable = FALSE;
+ event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
+ BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &discoverable);
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- if (discoverable == FALSE) {
- if (_bt_get_discoverable_timeout_property() > 0) {
- DBusGProxy *adapter_proxy;
- g_value_init(&timeout, G_TYPE_UINT);
- g_value_set_uint(&timeout, 0);
+ _bt_convert_device_path_to_address(path, address);
- adapter_proxy = _bt_get_adapter_properties_proxy();
- ret_if(adapter_proxy == NULL);
+ BT_DBG("trusted: %d", trusted);
+ BT_DBG("address: %s", address);
+ param = g_variant_new("(is)", result, address);
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ event,
+ param);
+ g_free(address);
+ } else if (strcasecmp(property, "TrustedProfiles") == 0) {
+ int trusted = 0;
- dbus_g_proxy_call_no_reply(adapter_proxy, "Set",
- G_TYPE_STRING, BT_ADAPTER_INTERFACE,
- G_TYPE_STRING, "DiscoverableTimeout",
- G_TYPE_VALUE, &timeout,
- G_TYPE_INVALID);
+ g_variant_get(val, "u", &trusted);
- g_value_unset(&timeout);
- }
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_device_path_to_address(path, address);
- mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
+ BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
+ g_variant_new("(isi)", result, address, trusted));
+ g_free(address);
+ } else if (strcasecmp(property, "IpspConnected") == 0) {
+ gboolean connected = FALSE;
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &mode,
- DBUS_TYPE_INVALID);
- } else {
- _bt_get_discoverable_mode(&mode);
+ g_variant_get(val, "b", &connected);
- /* Event will be sent by "DiscoverableTimeout" signal */
- ret_if(mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE);
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &mode,
- DBUS_TYPE_INVALID);
- }
- } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
- _bt_get_discoverable_mode(&mode);
+ event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
+ BLUETOOTH_EVENT_IPSP_DISCONNECTED;
- /* Event was already sent by "Discoverable" signal */
- ret_if(mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE);
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &mode,
- DBUS_TYPE_INVALID);
- }
-}
+ _bt_convert_device_path_to_address(path, address);
-static void __bt_device_remote_connected_properties(
- bt_remote_dev_info_t *remote_dev_info,
- char *address, gboolean connected)
-{
- int result = BLUETOOTH_ERROR_NONE;
+ BT_DBG("Ipspconnected: %d", connected);
+ BT_DBG("address: %s", address);
+ param = g_variant_new("(is)", result, address);
- BT_DBG("+");
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ event,
+ param);
+ g_free(address);
+ } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
+ char *ifname = NULL;
- if (remote_dev_info->uuid_count > 0 ) {
- for (int i = 0; i<remote_dev_info->uuid_count; i++) {
- char *uuid = remote_dev_info->uuids[i];
- if (strcasecmp(uuid, HID_UUID) == 0){
- int event = (connected == TRUE) ?
- BLUETOOTH_HID_CONNECTED :
- BLUETOOTH_HID_DISCONNECTED;
+ g_variant_get(val, "s", &ifname);
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
- _bt_send_event(BT_HID_EVENT, event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
- break;
- }
+ BT_DBG("Ipsp BT Interface Name: %s", ifname);
+ BT_DBG("address: %s", address);
+ param = g_variant_new("(iss)", result, address, ifname);
+
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
+ param);
+ g_free(address);
}
}
-
BT_DBG("-");
}
-void __bt_device_property_changed_event(DBusMessageIter *msg_iter, const char *path)
+static void __bt_media_control_changed_event(GVariant *msg, const char *path)
{
int event;
int result = BLUETOOTH_ERROR_NONE;
- DBusMessageIter value_iter;
- DBusMessageIter dict_iter;
- DBusMessageIter item_iter;
- const char *property = NULL;
+ GVariantIter value_iter;
+ char *property = NULL;
char *address;
+ GVariant *val = NULL;
+ GVariant *child = NULL;
bt_remote_dev_info_t *remote_dev_info;
-
- dbus_message_iter_recurse(msg_iter, &item_iter);
-
- do {
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_DICT_ENTRY) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
-
- dbus_message_iter_recurse(&item_iter, &dict_iter);
-
- dbus_message_iter_get_basic(&dict_iter, &property);
- ret_if(property == NULL);
-
- ret_if(!dbus_message_iter_next(&dict_iter));
-
+ GVariant *param = NULL;
+ g_variant_iter_init(&value_iter, msg);
+ while ((child = g_variant_iter_next_value(&value_iter))) {
+ g_variant_get(child, "{sv}", &property, &val);
+ BT_INFO("Property %s", property);
if (strcasecmp(property, "Connected") == 0) {
gboolean connected = FALSE;
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &connected);
+ g_variant_get(val, "b", &connected);
- event = connected ? BLUETOOTH_EVENT_DEVICE_CONNECTED :
- BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
+ event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
+ BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
address = g_malloc0(BT_ADDRESS_STRING_SIZE);
if (remote_dev_info != NULL) {
__bt_device_remote_connected_properties(
remote_dev_info, address, connected);
+ _bt_free_device_info(remote_dev_info);
}
-
+ param = g_variant_new("(is)", result, address);
/* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
-
+ _bt_send_event(BT_AVRCP_EVENT,
+ event,
+ param);
g_free(address);
+ }
+ g_free(property);
+ g_variant_unref(child);
+ g_variant_unref(val);
+ }
+ BT_DBG("-");
+}
- } else if (strcasecmp(property, "Paired") == 0) {
- gboolean paired = FALSE;
+int get_alert_level_enum(const char *alert)
+{
+ int lvl = -1;
+
+ if (strcmp(alert, "none") == 0)
+ lvl = BT_PXP_ALERT_NONE;
+ else if (strcmp(alert, "mild") == 0)
+ lvl = BT_PXP_ALERT_MILD;
+ else if (strcmp(alert, "high") == 0)
+ lvl = BT_PXP_ALERT_HIGH;
- GList *node;
- bt_remote_dev_info_t *dev_info;
+ return lvl;
+}
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &paired);
+static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
+{
+ int result = BLUETOOTH_ERROR_NONE;
+ int service_type;
+ int alert_lvl = -1;
+ GVariantIter value_iter;
+ char *property = NULL;
+ char *address;
+ GVariant *val = NULL;
+ GVariant *child = NULL;
+ GVariant *param = NULL;
+ g_variant_iter_init(&value_iter, msg);
- ret_if(paired == FALSE);
+ BT_DBG("+");
+ while ((child = g_variant_iter_next_value(&value_iter))) {
+ g_variant_get(child, "{sv}", &property, &val);
+ BT_INFO("Property %s", property);
- /* BlueZ sends paired signal for each paired device */
- /* during activation, We should ignore this, otherwise*/
- /* application thinks that a new device got paired */
- if (_bt_adapter_get_status() != BT_ACTIVATED) {
- BT_DBG("BT is not activated, so ignore this");
- return;
- }
+ if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
+ (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
+ char *alert_str = NULL;
address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
_bt_convert_device_path_to_address(path, address);
- remote_dev_info = _bt_get_remote_device_info(address);
- if (remote_dev_info == NULL) {
- g_free(address);
- return;
- }
-
- node = g_list_first(g_list);
+ if (strcasecmp(property, "LinkLossAlertLevel") == 0)
+ service_type = BT_PXP_PROPERTY_LLS;
+ else
+ service_type = BT_PXP_PROPERTY_IAS;
- while (node != NULL) {
- bt_remote_dev_info_t *dev_info;
- dev_info = (bt_remote_dev_info_t *)node->data;
- if (strcasecmp(dev_info->address, address) == 0) {
- g_list = g_list_remove(g_list, dev_info);
- _bt_free_device_info(dev_info);
- }
- node = g_list_next(node);
- }
+ g_variant_get(val, "s", &alert_str);
+ if (alert_str)
+ alert_lvl = get_alert_level_enum(alert_str);
- if (_bt_is_device_creating() == TRUE) {
- BT_DBG("Try to Pair by me or already paired");
- } else {
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_BONDING_FINISHED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_UINT32, &remote_dev_info->class,
- DBUS_TYPE_INT16, &remote_dev_info->rssi,
- DBUS_TYPE_STRING, &remote_dev_info->name,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->paired,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->connected,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &remote_dev_info->uuids, remote_dev_info->uuid_count,
- DBUS_TYPE_INVALID);
- }
+ param = g_variant_new("(isiii)", result, address,
+ role, service_type, alert_lvl);
- _bt_free_device_info(remote_dev_info);
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
+ param);
g_free(address);
+ g_free(alert_str);
}
- } while (dbus_message_iter_next(&item_iter));
+ g_free(property);
+ g_variant_unref(child);
+ g_variant_unref(val);
+ }
+ BT_DBG("-");
}
-void __bt_obex_property_changed_event(DBusMessageIter *msg_iter, const char *path)
+void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
{
- DBusMessageIter value_iter;
- DBusMessageIter dict_iter;
- DBusMessageIter item_iter;
- const char *property = NULL;
+ char *interface_name = NULL;
+ GVariant *val = NULL;
- dbus_message_iter_recurse(msg_iter, &item_iter);
+ g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_DICT_ENTRY) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
+ if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
+ __bt_adapter_property_changed_event(val,
+ object_path);
+ } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
+ __bt_device_property_changed_event(val, object_path);
+ } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
+ BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
+ __bt_obex_property_changed_event(val,
+ object_path);
+ } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
+ __bt_media_control_changed_event(val,
+ object_path);
+ } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
+ _bt_handle_avrcp_control_event(val,
+ object_path);
+ } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
+ BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
+ _bt_handle_network_client_event(val,
+ object_path);
+ } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
+ __bt_gatt_char_property_changed_event(val,
+ object_path);
+ } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
+ BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
+ _bt_handle_pxp_property_changed_event(val,
+ object_path, BT_PXP_REPORTER_ROLE);
+ }
+ g_variant_unref(val);
+}
- dbus_message_iter_recurse(&item_iter, &dict_iter);
+void __bt_opc_property_changed_event(GVariant *msg,
+ const char *path)
+{
+ GVariantIter value_iter;
+ char *property = NULL;
+ GVariant *val = NULL;
+ GVariant *child = NULL;
+
+ g_variant_iter_init(&value_iter, msg);
+ while ((child = g_variant_iter_next_value(&value_iter))) {
+ g_variant_get(child, "{sv}", &property, &val);
+ ret_if(property == NULL);
- dbus_message_iter_get_basic(&dict_iter, &property);
- ret_if(property == NULL);
+ if (strcasecmp(property, "Status") == 0) {
+ char *status = NULL;
+ g_variant_get(val, "s", &status);
+ BT_DBG("Status is %s", status);
- ret_if(!dbus_message_iter_next(&dict_iter));
+ if (strcasecmp(status, "active") == 0)
+ _bt_obex_client_started(path);
+ else if (strcasecmp(status, "complete") == 0)
+ _bt_obex_client_completed(path, TRUE);
+ else if (strcasecmp(status, "error") == 0)
+ _bt_obex_client_completed(path, FALSE);
- if (strcasecmp(property, "Status") == 0) {
- const char *status;
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &status);
+ g_free(status);
+ } else if (strcasecmp(property, "Transferred") == 0) {
+ guint64 transferred = 0;
+ g_variant_get(val, "t", &transferred);
- if (strcasecmp(status, "active") == 0){
- _bt_obex_transfer_started(path);
- }else if (strcasecmp(status, "complete") == 0) {
- _bt_obex_transfer_completed(path, TRUE);
- }else if (strcasecmp(status, "error") == 0){
- _bt_obex_transfer_completed(path, FALSE);
+ _bt_obex_client_progress(path, transferred);
+ } else {
+ BT_DBG("property : [%s]", property);
}
- } else if (strcasecmp(property, "Transferred") == 0) {
- static int transferred = 0;
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &transferred);
+ g_free(property);
+ g_variant_unref(child);
+ g_variant_unref(val);
+ }
+}
- _bt_obex_transfer_progress(path,transferred);
+void _bt_opc_property_changed_event(GVariant *msg, char *path)
+{
+ char *interface_name = NULL;
+ GVariant *value = NULL;
+ g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
+ BT_INFO("interface_name = %s", interface_name);
+ if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
+ __bt_opc_property_changed_event(value,
+ path);
+ } else {
+ BT_DBG("interface_name : [%s]", interface_name);
}
+ g_variant_unref(value);
}
-void _bt_handle_input_event(DBusMessage *msg)
+
+void _bt_handle_input_event(GVariant *msg, const char *path)
{
int result = BLUETOOTH_ERROR_NONE;
- DBusMessageIter item_iter;
- DBusMessageIter value_iter;
gboolean property_flag = FALSE;
- const char *member = dbus_message_get_member(msg);
- const char *path = dbus_message_get_path(msg);
- const char *property = NULL;
-
- ret_if(member == NULL);
-
- dbus_message_iter_init(msg, &item_iter);
-
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
-
- dbus_message_iter_get_basic(&item_iter, &property);
+ GVariantIter value_iter;
+ char *property = NULL;
+ GVariant *child = NULL, *val = NULL;
+ bt_remote_dev_info_t *remote_dev_info;
+ GVariant *param = NULL;
+ g_variant_iter_init(&value_iter, msg);
+ while ((child = g_variant_iter_next_value(&value_iter))) {
+ g_variant_get(child, "{sv}", &property, &val);
- ret_if(property == NULL);
+ ret_if(property == NULL);
- if (strcasecmp(property, "Connected") == 0) {
- int event;
- char *address;
+ if (strcasecmp(property, "Connected") == 0) {
+ int event = BLUETOOTH_EVENT_NONE;
+ char *address;
+ g_variant_get(val, "b", &property_flag);
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &property_flag);
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_device_path_to_address(path, address);
- _bt_convert_device_path_to_address(path, address);
+ event = (property_flag == TRUE) ?
+ BLUETOOTH_HID_CONNECTED :
+ BLUETOOTH_HID_DISCONNECTED;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HID_EVENT, event,
+ param);
+ /* Check HID connection type (Keyboard or Mouse) and update the status */
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
+
+ if (property_flag == TRUE) {
+ hid_connected_device_count++;
+ __bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_HID_CONNECTED);
+ } else {
+ hid_connected_device_count--;
+ if (hid_connected_device_count == 0)
+ __bt_set_device_values(FALSE,
+ VCONFKEY_BT_DEVICE_HID_CONNECTED);
+ }
- event = (property_flag == TRUE) ?
- BLUETOOTH_HID_CONNECTED :
- BLUETOOTH_HID_DISCONNECTED;
+ if (remote_dev_info != NULL) {
+ BT_DBG("HID device class [%x]", remote_dev_info->class);
+ if (remote_dev_info->class &
+ BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
+ __bt_set_device_values(property_flag,
+ VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
- _bt_send_event(BT_HID_EVENT, event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
+ }
- g_free(address);
- }
- }
+ if (remote_dev_info->class &
+ BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
+ __bt_set_device_values(property_flag,
+ VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
+ }
+ _bt_free_device_info(remote_dev_info);
+ }
+ g_free(address);
+ }
+ g_free(property);
+ g_variant_unref(val);
+ g_variant_unref(child);
+ }
+}
-void _bt_handle_network_server_event(DBusMessage *msg)
+void _bt_handle_network_server_event(GVariant *msg, const char *member)
{
int result = BLUETOOTH_ERROR_NONE;
char *address = NULL;
char *device = NULL;
- const char *member = dbus_message_get_member(msg);
-
+ GVariant *param = NULL;
ret_if(member == NULL);
-
if (strcasecmp(member, "PeerConnected") == 0) {
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &device,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return;
- }
+ g_variant_get(msg, "(ss)", &device, &address);
+ __bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_PAN_CONNECTED);
+ param = g_variant_new("(iss)", result, device, address);
_bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &device,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
+ param);
+ g_free(device);
+ g_free(address);
+ nap_connected_device_count++;
} else if (strcasecmp(member, "PeerDisconnected") == 0) {
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &device,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Unexpected parameters in signal");
- return;
- }
-
+ g_variant_get(msg, "(ss)", &device, &address);
+ nap_connected_device_count--;
+ if (nap_connected_device_count == 0)
+ __bt_set_device_values(FALSE,
+ VCONFKEY_BT_DEVICE_PAN_CONNECTED);
+ param = g_variant_new("(iss)", result, device, address);
_bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &device,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
+ param);
+ g_free(device);
+ g_free(address);
}
}
-void __bt_handle_network_client_event(DBusMessageIter *msg_iter, const char *path)
+void _bt_handle_network_client_event(GVariant *msg,
+ const char *path)
{
+ BT_DBG("+");
+
int result = BLUETOOTH_ERROR_NONE;
- DBusMessageIter item_iter;
- DBusMessageIter value_iter;
- DBusMessageIter dict_iter;
gboolean property_flag = FALSE;
- const char *property = NULL;
-
- dbus_message_iter_recurse(msg_iter, &item_iter);
+ char *property = NULL;
+ GVariant *val = NULL;
+ GVariantIter value_iter;
+ GVariant *param = NULL;
+ g_variant_iter_init(&value_iter, msg);
+ while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
+ if (strcasecmp(property, "Connected") == 0) {
+ int event = BLUETOOTH_EVENT_NONE;
+ char *address;
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_DICT_ENTRY) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
+ g_variant_get(val, "b", &property_flag);
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- dbus_message_iter_recurse(&item_iter, &dict_iter);
- dbus_message_iter_get_basic(&dict_iter, &property);
+ _bt_convert_device_path_to_address(path, address);
- ret_if(property == NULL);
+ BT_DBG("property_flag %d", property_flag);
+ if (property_flag == TRUE) {
+ event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
+ nap_connected_device_count++;
+ __bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_PAN_CONNECTED);
+ } else {
+ event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
+ nap_connected_device_count--;
+ if (nap_connected_device_count == 0)
+ __bt_set_device_values(FALSE,
+ VCONFKEY_BT_DEVICE_PAN_CONNECTED);
+ }
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_NETWORK_EVENT, event,
+ param);
- ret_if(!dbus_message_iter_next(&dict_iter));
+ g_free(address);
+ }
+ }
+ BT_DBG("-");
+}
- if (strcasecmp(property, "Connected") == 0) {
- int event = BLUETOOTH_EVENT_NONE;
- char *address;
+void __bt_gatt_char_property_changed_event(GVariant *msg,
+ const char *path)
+{
+ GVariantIter value_iter;
+ char *property = NULL;
+ char * char_handle = NULL;
+ GVariant *val = NULL;
+ int result = BLUETOOTH_ERROR_NONE;
+ GVariant *param = NULL;
+ g_variant_iter_init(&value_iter, msg);
+ char_handle = g_strdup(path);
+ while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
+ BT_INFO("Property %s", property);
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &property_flag);
+ ret_if(property == NULL);
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ if (strcasecmp(property, "Notifying") == 0) {
+ gboolean property_flag = FALSE;
+ g_variant_get(val, "b", &property_flag);
+ if (property_flag == TRUE)
+ BT_DBG("notifying is enabled");
+ else
+ BT_DBG("notifying is disabled");
+ } else if (strcasecmp(property, "ChangedValue") == 0) {
+ int len = 0;
+ GByteArray *gp_byte_array = NULL;
+ BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
+
+ if (val) {
+ gp_byte_array = g_byte_array_new();
+ len = g_variant_get_size(val);
+ BT_DBG("Len = %d", len);
+ g_byte_array_append(gp_byte_array,
+ (const guint8 *) g_variant_get_data(val), len);
+ if (gp_byte_array->len != 0) {
+ GVariant *byte_array = NULL;
+ byte_array = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ gp_byte_array->data,
+ gp_byte_array->len,
+ TRUE, NULL, NULL);
+ param = g_variant_new("(is@ay)", result, char_handle,
+ byte_array);
+
+ /* Send event only registered client */
+ _bt_send_char_value_changed_event(param);
+ }
+ g_byte_array_free(gp_byte_array, TRUE);
+ }
+ }
+ }
+ g_free(char_handle);
+}
- _bt_convert_device_path_to_address(path, address);
+void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
+{
+ ret_if(path == NULL);
- if (property_flag == TRUE) {
- event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
- } else {
- event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
+ if (strcasecmp(member, "GattValueChanged") == 0) {
+
+#if 0 // Debug Only
+ /*** Debug only ***/
+ GVariant *value = NULL;
+ int value_len = 0;
+ char *buffer = NULL;
+
+ g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
+ value_len = g_variant_get_size(value);
+ if (value_len > 0) {
+ char buf[8 * 5 + 1] = { 0 };
+ int i;
+ int to;
+ buffer = (char *)g_variant_get_data(value);
+ to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
+
+ for (i = 0; i < to; i++)
+ snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
+ buf[i * 5] = '\0';
+ BT_DBG("GATT Val[%d] %s", value_len, buf);
}
+ g_variant_unref(value);
+ /******/
+#endif
- _bt_send_event(BT_NETWORK_EVENT, event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
-
- g_free(address);
+ /* Send event only registered client */
+ _bt_send_char_value_changed_event(msg);
}
}
-void _bt_handle_device_event(DBusMessage *msg)
+
+void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
{
+ int event = 0;
int result = BLUETOOTH_ERROR_NONE;
- DBusMessageIter item_iter;
- DBusMessageIter value_iter;
char *address;
- const char *member = dbus_message_get_member(msg);
- const char *path = dbus_message_get_path(msg);
+ char *dev_name = NULL;
const char *property = NULL;
-
+ GVariant *param = NULL;
+ char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
ret_if(path == NULL);
- ret_if(member == NULL);
if (strcasecmp(member, "PropertyChanged") == 0) {
- dbus_message_iter_init(msg, &item_iter);
-
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
- dbus_message_iter_get_basic(&item_iter, &property);
+ g_variant_get(msg, "(s)", &property);
ret_if(property == NULL);
- if (strcasecmp(property, "Connected") == 0) {
- int event;
+ if (strcasecmp(property, "GattConnected") == 0) {
gboolean connected = FALSE;
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &connected);
-
- event = connected ? BLUETOOTH_EVENT_DEVICE_CONNECTED :
- BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
-
+ char *address;
address = g_malloc0(BT_ADDRESS_STRING_SIZE);
_bt_convert_device_path_to_address(path, address);
+ g_variant_get(msg, "(b)", &connected);
- BT_DBG("connected: %d", connected);
- BT_DBG("address: %s", address);
-
- /* Send event to application */
+ event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
+ BLUETOOTH_EVENT_GATT_DISCONNECTED;
+ param = g_variant_new("(is)", result, address);
_bt_send_event(BT_DEVICE_EVENT,
event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
-
+ param);
g_free(address);
} else if (strcasecmp(property, "Paired") == 0) {
gboolean paired = FALSE;
bt_remote_dev_info_t *remote_dev_info;
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &paired);
+ g_variant_get(msg, "(b)", &paired);
ret_if(paired == FALSE);
_bt_convert_device_path_to_address(path, address);
- remote_dev_info = _bt_get_remote_device_info(address);
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
if (remote_dev_info == NULL) {
g_free(address);
return;
}
-
+ GVariant *uuids = NULL;
+ GVariantBuilder *builder = NULL;
+ int i = 0;
+ builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+ for (i = 0; i < remote_dev_info->uuid_count; i++) {
+ g_variant_builder_add(builder, "s",
+ remote_dev_info->uuids[i]);
+ }
+ uuids = g_variant_new("as", builder);
+ g_variant_builder_unref(builder);
+ GVariant *manufacturer_data = NULL;
+ manufacturer_data = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ remote_dev_info->manufacturer_data,
+ remote_dev_info->manufacturer_data_len,
+ TRUE, NULL, NULL);
+ param = g_variant_new("(isunsbub@asn@ay)", result,
+ address,
+ remote_dev_info->class,
+ remote_dev_info->rssi,
+ remote_dev_info->name,
+ remote_dev_info->paired,
+ remote_dev_info->connected,
+ remote_dev_info->trust,
+ uuids,
+ remote_dev_info->manufacturer_data_len,
+ manufacturer_data);
_bt_send_event(BT_ADAPTER_EVENT,
BLUETOOTH_EVENT_BONDING_FINISHED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_UINT32, &remote_dev_info->class,
- DBUS_TYPE_INT16, &remote_dev_info->rssi,
- DBUS_TYPE_STRING, &remote_dev_info->name,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->paired,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->connected,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &remote_dev_info->uuids, remote_dev_info->uuid_count,
- DBUS_TYPE_INVALID);
+ param);
+ _bt_free_device_info(remote_dev_info);
+ g_free(address);
+
+ } else if (strcasecmp(property, "UUIDs") == 0) {
+ /* Once we get the updated uuid information after
+ * reverse service search, update it to application */
+
+ bt_remote_dev_info_t *remote_dev_info;
+
+ ret_if(_bt_is_device_creating() == TRUE);
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
+ if (remote_dev_info == NULL) {
+ g_free(address);
+ return;
+ }
+
+ BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
+ if (remote_dev_info->paired && remote_dev_info->uuid_count) {
+ GVariant *uuids = NULL;
+ GVariantBuilder *builder = NULL;
+ int i = 0;
+ builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+ for (i = 0; i < remote_dev_info->uuid_count; i++) {
+ g_variant_builder_add(builder, "s",
+ remote_dev_info->uuids[i]);
+ }
+ uuids = g_variant_new("as", builder);
+ g_variant_builder_unref(builder);
+ GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
+ remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
+ TRUE, NULL, NULL);
+
+ param = g_variant_new("(isunsbub@asn@ay)", result,
+ address, remote_dev_info->class,
+ remote_dev_info->rssi,
+ remote_dev_info->name,
+ remote_dev_info->paired,
+ remote_dev_info->connected,
+ remote_dev_info->trust,
+ uuids,
+ remote_dev_info->manufacturer_data_len,
+ manufacture_data);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_SERVICE_SEARCHED,
+ param);
+ }
_bt_free_device_info(remote_dev_info);
g_free(address);
}
- }
-}
+ } else if (strcasecmp(member, "DeviceConnected") == 0) {
+ unsigned char addr_type = 0;
-void __bt_handle_media_control_event(DBusMessageIter *msg_iter,
- const char *path)
-{
- int result = BLUETOOTH_ERROR_NONE;
- DBusMessageIter item_iter;
- DBusMessageIter value_iter;
- DBusMessageIter dict_iter;
- gboolean property_flag = FALSE;
- const char *property = NULL;
+ g_variant_get(msg, "(y)", &addr_type);
- dbus_message_iter_recurse(msg_iter, &item_iter);
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_DICT_ENTRY) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
+ _bt_convert_device_path_to_address(path, address);
+ dev_name = _bt_get_bonded_device_name(address);
+
+ _bt_convert_addr_string_to_secure_string(secure_address, address);
+ BT_INFO("Address : %s Type : %d", secure_address, addr_type);
+ BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
+ !addr_type ? dev_name : secure_address);
+ g_free(dev_name);
+
+ _bt_logging_connection(TRUE, addr_type);
+ param = g_variant_new("(isy)", result, address, addr_type);
+ /*Send event to application*/
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_DEVICE_CONNECTED,
+ param);
+ g_free(address);
+ } else if (strcasecmp(member, "Disconnected") == 0) {
+ unsigned char disc_reason = 0;
+ unsigned char addr_type = 0;
+ char *dev_name = NULL;
+ gboolean sending = FALSE;
- dbus_message_iter_recurse(&item_iter, &dict_iter);
+ g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
- dbus_message_iter_get_basic(&dict_iter, &property);
- ret_if(property == NULL);
+ result = disc_reason;
- ret_if(!dbus_message_iter_next(&dict_iter));
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- if (strcasecmp(property, "Connected") == 0) {
- int event;
- char *address;
+ _bt_convert_device_path_to_address(path, address);
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &property_flag);
+ /* 0x00 BDADDR_BRDER
+ 0x01 BDADDR_LE_PUBLIC
+ 0x02 BDADDR_LE_RANDOM */
+ _bt_convert_addr_string_to_secure_string(secure_address, address);
+ BT_INFO("Address : %s Type : %d", secure_address, addr_type);
+ BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
+ disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
+ !addr_type ? dev_name : secure_address);
+ g_free(dev_name);
+
+ _bt_headset_set_local_connection(FALSE);
+ _bt_logging_connection(FALSE, addr_type);
+
+ if (!addr_type) {
+#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
+ {
+ int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
+
+ if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
+ BT_ERR("vconf_get_int failed");
+
+ BT_INFO("conn_state[0x%x], adapter_state [%d]",
+ bt_device_state, _bt_adapter_get_status());
+
+ if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
+ _bt_audio_start_auto_connect(TRUE);
+ } else if (bt_device_state &
+ VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
+ BT_INFO("Disconnected due to turning BT off. Skip a address");
+ } else {
+ char *last_connected = NULL;
+ last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
+ if (!g_strcmp0(address, last_connected))
+ _bt_audio_set_auto_connect_device_addr("");
+ if (last_connected)
+ free(last_connected);
+ }
+ }
+
+#endif
+ /*Check for any OPP transfer on the device and cancel
+ * the transfer
+ */
+ _bt_obex_check_pending_transfer(address);
+ _bt_opp_client_is_sending(&sending);
+ if (sending == TRUE)
+ _bt_opp_client_check_pending_transfer(address);
+ }
+ param = g_variant_new("(isy)", result, address, addr_type);
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
+ param);
+ g_free(address);
+ } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
+ int state = 0;
+ char *profile_uuid = NULL;
+ bt_headset_wait_t *wait_list;
+ bluetooth_device_address_t bd_addr;
+
+ g_variant_get(msg, "(si)", &profile_uuid, &state);
address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_device_path_to_address(path, address);
+ _bt_convert_device_path_to_address(path, address);
+ _bt_convert_addr_string_to_type(bd_addr.addr, address);
+
+ _bt_convert_addr_string_to_secure_string(secure_address, address);
+ BT_DBG("Address: %s", secure_address);
+ BT_DBG("Profile UUID: %s", profile_uuid);
+ BT_DBG("State: %d", state);
+
+ if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
+ (state == BT_PROFILE_STATE_CONNECTED)) {
+
+ int event = BLUETOOTH_EVENT_AV_CONNECTED;
+ char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+ bluetooth_device_address_t device_address;
+ gboolean connected;
+ bt_headset_wait_t *wait_list;
+ guint restricted = 0x0;
+
+ __bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
+
+ __bt_connection_manager_set_state(address, event);
+
+ _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
+
+ if (_bt_headset_get_local_connection() == FALSE) {
+ if (restricted == 0x0) /* not restricted*/
+ _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
+ } else {
+ /* Connection Started from local device therefore no need to
+ * intiate connection for pending profile */
+ _bt_headset_set_local_connection(FALSE);
+ }
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HEADSET_EVENT, event,
+ param);
+ connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
+ connected_address);
+ if (connected) {
+ if (g_strcmp0(connected_address, address) != 0) {
+ _bt_convert_addr_string_to_type(
+ device_address.addr,
+ connected_address);
+ _bt_audio_disconnect(0, BT_AUDIO_A2DP,
+ &device_address, NULL);
+ }
+ }
+
+ _bt_add_headset_to_list(BT_AUDIO_A2DP,
+ BT_STATE_CONNECTED, address);
+
+ wait_list = _bt_get_audio_wait_data();
+ if (wait_list != NULL &&
+ (g_strcmp0(wait_list->address, address) == 0))
+ _bt_rel_wait_data();
+
+ } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
+ (state == BT_PROFILE_STATE_DISCONNECTED)) {
+
+ int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
+
+ if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
+ g_free(address);
+ g_free(profile_uuid);
+ return;
+ }
+
+ __bt_set_device_values(FALSE,
+ VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
+
+ __bt_connection_manager_set_state(address, event);
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HEADSET_EVENT, event,
+ param);
+ /* Remove data from the connected list */
+ _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
+ wait_list = _bt_get_audio_wait_data();
+
+ if (wait_list == NULL) {
+ g_free(address);
+ g_free(profile_uuid);
+ return;
+ }
+
+ if (((wait_list->type == BT_AUDIO_ALL) &&
+ (wait_list->ag_flag == TRUE)) ||
+ (wait_list->type == BT_AUDIO_A2DP) ||
+ (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
+ bluetooth_device_address_t device_address;
+ _bt_convert_addr_string_to_type(
+ device_address.addr,
+ wait_list->address);
- event = (property_flag == TRUE) ?
- BLUETOOTH_EVENT_AV_CONNECTED :
- BLUETOOTH_EVENT_AV_DISCONNECTED;
+ _bt_audio_connect(wait_list->req_id,
+ wait_list->type,
+ &device_address,
+ NULL);
+ }
+ } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
- _bt_send_event(BT_AVRCP_EVENT, event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
+ if (state == BT_PROFILE_STATE_CONNECTED) {
+ int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
+ char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+ bluetooth_device_address_t device_address;
+ gboolean connected;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
+ param);
+ connected = _bt_is_headset_type_connected(
+ BT_AVRCP,
+ connected_address);
+ if (connected) {
+ if (g_strcmp0(connected_address,
+ address) != 0) {
+ _bt_convert_addr_string_to_type(
+ device_address.addr,
+ connected_address);
+ _bt_audio_disconnect(0,
+ BT_AVRCP,
+ &device_address, NULL);
+ }
+ }
+ BT_DBG("device Path: %s", path);
+ _bt_add_headset_to_list(BT_AVRCP,
+ BT_STATE_CONNECTED, address);
+ } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
+ int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
+ param);
+ /* Remove data from the connected list */
+ _bt_remove_headset_from_list(BT_AVRCP, address);
+ }
+ } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
+ if (state == BT_PROFILE_STATE_CONNECTED) {
+ int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
+ BT_INFO("A2DP Source is connected");
+#ifdef TIZEN_BT_A2DP_SINK_ENABLE
+ __bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
+#endif
+
+#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
+ _bt_audio_set_auto_connect_device_addr(address);
+ _bt_audio_stop_auto_connect();
+#endif
+ _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
+ BT_STATE_CONNECTED, address);
+ _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
+ g_variant_new("(is)", result, address));
+ } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
+ int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
+ BT_INFO("A2DP Source Disconnected");
+#ifdef TIZEN_BT_A2DP_SINK_ENABLE
+ __bt_set_device_values(FALSE,
+ VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
+#endif
+ _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
+ _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
+ g_variant_new("(is)", result, address));
+
+ wait_list = _bt_get_audio_wait_data();
+ if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
+ bluetooth_device_address_t device_address;
+ _bt_convert_addr_string_to_type(
+ device_address.addr,
+ wait_list->address);
+ _bt_audio_connect(wait_list->req_id,
+ wait_list->type,
+ &device_address,
+ NULL);
+ /* Now free the wait list */
+ _bt_rel_wait_data();
+ }
+ }
+ } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
+ ((state == BT_PROFILE_STATE_CONNECTED) ||
+ (state == BT_PROFILE_STATE_DISCONNECTED))) {
+ int event;
+ if (state == BT_PROFILE_STATE_CONNECTED)
+ event = BLUETOOTH_HID_CONNECTED;
+ else
+ event = BLUETOOTH_HID_DISCONNECTED;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HID_EVENT, event,
+ param);
+ } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
+ if (state == BT_PROFILE_STATE_CONNECTED) {
+ int event;
+ event = BLUETOOTH_HID_DEVICE_CONNECTED;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HID_DEVICE_EVENT, event,
+ param);
+ } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
+ event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HID_DEVICE_EVENT, event,
+ param);
+ }
+ }
g_free(address);
- }
-}
+ g_free(profile_uuid);
+ } else if (strcasecmp(member, "AdvReport") == 0) {
+
+ bt_remote_le_dev_info_t *le_dev_info = NULL;
+ char *buffer = NULL;
+ int buffer_len = 0;
+ bt_le_adv_info_t *adv_info = NULL;
+ GVariant *value = NULL;
+ ret_if(_bt_is_le_scanning() == FALSE);
+
+ le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
+
+ g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
+ &le_dev_info->addr_type,
+ &le_dev_info->adv_type,
+ &le_dev_info->rssi,
+ &le_dev_info->adv_data_len,
+ &value);
+
+ ret_if(value == NULL);
+
+ _bt_convert_device_path_to_address(path, le_dev_info->address);
+
+ buffer_len = g_variant_get_size(value);
+ if (buffer_len > 0)
+ buffer = (char *)g_variant_get_data(value);
+
+ le_dev_info->adv_data = g_memdup(buffer, buffer_len);
+ if (le_dev_info->adv_data == NULL &&
+ le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
+ _bt_free_le_device_info(le_dev_info);
+ g_variant_unref(value);
+ return;
+ }
-void _bt_handle_property_changed_event(DBusMessage *msg)
-{
- DBusMessageIter item_iter;
- const char *member = dbus_message_get_member(msg);
- const char *interface_name = NULL;
+ if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
+ _bt_send_scan_result_event(le_dev_info, NULL);
+ _bt_free_le_device_info(le_dev_info);
+ g_variant_unref(value);
+ return;
+ }
- ret_if(member == NULL);
+ if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
+ adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
+ adv_info->addr = g_strdup(le_dev_info->address);
+ adv_info->addr_type = le_dev_info->addr_type;
+ adv_info->rssi = le_dev_info->rssi;
+ adv_info->data_len = le_dev_info->adv_data_len;
+ adv_info->data = g_malloc0(le_dev_info->adv_data_len);
+ memcpy(adv_info->data, le_dev_info->adv_data,
+ le_dev_info->adv_data_len);
+
+ if (__bt_add_adv_ind_info(adv_info) == 0) {
+ adv_info->timer_id = g_timeout_add(1000,
+ (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
+ }
+ } else { /* SCAN_RSP */
+ adv_info = __bt_get_adv_ind_info(le_dev_info->address);
+ if (adv_info) {
+ _bt_send_scan_result_event(le_dev_info, adv_info);
+ __bt_del_adv_ind_info(le_dev_info->address);
+ }
+ }
+ _bt_free_le_device_info(le_dev_info);
+ g_variant_unref(value);
+ } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
+ guint16 tx_octets = 0;
+ guint16 tx_time = 0;
+ guint16 rx_octets = 0;
+ guint16 rx_time = 0;
- dbus_message_iter_init(msg, &item_iter);
+ g_variant_get(msg, "(qqqq)",
+ &tx_octets, &tx_time, &rx_octets, &rx_time);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_device_path_to_address(path, address);
- dbus_message_iter_get_basic(&item_iter, &interface_name);
+ param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
+ rx_octets, rx_time);
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
+ g_free(address);
+ } else if (strcasecmp(member, "IpspStateChanged") == 0) {
+ gboolean connected = FALSE;
+ char *ifname = NULL;
- ret_if(interface_name == NULL);
+ g_variant_get(msg, "(bs)", &connected, &ifname);
- BT_DBG("interface: %s", interface_name);
+ event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
+ BLUETOOTH_EVENT_IPSP_DISCONNECTED;
- ret_if(dbus_message_iter_next(&item_iter) == FALSE);
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_device_path_to_address(path, address);
- ret_if(dbus_message_iter_get_arg_type(&item_iter) != DBUS_TYPE_ARRAY);
+ BT_DBG("Ipsp BT Interface Name: %s", ifname);
+ BT_DBG("address: %s", address);
+ param = g_variant_new("(iss)", result, address, ifname);
- if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
- __bt_adapter_property_changed_event(&item_iter,
- dbus_message_get_path(msg));
- } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
- __bt_device_property_changed_event(&item_iter,
- dbus_message_get_path(msg));
- } else if (strcasecmp(interface_name,
- BT_OBEX_TRANSFER_INTERFACE) == 0) {
- __bt_obex_property_changed_event(&item_iter,
- dbus_message_get_path(msg));
- } else if (strcasecmp(interface_name,
- BT_MEDIA_CONTROL_INTERFACE) == 0) {
- __bt_handle_media_control_event(&item_iter,
- dbus_message_get_path(msg));
- } else if (strcasecmp(interface_name,
- BT_NETWORK_CLIENT_INTERFACE) == 0) {
- __bt_handle_network_client_event(&item_iter,
- dbus_message_get_path(msg));
- } else {
- BT_DBG("No bluez interface");
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ event,
+ param);
+ g_free(address);
}
}
int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
/* Set the headset name */
- if (connected == TRUE) {
- name = __bt_get_headset_name(address);
- } else {
+ if (connected == TRUE)
+ name = _bt_get_bonded_device_name(address);
+ else
name = g_strdup("");
- }
- if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
- name) != 0) {
+ if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
BT_ERR("vconf_set_str failed");
- }
g_free(name);
/* Set the headset state */
- if (vconf_get_int(VCONFKEY_BT_DEVICE,
- &bt_device_state) != 0) {
- BT_ERR("vconf_get_str failed");
- }
+ if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
+ BT_ERR("vconf_get_int failed");
- if (connected == TRUE) {
+#ifdef TIZEN_SUPPORT_DUAL_HF
+ if ((connected == TRUE) &&
+ (FALSE == __bt_is_companion_device(address))) {
bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
- } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
+ } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
+ (FALSE == __bt_is_companion_device(address))) {
bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
}
+#else
+ if (connected == TRUE)
+ bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
+ else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
+ bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
+#endif
if (vconf_set_int(VCONFKEY_BT_DEVICE,
bt_device_state) != 0) {
}
}
-void _bt_handle_headset_event(DBusMessage *msg)
+void _bt_handle_headset_event(GVariant *msg, const char *path)
{
int result = BLUETOOTH_ERROR_NONE;
- DBusMessageIter item_iter;
- DBusMessageIter value_iter;
gboolean property_flag = FALSE;
- const char *member = dbus_message_get_member(msg);
- const char *path = dbus_message_get_path(msg);
- const char *property = NULL;
-
- ret_if(member == NULL);
-
- dbus_message_iter_init(msg, &item_iter);
-
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
-
- dbus_message_iter_get_basic(&item_iter, &property);
+ char *property = NULL;
+ GVariant *value = NULL;
+ GVariant *param = NULL;
+ g_variant_get(msg, "(sv)", &property, &value);
+ bluetooth_device_address_t bd_addr;
ret_if(property == NULL);
+ BT_DBG("Property = %s \n", property);
/* We allow only 1 headset connection (HSP or HFP)*/
if (strcasecmp(property, "Connected") == 0) {
int event = BLUETOOTH_EVENT_NONE;
+ bt_headset_wait_t *wait_list;
char *address;
-
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &property_flag);
+ guint restricted = 0x0;
+ g_variant_get(value, "b", &property_flag);
address = g_malloc0(BT_ADDRESS_STRING_SIZE);
_bt_convert_device_path_to_address(path, address);
+ _bt_convert_addr_string_to_type(bd_addr.addr, address);
if (property_flag == TRUE) {
event = BLUETOOTH_EVENT_AG_CONNECTED;
+ _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
+
+ if (_bt_headset_get_local_connection() == FALSE) {
+ if (restricted == 0x0) /* not restricted*/
+ _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
+ } else
+ _bt_headset_set_local_connection(FALSE);
} else {
+ int previous_state;
+
event = BLUETOOTH_EVENT_AG_DISCONNECTED;
- }
+ previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
+ if (previous_state == BT_STATE_DISCONNECTING)
+ _bt_send_hf_local_term_event(address);
+ }
+ /* Set the State machine here */
+ __bt_connection_manager_set_state(address, event);
__bt_set_audio_values(property_flag, address);
-
+ param = g_variant_new("(is)", result, address);
_bt_send_event(BT_HEADSET_EVENT, event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
+ param);
+
+ if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
+ /* Remove data from the connected list */
+ _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
+
+ wait_list = _bt_get_audio_wait_data();
+ if (wait_list == NULL) {
+ g_free(address);
+ return;
+ }
+
+ bluetooth_device_address_t device_address;
+
+ _bt_set_audio_wait_data_flag(TRUE);
+
+ _bt_convert_addr_string_to_type(device_address.addr,
+ wait_list->address);
+ _bt_audio_connect(wait_list->req_id, wait_list->type,
+ &device_address, NULL);
+ _bt_rel_wait_data();
+ } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
+ /* Add data to the connected list */
+ _bt_add_headset_to_list(BT_AUDIO_HSP,
+ BT_STATE_CONNECTED, address);
+
+ wait_list = _bt_get_audio_wait_data();
+ if (wait_list != NULL &&
+ (g_strcmp0(wait_list->address, address) == 0))
+ _bt_rel_wait_data();
+ BT_INFO("Check A2DP pending connect");
+ _bt_audio_check_pending_connect();
+ }
g_free(address);
} else if (strcasecmp(property, "State") == 0) {
- int event = BLUETOOTH_EVENT_NONE;
- int sco_connected = FALSE;
char *state = NULL;
- char *address;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &state);
+ g_variant_get(value, "s", &state);
/* This code assumes we support only 1 headset connection */
/* Need to use the headset list, if we support multi-headsets */
- if (strcasecmp(property, "Playing") == 0) {
- event = BLUETOOTH_EVENT_AG_AUDIO_CONNECTED;
- sco_connected = TRUE;
- } else if (strcasecmp(property, "connected") == 0 ||
- strcasecmp(property, "disconnected") == 0) {
- event = BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED;
- sco_connected = FALSE;
+ if (strcasecmp(state, "Playing") == 0) {
+ BT_DBG("Playing: Sco Connected");
+ } else if (strcasecmp(state, "connected") == 0 ||
+ strcasecmp(state, "disconnected") == 0) {
+ BT_DBG("connected/disconnected: Sco Disconnected");
} else {
- BT_ERR("Not handled state");
- g_free(address);
+ BT_ERR("Not handled state - %s", state);
+ g_free(state);
return;
}
-
- if (vconf_set_bool(VCONFKEY_BT_HEADSET_SCO, sco_connected) < 0)
- BT_ERR("vconf_set_bool - Failed\n");
-
- _bt_send_event(BT_HEADSET_EVENT, event,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
-
- g_free(address);
+ g_free(state);
} else if (strcasecmp(property, "SpeakerGain") == 0) {
guint16 spkr_gain;
char *address;
_bt_convert_device_path_to_address(path, address);
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &spkr_gain);
+ spkr_gain = g_variant_get_uint16(value);
+
+ BT_DBG("spkr_gain: %d", spkr_gain);
+ param = g_variant_new("(i&sq)", result, address, spkr_gain);
_bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_UINT16, &spkr_gain,
- DBUS_TYPE_INVALID);
+ param);
g_free(address);
} else if (strcasecmp(property, "MicrophoneGain") == 0) {
_bt_convert_device_path_to_address(path, address);
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &mic_gain);
+ mic_gain = g_variant_get_uint16(value);
+ param = g_variant_new("(i&sq)", result, address, mic_gain);
_bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_UINT16, &mic_gain,
- DBUS_TYPE_INVALID);
-
+ param);
g_free(address);
}
+
+ if (property)
+ g_free(property);
+ g_variant_unref(value);
+}
+
+void _bt_handle_sink_event(GVariant *msg, const char *path)
+{
+ GVariantIter value_iter;
+ char *property = NULL;
+
+ bt_headset_wait_t *wait_list;
+
+ GVariant *child = NULL;
+ GVariant *val = NULL;
+ GVariant *param = NULL;
+ g_variant_iter_init(&value_iter, msg);
+ while ((child = g_variant_iter_next_value(&value_iter))) {
+
+ g_variant_get(child, "{sv}", &property, &val);
+
+ ret_if(property == NULL);
+
+ BT_DBG("Property = %s \n", property);
+
+
+ if (strcasecmp(property, "State") == 0) {
+ int result = BLUETOOTH_ERROR_NONE;
+ char *value;
+
+ g_variant_get(val, "s", &value);
+ BT_DBG("value: %s", value);
+
+ if (g_strcmp0(value, "disconnected") == 0) {
+ char *address;
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+
+ __bt_set_device_values(FALSE,
+ VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HEADSET_EVENT,
+ BLUETOOTH_EVENT_AV_DISCONNECTED,
+ param);
+
+ /* Remove data from the connected list */
+ _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
+ wait_list = _bt_get_audio_wait_data();
+ if (wait_list == NULL) {
+ g_free(value);
+ g_free(property);
+ g_variant_unref(val);
+ g_variant_unref(child);
+ g_free(address);
+ return;
+ }
+
+ if (((wait_list->type == BT_AUDIO_ALL) &&
+ (wait_list->ag_flag == TRUE)) ||
+ (wait_list->type == BT_AUDIO_A2DP) ||
+ (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
+ bluetooth_device_address_t device_address;
+ _bt_convert_addr_string_to_type(
+ device_address.addr,
+ wait_list->address);
+
+ _bt_audio_connect(wait_list->req_id,
+ wait_list->type,
+ &device_address,
+ NULL);
+ }
+ g_free(address);
+ } else if (strcasecmp(value, "Connected") == 0) {
+ char *address;
+ char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+ bluetooth_device_address_t device_address;
+ gboolean connected;
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+
+ __bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HEADSET_EVENT,
+ BLUETOOTH_EVENT_AV_CONNECTED,
+ param);
+ /* Check for existing Media device to disconnect */
+ connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
+ connected_address);
+ if (connected) {
+ /* Match connected device address */
+ if (g_strcmp0(connected_address, address) != 0) {
+ /* Convert BD adress from string type */
+ _bt_convert_addr_string_to_type(
+ device_address.addr,
+ connected_address);
+ _bt_audio_disconnect(0, BT_AUDIO_A2DP,
+ &device_address, NULL);
+ }
+ }
+
+ /* Add data to the connected list */
+ _bt_add_headset_to_list(BT_AUDIO_A2DP,
+ BT_STATE_CONNECTED, address);
+
+ g_free(address);
+ }
+ g_free(value);
+ }
+ g_free(property);
+ g_variant_unref(val);
+ g_variant_unref(child);
+ }
}
-void _bt_handle_agent_event(DBusMessage *msg)
+void _bt_handle_agent_event(GVariant *msg, const char *member)
{
- const char *member = dbus_message_get_member(msg);
int result = BLUETOOTH_ERROR_NONE;
char *address = NULL;
char *name = NULL;
char *uuid = NULL;
-
+ GVariant *param = NULL;
ret_if(member == NULL);
if (strcasecmp(member, "ObexAuthorize") == 0) {
__bt_get_agent_signal_info(msg, &address, &name, &uuid);
-
+ param = g_variant_new("(iss)", result, address, name);
_bt_send_event(BT_OPP_SERVER_EVENT,
BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID);
+ param);
+ g_free(address);
+ g_free(name);
} else if (strcasecmp(member, "RfcommAuthorize") == 0) {
bt_rfcomm_server_info_t *server_info;
server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
ret_if(server_info == NULL);
ret_if(server_info->server_type != BT_CUSTOM_SERVER);
-
+ param = g_variant_new("(isssn)", result, address, uuid, name,
+ server_info->control_fd);
_bt_send_event(BT_RFCOMM_SERVER_EVENT,
BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &uuid,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INT16, &server_info->control_fd,
- DBUS_TYPE_INVALID);
+ param);
+ g_free(address);
+ g_free(uuid);
+ g_free(name);
}
}
-static int __bt_get_object_path(DBusMessage *msg, char **path)
+static int __bt_get_object_path(GVariant *msg, char **path)
{
- DBusMessageIter item_iter;
-
- dbus_message_iter_init(msg, &item_iter);
-
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_OBJECT_PATH) {
- BT_ERR("This is bad format dbus\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- dbus_message_iter_get_basic(&item_iter, path);
-
+ g_variant_get(msg, "(o*)", path, NULL);
if (*path == NULL)
return BLUETOOTH_ERROR_INTERNAL;
return BLUETOOTH_ERROR_NONE;
}
-static void __bt_devices_list_free()
+static void __bt_devices_list_free(void)
{
+ bt_cache_info_t *cache_info;
GList *node;
- node = g_list_first(g_list);
-
- while (node != NULL){
- bt_remote_dev_info_t *dev_info;
- dev_info = (bt_remote_dev_info_t *)node->data;
+ node = g_list_first(p_cache_list);
- g_list = g_list_remove(g_list, dev_info);
- _bt_free_device_info(dev_info);
+ while (node != NULL) {
+ cache_info = (bt_cache_info_t *)node->data;
+ p_cache_list = g_list_remove(p_cache_list, cache_info);
+ __bt_free_cache_info(cache_info);
node = g_list_next(node);
}
}
-static DBusHandlerResult __bt_manager_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static int __bt_parse_event(GVariant *msg)
{
- const char *member = dbus_message_get_member(msg);
- bt_event_type_t bt_event;
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ GVariantIter iter;
+ GVariant *child;
+ char *interface_name = NULL;
+ GVariant *inner_iter = NULL;
- BT_DBG("interface: %s | member: %s", dbus_message_get_interface(msg), member);
+ g_variant_iter_init(&iter, msg);
- if (strcasecmp(member, "InterfacesAdded") == 0) {
- char *object_path = NULL;
-
- if (__bt_get_object_path(msg, &object_path)) {
- BT_ERR("Fail to get the path");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ while ((child = g_variant_iter_next_value(&iter))) {
+ g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
+ if (g_strcmp0(interface_name,
+ BT_DEVICE_INTERFACE) == 0) {
+ g_variant_unref(inner_iter);
+ g_variant_unref(child);
+ return BT_DEVICE_EVENT;
+ } else if (g_strcmp0(interface_name,
+ BT_MEDIATRANSPORT_INTERFACE) == 0) {
+ g_variant_unref(inner_iter);
+ g_variant_unref(child);
+ return BT_MEDIA_TRANSFER_EVENT;
+ } else if (g_strcmp0(interface_name,
+ BT_PLAYER_CONTROL_INTERFACE) == 0) {
+ g_variant_unref(inner_iter);
+ g_variant_unref(child);
+ return BT_AVRCP_CONTROL_EVENT;
}
+ g_variant_unref(inner_iter);
+ g_variant_unref(child);
+ }
- bt_event = __bt_parse_event(msg);
-
- if (bt_event == BT_DEVICE_EVENT) {
- bt_remote_dev_info_t *dev_info;
- int result = BLUETOOTH_ERROR_NONE;
-
- retv_if(_bt_is_discovering() == FALSE,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- dev_info = __bt_parse_interface(msg);
-
- if (dev_info == NULL) {
- BT_ERR("Fail to parse the properies");
- return
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- if (dev_info->name == NULL)
- dev_info->name = g_strdup("");
-
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &dev_info->address,
- DBUS_TYPE_UINT32, &dev_info->class,
- DBUS_TYPE_INT16, &dev_info->rssi,
- DBUS_TYPE_STRING, &dev_info->name,
- DBUS_TYPE_BOOLEAN, &dev_info->paired,
- DBUS_TYPE_BOOLEAN,
- &dev_info->connected,
- DBUS_TYPE_BOOLEAN, &dev_info->trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &dev_info->uuids, dev_info->uuid_count,
- DBUS_TYPE_INVALID);
- g_list = g_list_append(g_list, dev_info);
- } else if (bt_event == BT_MEDIA_TRANSFER_EVENT) {
- __bt_parse_audio_properties(msg);
- }
+ return 0;
+}
- } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
+static void __bt_manager_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ bt_event_type_t bt_event = 0x00;
+ int result = BLUETOOTH_ERROR_NONE;
+ GVariant *value;
+ char *obj_path = NULL;
+ GVariant *param = NULL;
+ if (signal_name == NULL)
+ return;
+ if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
+ g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
+
+ if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
+#ifdef TIZEN_FEATURE_BT_USB_DONGLE
+ BT_DBG("Enable Adapter");
+ _bt_enable_adapter();
+#else
+ _bt_handle_adapter_added();
+#endif
+ } else {
+ bt_event = __bt_parse_event(value);
+ if (bt_event == BT_DEVICE_EVENT) {
+ bt_cache_info_t *cache_info;
+ bt_remote_dev_info_t *dev_info;
+#ifdef TIZEN_FEATURE_BT_DPM
+ int desktop_state = DPM_BT_ERROR;
+#endif
+ ret_if(_bt_is_discovering() == FALSE &&
+ _bt_is_le_scanning() == FALSE);
- bt_event = __bt_parse_remove_event(msg);
+ cache_info = g_malloc0(sizeof(bt_cache_info_t));
- if (bt_event == BT_MEDIA_TRANSFER_EVENT){
- _bt_parse_audio_remove_properties(msg);
- } else if (bt_event == BT_DEVICE_EVENT) {
- char *object_path = NULL;
- if (__bt_get_object_path(msg, &object_path)) {
- BT_ERR("Fail to get the path");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
- if (strncasecmp(object_path, BT_BLUEZ_HCI_DEV_PATH, strlen(BT_BLUEZ_HCI_DEV_PATH)) == 0) {
- int result = BLUETOOTH_ERROR_NONE;
- char *address;
- bt_remote_dev_info_t *dev_info;
- GList * node;
- gboolean is_in_glist = FALSE;
+ cache_info->dev_info = dev_info;
- BT_DBG("device interface removed | path: %s", object_path);
+ if (__bt_parse_interface(parameters, dev_info) == FALSE) {
+ BT_ERR("Fail to parse the properies");
+ __bt_free_cache_info(cache_info);
+ g_variant_unref(value);
+ return;
+ }
- /* Remove bonding from remote device */
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ if (dev_info->addr_type != BDADDR_BREDR) {
+ /* Whenever emit the property changed from bluez,
+ some property doesn't reach to bt-service.
+ So LE device is handled as AdvReport signal */
+ __bt_free_cache_info(cache_info);
+ g_variant_unref(value);
+ return;
+ }
- _bt_convert_device_path_to_address(object_path, address);
-
- node = g_list_first(g_list);
-
- while (node != NULL) {
- dev_info = (bt_remote_dev_info_t *)node->data;
- if (strcasecmp(dev_info->address, address) == 0) {
- is_in_glist = TRUE;
-
- BT_DBG("Bluez removes device %s, send device disappear event", dev_info->name);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_REMOTE_DEVICE_DISAPPEARED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &dev_info->address,
- DBUS_TYPE_UINT32, &dev_info->class,
- DBUS_TYPE_INT16, &dev_info->rssi,
- DBUS_TYPE_STRING, &dev_info->name,
- DBUS_TYPE_BOOLEAN, &dev_info->paired,
- DBUS_TYPE_BOOLEAN, &dev_info->connected,
- DBUS_TYPE_BOOLEAN, &dev_info->trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &dev_info->uuids, dev_info->uuid_count,
- DBUS_TYPE_INVALID);
-
- g_list = g_list_remove(g_list, dev_info);
- _bt_free_device_info(dev_info);
- break;
+ if (dev_info->name == NULL)
+ /* If Remote device name is NULL or still RNR is not done
+ * then display address as name.
+ */
+ dev_info->name = g_strdup(dev_info->address);
+
+#ifdef TIZEN_FEATURE_BT_DPM
+ _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
+ if (desktop_state == DPM_RESTRICTED) {
+ bluetooth_device_class_t device_class;
+ _bt_divide_device_class(&device_class, dev_info->class);
+ BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
+
+ if (device_class.major_class ==
+ BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
+ __bt_free_cache_info(cache_info);
+ g_variant_unref(value);
+ return;
}
- node = g_list_next(node);
}
- /* if device is not in glist, we need to trig destroy bonding event */
- if (!is_in_glist) {
- BT_DBG("send bt bond destroy event");
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID);
+#endif
+
+ GVariant *uuids = NULL;
+ GVariantBuilder *builder = NULL;
+ int i = 0;
+ builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+ for (i = 0; i < dev_info->uuid_count; i++) {
+ g_variant_builder_add(builder, "s",
+ dev_info->uuids[i]);
}
- g_free(address);
+ uuids = g_variant_new("as", builder);
+ g_variant_builder_unref(builder);
+ GVariant *manufacturer_data = NULL;
+ manufacturer_data = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ dev_info->manufacturer_data,
+ dev_info->manufacturer_data_len,
+ TRUE, NULL, NULL);
+ param = g_variant_new("(isunsbub@asn@ay)", result,
+ dev_info->address,
+ dev_info->class,
+ dev_info->rssi,
+ dev_info->name,
+ dev_info->paired,
+ dev_info->connected,
+ dev_info->trust,
+ uuids,
+ dev_info->manufacturer_data_len,
+ manufacturer_data);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
+ param);
+ p_cache_list = g_list_append(p_cache_list, cache_info);
+ } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
+ BT_DBG("Device path : %s ", obj_path);
+ _bt_set_control_device_path(obj_path);
}
- } else {
- char *object_path = NULL;
- if (__bt_get_object_path(msg, &object_path)) {
- BT_ERR("Fail to get the path");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ g_variant_unref(value);
+ } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
+#ifdef TIZEN_FEATURE_BT_USB_DONGLE
+ BT_DBG("InterfacesRemoved");
+ _bt_handle_adapter_removed();
+#endif
+ if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
+ bt_event = BT_MEDIA_TRANSFER_EVENT;
+ else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
+ bt_event = BT_DEVICE_EVENT;
+ else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
+ bt_event = BT_AVRCP_CONTROL_EVENT;
+
+ if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
+ _bt_handle_adapter_event(parameters, signal_name);
+ if (bt_event == BT_AVRCP_CONTROL_EVENT) {
+ BT_INFO("Object Path %s", obj_path);
+ _bt_remove_control_device_path(obj_path);
}
}
- } else if (strcasecmp(member, "NameOwnerChanged") == 0) {
+ } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
gboolean value;
char *name = NULL;
char *previous = NULL;
char *current = NULL;
- BT_DBG("NameOwnerChanged");
-
- if (__bt_get_owner_info(msg, &name, &previous, ¤t)) {
+ if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
BT_ERR("Fail to get the owner info");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return;
}
- if (*current != '\0')
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (*current != '\0') {
+ g_free(current);
+ if (name)
+ g_free(name);
+ if (previous)
+ g_free(previous);
+ return;
+ }
- if (strcasecmp(name, "org.bluez") == 0) {
- BT_DBG("Bluetoothd is terminated");
+ if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
+ BT_INFO_C("### Bluetoothd is terminated");
+ if (_bt_adapter_get_status() != BT_DEACTIVATING &&
+ _bt_adapter_get_status() != BT_DEACTIVATED) {
+ BT_INFO_C("### Recover it");
+ _bt_recover_adapter();
+ }
_bt_handle_adapter_removed();
__bt_devices_list_free();
}
/* The obex server was terminated abnormally */
_bt_rfcomm_server_check_termination(name);
}
- } else if (dbus_message_has_interface(msg, BT_PROPERTIES_INTERFACE)) {
- _bt_handle_property_changed_event(msg);
- } else if (dbus_message_has_interface(msg, BT_INPUT_INTERFACE)) {
- _bt_handle_input_event(msg);
- } else if (dbus_message_has_interface(msg, BT_NETWORK_SERVER_INTERFACE)) {
- _bt_handle_network_server_event(msg);
- } else if (dbus_message_has_interface(msg, BT_HFP_AGENT_INTERFACE)) {
- _bt_handle_headset_event(msg);
- } else if (dbus_message_has_interface(msg, BT_AGENT_INTERFACE)) {
- _bt_handle_agent_event(msg);
- } else if (dbus_message_has_interface(msg, BT_DEVICE_INTERFACE)) {
- _bt_handle_device_event(msg);
+
+ /* Stop advertising started by terminated process */
+ _bt_stop_advertising_by_terminated_process(name);
+ /* Stop LE Scan */
+ _bt_stop_le_scan(name);
+
+ /* Stop the Proximity reporter service */
+ _bt_proximity_reporter_stop_by_terminated_process(name);
+
+ g_free(name);
+ g_free(previous);
+ g_free(current);
+ } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
+ const char *path = object_path;
+
+ if (strncmp(path, BT_MEDIA_OBJECT_PATH,
+ strlen(BT_MEDIA_OBJECT_PATH)) == 0)
+ return;
+
+ _bt_handle_property_changed_event(parameters, object_path);
+ } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
+ _bt_handle_adapter_event(parameters, signal_name);
+ } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
+ _bt_handle_input_event(parameters, object_path);
+ } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
+ _bt_handle_network_server_event(parameters, signal_name);
+ } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
+ _bt_handle_headset_event(parameters, object_path);
+ } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
+ _bt_handle_sink_event(parameters, object_path);
+ } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
+ _bt_handle_agent_event(parameters, signal_name);
+ } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
+ _bt_handle_device_event(parameters, signal_name, object_path);
+ } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
+ _bt_handle_gatt_event(parameters, signal_name, object_path);
}
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return;
}
-static gboolean __bt_is_obexd_event(DBusMessage *msg)
+static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
{
- const char *member = dbus_message_get_member(msg);
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return FALSE;
+ if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
+ char *interface_name = NULL;
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
+ retv_if(interface_name == NULL, FALSE);
- if (dbus_message_has_interface(msg, BT_PROPERTIES_INTERFACE)) {
+ if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
+ BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
+ return TRUE;
+ }
+ }
- DBusMessageIter item_iter;
- const char *interface_name = NULL;
+ return FALSE;
+}
- dbus_message_iter_init(msg, &item_iter);
+static void __bt_obexd_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ const char *member = signal_name;
+ char *obj_path = NULL;
+ ret_if(member == NULL);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return FALSE;
- }
+ if (strcasecmp(member, "InterfacesAdded") == 0) {
+ if (__bt_get_object_path(parameters, &obj_path)) {
+ BT_ERR("Fail to get the path");
+ return;
+ }
+ BT_INFO("object_path = [%s]", obj_path);
- dbus_message_iter_get_basic(&item_iter, &interface_name);
+ /*Handle OPP_SERVER_CONNECTED_EVENT here */
+ if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
+ strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
+ g_free(obj_path);
+ return;
+ }
- retv_if(interface_name == NULL, FALSE);
+ if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
+ BT_DBG("Obex_Server_Session_Transfer connected");
+ _bt_obex_transfer_connected(obj_path);
+ }
+ g_free(obj_path);
+ } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
+ /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
+ if (__bt_get_object_path(parameters, &obj_path)) {
+ BT_ERR("Fail to get the path");
+ return;
+ }
+ BT_INFO("object_path = [%s]", obj_path);
+
+ if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
+ BT_DBG("Call PBAP Disconnected");
+ _bt_obex_pbap_client_disconnect(obj_path);
+ }
+
+ if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
+ strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
+ g_free(obj_path);
+ return;
+ }
+
+ if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
+ BT_DBG("Obex_Server_Session_Transfer disconnected %s",
+ obj_path);
+
+ _bt_obex_transfer_disconnected(obj_path);
+ }
+ g_free(obj_path);
+ } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
+ const char *path = object_path;
+
+ if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
+ strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
+ strncmp(path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
+ BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
+ return;
+ }
+
+ _bt_handle_property_changed_event(parameters, path);
+ }
+ BT_DBG("-");
+ return;
+}
+
+static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
+{
+ BT_DBG("+");
- BT_DBG("interface: %s", interface_name);
+ if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
+ char *interface_name = NULL;
- retv_if(dbus_message_iter_next(&item_iter) == FALSE, FALSE);
+ g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
- retv_if(dbus_message_iter_get_arg_type(&item_iter) != DBUS_TYPE_ARRAY,
- FALSE);
+ retv_if(interface_name == NULL, FALSE);
- if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0)
- return TRUE;
+ if (strcasecmp(interface_name,
+ BT_OBEX_TRANSFER_INTERFACE) == 0) {
+ BT_DBG("-");
+ return TRUE;
+ }
}
+ BT_DBG("-");
+
return FALSE;
}
-void __bt_opc_property_changed_event(DBusMessageIter *msg_iter,
- const char *path)
+static void __bt_opc_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
- DBusMessageIter value_iter;
- DBusMessageIter dict_iter;
- DBusMessageIter item_iter;
- const char *property = NULL;
-
- dbus_message_iter_recurse(msg_iter, &item_iter);
-
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_DICT_ENTRY) {
- BT_ERR("This is bad format dbus\n");
- return;
- }
-
- dbus_message_iter_recurse(&item_iter, &dict_iter);
+ const char *member = signal_name;
+ char *obj_path = NULL;
+ if (strcasecmp(member, "InterfacesAdded") == 0) {
+ BT_DBG("InterfacesAdded");
+ } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
- dbus_message_iter_get_basic(&dict_iter, &property);
- ret_if(property == NULL);
+ if (__bt_get_object_path(parameters, &obj_path)) {
+ BT_ERR("Fail to get the path");
+ return;
+ }
- ret_if(!dbus_message_iter_next(&dict_iter));
+ BT_DBG("object_path = %s", obj_path);
- if (strcasecmp(property, "Status") == 0) {
- const char *status = NULL;
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &status);
+ if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
+ || strstr(obj_path, "transfer") == NULL) {
+ g_free(obj_path);
+ return;
+ } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
+ BT_DBG("Going to call opc disconnected");
+ _bt_opc_disconnected(obj_path);
+ }
- if(strcasecmp(status, "active") == 0){
- _bt_obex_client_started(path);
- }else if (strcasecmp(status, "complete") == 0) {
- _bt_obex_client_completed(TRUE);
- }else if (strcasecmp(status, "error") == 0){
- _bt_obex_client_completed(FALSE);
+ _bt_sending_files();
+ g_free(obj_path);
+ } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
+ char *path = (char *)object_path;
+ BT_INFO("object_path %s", path);
+ if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
+ strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
+ BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
+ return;
}
- } else if (strcasecmp(property, "Transferred") == 0) {
- static int transferred = 0;
- dbus_message_iter_recurse(&dict_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &transferred);
- _bt_obex_client_progress(transferred);
+ _bt_opc_property_changed_event(parameters, path);
}
+
+ return;
}
-void _bt_opc_property_changed_event(DBusMessage *msg)
+int _bt_opp_client_event_init(void)
{
- DBusMessageIter item_iter;
- const char *member = dbus_message_get_member(msg);
- const char *interface_name = NULL;
-
- ret_if(member == NULL);
+ GError *error = NULL;
- dbus_message_iter_init(msg, &item_iter);
+ if (opc_obexd_conn == NULL) {
+ opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return;
+ if (!opc_obexd_conn) {
+ if (error) {
+ BT_ERR("Unable to connect to dbus: %s", error->message);
+ g_clear_error(&error);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
}
- dbus_message_iter_get_basic(&item_iter, &interface_name);
-
- ret_if(interface_name == NULL);
-
- BT_DBG("interface: %s", interface_name);
+ if (_bt_register_service_event(opc_obexd_conn,
+ BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
+ g_object_unref(opc_obexd_conn);
+ opc_obexd_conn = NULL;
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
- ret_if(dbus_message_iter_next(&item_iter) == FALSE);
+ return BLUETOOTH_ERROR_NONE;
+}
- ret_if(dbus_message_iter_get_arg_type(&item_iter) != DBUS_TYPE_ARRAY);
+void _bt_opp_client_event_deinit(void)
+{
+ if (opc_obexd_conn) {
+ _bt_unregister_service_event(opc_obexd_conn,
+ BT_OPP_CLIENT_EVENT);
+ g_object_unref(opc_obexd_conn);
+ opc_obexd_conn = NULL;
+ }
+}
- if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
- __bt_opc_property_changed_event(&item_iter,
- dbus_message_get_path(msg));
+int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
+
+ static int subs_interface_added_id = -1;
+ static int subs_interface_removed_id = -1;
+ static int subs_name_owner_id = -1;
+ static int subs_property_id = -1;
+ static int subs_adapter_id = -1;
+ static int subs_gatt_id = -1;
+
+ if (subscribe) {
+ if (subs_interface_added_id == -1) {
+ subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE,
+ BT_INTERFACES_ADDED, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_interface_removed_id == -1) {
+ subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE,
+ BT_INTERFACES_REMOVED, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_name_owner_id == -1) {
+ subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_FREEDESKTOP_INTERFACE,
+ BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_property_id == -1) {
+ subs_property_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_PROPERTIES_INTERFACE,
+ BT_PROPERTIES_CHANGED, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_adapter_id == -1) {
+ subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_ADAPTER_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_gatt_id == -1) {
+ subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_GATT_CHAR_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
} else {
- BT_DBG("No bluez interface");
+ if (subs_interface_added_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_interface_added_id);
+ subs_interface_added_id = -1;
+ }
+ if (subs_interface_removed_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_interface_removed_id);
+ subs_interface_removed_id = -1;
+ }
+ if (subs_name_owner_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_name_owner_id);
+ subs_name_owner_id = -1;
+ }
+ if (subs_property_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_property_id);
+ subs_property_id = -1;
+ }
+ if (subs_adapter_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
+ subs_adapter_id = -1;
+ }
+ if (subs_gatt_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
+ subs_gatt_id = -1;
+ }
}
+ return 0;
}
-static gboolean __bt_is_obexd_client_event(DBusMessage *msg)
+int _bt_register_device_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
{
- const char *member = dbus_message_get_member(msg);
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return FALSE;
-
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (dbus_message_has_interface(msg, BT_PROPERTIES_INTERFACE)) {
- DBusMessageIter item_iter;
- const char *interface_name = NULL;
-
- dbus_message_iter_init(msg, &item_iter);
-
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus\n");
- return FALSE;
+ if (conn == NULL)
+ return -1;
+
+ static int subs_device_id = -1;
+
+ if (subscribe) {
+ if (subs_device_id == -1) {
+ subs_device_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_DEVICE_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
}
+ } else {
+ if (subs_device_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_device_id);
+ subs_device_id = -1;
+ }
+ }
+ return 0;
+}
- dbus_message_iter_get_basic(&item_iter, &interface_name);
-
- retv_if(interface_name == NULL, FALSE);
-
- BT_DBG("interface: %s", interface_name);
-
- retv_if(dbus_message_iter_next(&item_iter) == FALSE,
- FALSE);
-
- retv_if(dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_ARRAY, FALSE);
-
- if (strcasecmp(interface_name,
- BT_OBEX_TRANSFER_INTERFACE) == 0)
- return TRUE;
+int _bt_register_input_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
+
+ static int subs_input_id = -1;
+
+ if (subscribe) {
+ if (subs_input_id == -1) {
+ subs_input_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_INPUT_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_input_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_input_id);
+ subs_input_id = -1;
+ }
}
+ return 0;
+}
- return FALSE;
+int _bt_register_network_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
+
+ static int subs_serv_id = -1;
+ static int subs_client_id = -1;
+
+ if (subscribe) {
+ if (subs_serv_id == -1) {
+ subs_serv_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_NETWORK_SERVER_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_client_id == -1) {
+ subs_client_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_NETWORK_CLIENT_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_serv_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_serv_id);
+ subs_serv_id = -1;
+ }
+ if (subs_client_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_client_id);
+ subs_client_id = -1;
+ }
+ }
+ return 0;
}
-static DBusHandlerResult __bt_opc_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
{
- const char *member = dbus_message_get_member(msg);
+ if (conn == NULL)
+ return -1;
+
+ static int subs_headset_id = -1;
+ static int subs_sink_id = -1;
+
+ if (subscribe) {
+ if (subs_headset_id == -1) {
+ subs_headset_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_HEADSET_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ if (subs_sink_id == -1) {
+ subs_sink_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_SINK_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_manager_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_headset_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_headset_id);
+ subs_headset_id = -1;
+ }
+ if (subs_sink_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_sink_id);
+ subs_sink_id = -1;
+ }
+ }
+ return 0;
+}
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+ static int subs_opp_server_interface_added_id = -1;
+ static int subs_opp_server_interface_removed_id = -1;
+ static int subs_opp_server_property_id = -1;
- if (strcasecmp(member, "InterfacesAdded") == 0) {
- BT_DBG("InterfacesAdded");
- }else if (strcasecmp(member, "InterfacesRemoved") == 0) {
- char *object_path = NULL;
- if (__bt_get_object_path(msg, &object_path)) {
- BT_ERR("Fail to get the path");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (subscribe) {
+ if (subs_opp_server_interface_added_id == -1) {
+ subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE,
+ BT_INTERFACES_ADDED, NULL, NULL, 0,
+ __bt_obexd_event_filter,
+ NULL, NULL);
}
+ if (subs_opp_server_interface_removed_id == -1) {
+ subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE,
+ BT_INTERFACES_REMOVED, NULL, NULL, 0,
+ __bt_obexd_event_filter,
+ NULL, NULL);
+ }
+ if (subs_opp_server_property_id == -1) {
+ subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_PROPERTIES_INTERFACE,
+ BT_PROPERTIES_CHANGED, NULL, NULL, 0,
+ __bt_obexd_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_opp_server_interface_added_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_opp_server_interface_added_id);
+ subs_opp_server_interface_added_id = -1;
+ }
+ if (subs_opp_server_interface_removed_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_opp_server_interface_removed_id);
+ subs_opp_server_interface_removed_id = -1;
+ }
+ if (subs_opp_server_property_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_opp_server_property_id);
+ subs_opp_server_property_id = -1;
+ }
+ }
+ return 0;
+}
- BT_DBG("object_path =%s",object_path);
-
- if (strncmp(object_path, BT_SESSION_BASEPATH_CLIENT,
- strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
- || strstr(object_path, "transfer") == NULL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- _bt_sending_files();
+int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
- }else if (__bt_is_obexd_client_event(msg) == TRUE){
- const char *path = dbus_message_get_path(msg);
+ static int subs_opp_client_interface_added_id = -1;
+ static int subs_opp_client_interface_removed_id = -1;
+ static int subs_opp_client_property_id = -1;
- if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
- strlen(BT_SESSION_BASEPATH_CLIENT)) != 0)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- _bt_opc_property_changed_event(msg);
+ if (subscribe) {
+ if (subs_opp_client_interface_added_id == -1) {
+ subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE,
+ BT_INTERFACES_ADDED, NULL, NULL, 0,
+ __bt_opc_event_filter,
+ NULL, NULL);
+ }
+ if (subs_opp_client_interface_removed_id == -1) {
+ subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_MANAGER_INTERFACE,
+ BT_INTERFACES_REMOVED, NULL, NULL, 0,
+ __bt_opc_event_filter,
+ NULL, NULL);
+ }
+ if (subs_opp_client_property_id == -1) {
+ subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_PROPERTIES_INTERFACE,
+ BT_PROPERTIES_CHANGED, NULL, NULL, 0,
+ __bt_opc_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_opp_client_interface_added_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_opp_client_interface_added_id);
+ subs_opp_client_interface_added_id = -1;
+ }
+ if (subs_opp_client_interface_removed_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_opp_client_interface_removed_id);
+ subs_opp_client_interface_removed_id = -1;
+ }
+ if (subs_opp_client_property_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_opp_client_property_id);
+ subs_opp_client_property_id = -1;
+ }
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return 0;
}
-static DBusHandlerResult __bt_obexd_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
{
- const char *member = dbus_message_get_member(msg);
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- retv_if(member == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- if (__bt_is_obexd_event(msg) == TRUE){
- const char *path = dbus_message_get_path(msg);
+ if (conn == NULL)
+ return -1;
+
+ static int subs_a2dp_source_id = -1;
+ static int subs_a2dp_sink_id = -1;
+
+ if (subscribe) {
+ if (subs_a2dp_source_id == -1) {
+ subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_A2DP_SOURCE_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_opc_event_filter,
+ NULL, NULL);
+ }
+ if (subs_a2dp_sink_id == -1) {
+ subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_SINK_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bt_opc_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_a2dp_source_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_a2dp_source_id);
+ subs_a2dp_source_id = -1;
+ }
+ if (subs_a2dp_sink_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_a2dp_sink_id);
+ subs_a2dp_sink_id = -1;
+ }
+ }
+ return 0;
+}
- if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
- strlen(BT_SESSION_BASEPATH_SERVER)) != 0)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+static void __bt_dump_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ return;
+}
- _bt_handle_property_changed_event(msg);
+int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
+ gboolean subscribe)
+{
+ if (conn == NULL)
+ return -1;
+
+ static int subs_source_id = -1;
+
+ if (subscribe) {
+ if (subs_source_id == -1) {
+ subs_source_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BT_DUMP_SERVICE_INTERFACE,
+ BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
+ __bt_dump_event_filter,
+ NULL, NULL);
+ }
+ } else {
+ if (subs_source_id != -1) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subs_source_id);
+ subs_source_id = -1;
+ }
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return 0;
}
-int _bt_register_service_event(DBusGConnection *g_conn, int event_type)
+int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
{
- DBusError dbus_error;
- char *match1 = NULL;
- char *match2 = NULL;
- char *match3 = NULL;
- char *match4 = NULL;
- DBusConnection *conn;
- DBusHandleMessageFunction event_func = NULL;
+ BT_DBG("+");
retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = dbus_g_connection_get_connection(g_conn);
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
switch (event_type) {
case BT_MANAGER_EVENT:
- event_func = __bt_manager_event_filter;
- match1 = g_strdup_printf(MANAGER_EVENT_MATCH_RULE,
- BT_MANAGER_INTERFACE,
- BT_INTERFACES_ADDED);
-
- match2 = g_strdup_printf(MANAGER_EVENT_MATCH_RULE,
- BT_MANAGER_INTERFACE,
- BT_INTERFACES_REMOVED);
-
- match3 = g_strdup_printf(MANAGER_EVENT_MATCH_RULE,
- BT_FREEDESKTOP_INTERFACE,
- BT_NAME_OWNER_CHANGED);
-
- match4 = g_strdup_printf(MANAGER_EVENT_MATCH_RULE,
- BT_PROPERTIES_INTERFACE,
- BT_PROPERTIES_CHANGED);
+ _bt_register_manager_subscribe_signal(g_conn, TRUE);
break;
case BT_DEVICE_EVENT:
- match1 = g_strdup_printf(EVENT_MATCH_RULE,
- BT_DEVICE_INTERFACE);
+ _bt_register_device_subscribe_signal(g_conn, TRUE);
break;
case BT_HID_EVENT:
- match1 = g_strdup_printf(EVENT_MATCH_RULE,
- BT_INPUT_INTERFACE);
+ _bt_register_input_subscribe_signal(g_conn, TRUE);
break;
case BT_NETWORK_EVENT:
- match1 = g_strdup_printf(EVENT_MATCH_RULE,
- BT_NETWORK_SERVER_INTERFACE);
-
- match2 = g_strdup_printf(EVENT_MATCH_RULE,
- BT_NETWORK_CLIENT_INTERFACE);
+ _bt_register_network_subscribe_signal(g_conn, TRUE);
break;
case BT_HEADSET_EVENT:
- match1 = g_strdup_printf(EVENT_MATCH_RULE,
- BT_HFP_AGENT_INTERFACE);
-
- match2 = g_strdup_printf(EVENT_MATCH_RULE,
- BT_SINK_INTERFACE);
+ _bt_register_audio_subscribe_signal(g_conn, TRUE);
break;
+
case BT_OPP_SERVER_EVENT:
- event_func = __bt_obexd_event_filter;
- match1 = g_strdup_printf(MANAGER_EVENT_MATCH_RULE,
- BT_PROPERTIES_INTERFACE,
- BT_PROPERTIES_CHANGED);
+ BT_ERR("BT_OPP_SERVER_EVENT: register service event");
+ _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
break;
case BT_OPP_CLIENT_EVENT:
- event_func = __bt_opc_event_filter;
- match1 = g_strdup_printf(MANAGER_EVENT_MATCH_RULE,
- BT_PROPERTIES_INTERFACE,
- BT_PROPERTIES_CHANGED);
-
- match2 = g_strdup_printf(MANAGER_EVENT_MATCH_RULE,
- BT_MANAGER_INTERFACE,
- BT_INTERFACES_ADDED);
-
- match3 = g_strdup_printf(MANAGER_EVENT_MATCH_RULE,
- BT_MANAGER_INTERFACE,
- BT_INTERFACES_REMOVED);
+ BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
+ _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
+ break;
+ case BT_A2DP_SOURCE_EVENT:
+ BT_INFO("A2dp Source event");
+ _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
break;
default:
BT_ERR("Unknown event");
return BLUETOOTH_ERROR_INTERNAL;
}
- if (event_func) {
- if (!dbus_connection_add_filter(conn, event_func,
- NULL, NULL)) {
- BT_ERR("Fail to add filter");
- goto fail;
- }
- }
-
- dbus_error_init(&dbus_error);
-
- if (match1)
- dbus_bus_add_match(conn, match1, &dbus_error);
-
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add match: %s\n", dbus_error.message);
- dbus_error_free(&dbus_error);
- goto fail;
- }
-
- if (match2)
- dbus_bus_add_match(conn, match2, &dbus_error);
-
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add match: %s\n", dbus_error.message);
- dbus_error_free(&dbus_error);
- goto fail;
- }
-
- if (match3)
- dbus_bus_add_match(conn, match3, &dbus_error);
-
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add match: %s\n", dbus_error.message);
- dbus_error_free(&dbus_error);
- goto fail;
- }
-
- if (match4)
- dbus_bus_add_match(conn, match4, &dbus_error);
-
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add match: %s\n", dbus_error.message);
- dbus_error_free(&dbus_error);
- goto fail;
- }
-
- g_free(match1);
- g_free(match2);
- g_free(match3);
- g_free(match4);
-
return BLUETOOTH_ERROR_NONE;
-fail:
- g_free(match1);
- g_free(match2);
- g_free(match3);
- g_free(match4);
- return BLUETOOTH_ERROR_INTERNAL;
}
-void _bt_unregister_service_event(DBusGConnection *g_conn, int event_type)
+void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
{
- DBusConnection *conn;
- DBusHandleMessageFunction event_func;
+ BT_DBG("+");
ret_if(g_conn == NULL);
- conn = dbus_g_connection_get_connection(g_conn);
switch (event_type) {
case BT_MANAGER_EVENT:
- event_func = __bt_manager_event_filter;
+ _bt_register_manager_subscribe_signal(g_conn, FALSE);
+ _bt_register_device_subscribe_signal(g_conn, FALSE);
+ _bt_register_input_subscribe_signal(g_conn, FALSE);
+ _bt_register_network_subscribe_signal(g_conn, FALSE);
+ _bt_register_audio_subscribe_signal(g_conn, FALSE);
break;
case BT_OPP_SERVER_EVENT:
- event_func = __bt_obexd_event_filter;
+ _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
break;
case BT_OPP_CLIENT_EVENT:
- event_func = __bt_opc_event_filter;
+ _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
break;
default:
BT_ERR("Unknown event");
return;
}
- ret_if(conn == NULL);
-
- dbus_connection_remove_filter(conn, event_func, NULL);
+ BT_DBG("-");
}
static int __bt_init_manager_receiver(void)
{
+ BT_DBG("+");
+
GError *error = NULL;
if (manager_conn == NULL) {
- manager_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (error != NULL) {
BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
- g_error_free(error);
+ g_clear_error(&error);
}
retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
}
if (_bt_register_service_event(manager_conn,
BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
goto fail;
-
if (_bt_register_service_event(manager_conn,
BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
goto fail;
BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
goto fail;
+ __bt_register_dump_subscribe_signal(manager_conn, TRUE);
return BLUETOOTH_ERROR_NONE;
fail:
if (manager_conn) {
- dbus_g_connection_unref(manager_conn);
+ g_object_unref(manager_conn);
manager_conn = NULL;
}
+ BT_DBG("-");
+
return BLUETOOTH_ERROR_INTERNAL;
}
static int __bt_init_obexd_receiver(void)
{
+ BT_DBG("+");
+#ifndef TIZEN_PROFILE_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
GError *error = NULL;
if (obexd_conn == NULL) {
- obexd_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
if (error != NULL) {
BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
- g_error_free(error);
+ g_clear_error(&error);
}
retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
}
if (_bt_register_service_event(obexd_conn,
BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
- dbus_g_connection_unref(obexd_conn);
+ BT_ERR("Error while registering service event");
+ g_object_unref(obexd_conn);
obexd_conn = NULL;
return BLUETOOTH_ERROR_INTERNAL;
}
+#endif
+ BT_DBG("-");
return BLUETOOTH_ERROR_NONE;
}
+gboolean __bt_reinit_obexd_receiver(gpointer user_data)
+{
+ static int retry_cnt = 0;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ BT_DBG("+");
+
+ result = __bt_init_obexd_receiver();
+ if (result != BLUETOOTH_ERROR_NONE) {
+ /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
+ then it is not the timing issue. Just can't use the session bus connection */
+ if (retry_cnt > 100) {
+ BT_ERR("Fail to init obexd receiver by 50 times.");
+ retry_cnt = 0;
+ session_reinit_timer = 0;
+ return FALSE;
+ }
+ retry_cnt++;
+ BT_DBG("Retry to initialize the obexd receiver");
+ return TRUE;
+ }
+
+ retry_cnt = 0;
+ session_reinit_timer = 0;
+
+ BT_DBG("-");
+
+ return FALSE;
+}
+
/* To receive the event from bluez */
int _bt_init_service_event_receiver(void)
{
+ BT_DBG("+");
+
int result;
result = __bt_init_manager_receiver();
retv_if(result != BLUETOOTH_ERROR_NONE, result);
result = __bt_init_obexd_receiver();
- if (result != BLUETOOTH_ERROR_NONE)
+ if (result != BLUETOOTH_ERROR_NONE) {
BT_ERR("Fail to init obexd receiver");
+ /* Try to re-initialize obexd receiver in the timer */
+ if (session_reinit_timer > 0)
+ g_source_remove(session_reinit_timer);
+
+ session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
+ (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
+ }
+
+ BT_DBG("-");
+
return BLUETOOTH_ERROR_NONE;
}
-void _bt_deinit_service_event_reciever(void)
+void _bt_deinit_service_event_receiver(void)
{
+ BT_DBG("+");
+
_bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
_bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
+ __bt_register_dump_subscribe_signal(manager_conn, FALSE);
+
if (manager_conn) {
- dbus_g_connection_unref(manager_conn);
+ g_object_unref(manager_conn);
manager_conn = NULL;
}
if (obexd_conn) {
- dbus_g_connection_unref(obexd_conn);
+ g_object_unref(obexd_conn);
obexd_conn = NULL;
}
if (event_id > 0)
g_source_remove(event_id);
-}
-
-int _bt_opp_client_event_init(void)
-{
- GError *error = NULL;
-
- if (opc_obexd_conn == NULL) {
- opc_obexd_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
- if (error != NULL) {
- BT_ERR("ERROR: Can't get on session bus [%s]",
- error->message);
- g_error_free(error);
- }
-
- retv_if(opc_obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- }
-
- if (_bt_register_service_event(opc_obexd_conn,
- BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
- dbus_g_connection_unref(opc_obexd_conn);
- opc_obexd_conn = NULL;
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ event_id = 0;
- return BLUETOOTH_ERROR_NONE;
-}
+ if (le_scan_event_id > 0)
+ g_source_remove(le_scan_event_id);
+ le_scan_event_id = 0;
-void _bt_opp_client_event_deinit(void)
-{
- if (opc_obexd_conn) {
- _bt_unregister_service_event(opc_obexd_conn,
- BT_OPP_CLIENT_EVENT);
- dbus_g_connection_unref(opc_obexd_conn);
- opc_obexd_conn = NULL;
- }
+ BT_DBG("-");
}
-void _bt_get_temp_remote_devinfo(void)
-{
- bt_remote_dev_info_t *dev_info;
- GList *node;
- int result = BLUETOOTH_ERROR_NONE;
-
- node = g_list_first(g_list);
-
- while (node != NULL) {
- dev_info = (bt_remote_dev_info_t *)node->data;
-
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &dev_info->address,
- DBUS_TYPE_UINT32, &dev_info->class,
- DBUS_TYPE_INT16, &dev_info->rssi,
- DBUS_TYPE_STRING, &dev_info->name,
- DBUS_TYPE_BOOLEAN, &dev_info->paired,
- DBUS_TYPE_BOOLEAN, &dev_info->connected,
- DBUS_TYPE_BOOLEAN, &dev_info->trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &dev_info->uuids, dev_info->uuid_count,
- DBUS_TYPE_INVALID);
-
- node = g_list_next(node);
- }
-}