/*
- * 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-bindings.h>
#include <unistd.h>
#include <vconf.h>
#include <vconf-keys.h>
#include "bt-common.h"
#include "bluetooth-telephony-api.h"
-#include "marshal.h"
+#include "bt-internal-types.h"
+
+#define BT_SCO_TIMEOUT 3000
+
+#define BT_CVSD_CODEC_ID 1
+#define BT_MSBC_CODEC_ID 2
typedef struct {
- DBusGConnection *conn;
- DBusGProxy *proxy;
- DBusGProxy *dbus_proxy;
- DBusGProxy *manager_proxy;
+ GDBusConnection *conn;
+ GDBusProxy *proxy;
+ GDBusProxy *dbus_proxy;
+ GDBusProxy *manager_proxy;
} telephony_dbus_info_t;
typedef struct {
void *user_data;
} bt_telephony_info_t;
+
+static char *src_addr = NULL;
+static guint owner_id = 0;
+
#define BLUETOOTH_TELEPHONY_ERROR (__bluetooth_telephony_error_quark())
#define BLUEZ_SERVICE_NAME "org.bluez"
#define BLUEZ_HEADSET_INTERFACE "org.bluez.Headset"
-#define BLUEZ_MANAGER_INTERFACE "org.bluez.Manager"
-#define BLUEZ_ADAPTER_INTERFACE "org.bluez.Adapter"
-#define BLUEZ_DEVICE_INTERFACE "org.bluez.Device"
-#define HFP_AGENT_SERVICE "org.bluez.hfp_agent"
+#define BLUEZ_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
+#define BLUEZ_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
+#define BLUEZ_ADAPTER_INTERFACE "org.bluez.Adapter1"
+#define BLUEZ_DEVICE_INTERFACE "org.bluez.Device1"
+#define HFP_AGENT_SERVICE "org.bluez.ag_agent"
+
+
#define HFP_AGENT_PATH "/org/bluez/hfp_agent"
#define HFP_AGENT_INTERFACE "Org.Hfp.App.Interface"
#define CSD_CALL_APP_PATH "/org/tizen/csd/%d"
#define HFP_NREC_STATUS_CHANGE "NrecStatusChanged"
+#define HFP_ANSWER_CALL "Answer"
+#define HFP_REJECT_CALL "Reject"
+#define HFP_RELEASE_CALL "Release"
+#define HFP_THREEWAY_CALL "Threeway"
+
+#define DEFAULT_ADAPTER_OBJECT_PATH "/org/bluez/hci0"
+
+/*Below Inrospection data is exposed to bluez from agent*/
+static const gchar bt_telephony_introspection_xml[] =
+"<node name='/'>"
+" <interface name='org.tizen.csd.Call.Instance'>"
+" <method name='SendDtmf'>"
+" <arg type='s' name='dtmf' direction='in'/>"
+" </method>"
+" <method name='VendorCmd'>"
+" <arg type='s' name='vendor' direction='in'/>"
+" </method>"
+" </interface>"
+"</node>";
#define BT_TELEPHONY_CHECK_ENABLED() \
do { \
- if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) \
- { \
+ if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) { \
BT_ERR("BT is not enabled"); \
return BLUETOOTH_TELEPHONY_ERROR_NOT_ENABLED; \
} \
static gboolean is_initialized = FALSE;
#define BT_TELEPHONY_CHECK_INITIALIZED() \
do { \
- if (is_initialized == FALSE) \
- { \
+ if (is_initialized == FALSE) { \
BT_ERR("Bluetooth telephony not initilized"); \
return BLUETOOTH_TELEPHONY_ERROR_NOT_INITIALIZED; \
} \
} while (0)
-#define BLUETOOTH_TELEPHONY_METHOD (bluetooth_telephony_method_get_type())
-#define BLUETOOTH_TELEPHONY_METHOD_GET_OBJECT(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST((obj), \
- BLUETOOTH_TELEPHONY_METHOD, BluetoothTelephonyMethod))
-
-#define BLUETOOTH_TELEPHONY_METHOD_IS_OBJECT(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
- BLUETOOTH_TELEPHONY_METHOD))
-
-#define BLUETOOTH_TELEPHONY_METHOD_CLASS(class) \
- (G_TYPE_CHECK_CLASS_CAST((class), \
- BLUETOOTH_TELEPHONY_METHOD, BluetoothTelephonyMethodClass))
-
-#define BLUETOOTH_TELEPHONY_METHOD_GET_AGENT_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS((obj), \
- BLUETOOTH_TELEPHONY_METHOD, BluetoothTelephonyMethodClass))
-
-#define BLUETOOTH_TELEPHONY_METHOD_IS_AGENT_CLASS(class) \
- (G_TYPE_CHECK_CLASS_TYPE((class), BLUETOOTH_TELEPHONY_METHOD))
-
-#define BLUETOOTH_TELEPHONY_METHOD_AGENT_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
- BLUETOOTH_TELEPHONY_METHOD, BluetoothTelephonyMethodPrivate))
-
-typedef struct _BluetoothTelephonyMethod BluetoothTelephonyMethod;
-typedef struct _BluetoothTelephonyMethodClass BluetoothTelephonyMethodClass;
-
-struct _BluetoothTelephonyMethod {
- GObject parent;
-};
-
-struct _BluetoothTelephonyMethodClass {
- GObjectClass parent_class;
-};
-
-BluetoothTelephonyMethod *bluetooth_telephony_method_new(void);
-GType bluetooth_telephony_method_get_type(void);
-
-G_DEFINE_TYPE(BluetoothTelephonyMethod, bluetooth_telephony_method, G_TYPE_OBJECT)
-
-
-static gboolean bluetooth_telephony_method_answer(BluetoothTelephonyMethod *object,
- guint callid,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_telephony_method_release(
- BluetoothTelephonyMethod *object, guint callid,
- DBusGMethodInvocation *context);
-
-static gboolean bluetooth_telephony_method_reject(BluetoothTelephonyMethod *object,
- guint callid, DBusGMethodInvocation *context);
-
-static gboolean bluetooth_telephony_method_threeway(
- BluetoothTelephonyMethod *object, guint value,
- DBusGMethodInvocation *context);
+static void __bt_telephony_adapter_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data);
-static gboolean bluetooth_telephony_method_send_dtmf(
- BluetoothTelephonyMethod *object,
- gchar *dtmf, DBusGMethodInvocation *context);
+static int __bt_telephony_get_src_addr(GVariant *value);
-#include "bt-telephony-glue.h"
-
-static GObject *object;
static bt_telephony_info_t telephony_info;
static telephony_dbus_info_t telephony_dbus_info;
static gboolean is_active = FALSE;
static int __bt_telephony_get_error(const char *error_message);
static void __bt_telephony_event_cb(int event, int result, void *param_data);
static GQuark __bluetooth_telephony_error_quark(void);
-static DBusMessage* __bluetooth_telephony_dbus_method_send(const char *path,
- const char *interface, const char *method, DBusError *err, int type, ...);
+static GVariant *__bluetooth_telephony_dbus_method_send(const char *path,
+ const char *interface, const char *method,
+ GError **err, GVariant *parameters);
static int __bluetooth_telephony_send_call_status(
bt_telephony_call_status_t call_status,
- unsigned int call_id);
-static GError *__bluetooth_telephony_error(bluetooth_telephony_error_t error,
- const char *err_msg);
-
-static DBusHandlerResult __bluetooth_telephony_event_filter(
- DBusConnection *conn,
- DBusMessage *msg, void *data);
-
-static void __bluetooth_telephony_adapter_added_cb(DBusGProxy *manager_proxy,
- const char *adapter_path, gpointer user_data);
-static int __bluetooth_telephony_proxy_init(void);
-static void __bluetooth_telephony_proxy_deinit(void);
+ unsigned int call_id, const char *ph_number);
+static void __bluetooth_telephony_error(GDBusMethodInvocation *invocation,
+ bluetooth_telephony_error_t error, const char *err_msg);
+
+static void __bluetooth_telephony_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);
+
static int __bluetooth_telephony_register(void);
static int __bluetooth_telephony_unregister(void);
-static int __bluetooth_get_default_adapter_path(DBusGConnection *GConn,
- char *path);
+
static gboolean __bluetooth_telephony_is_headset(uint32_t device_class);
static int __bluetooth_telephony_get_connected_device(void);
-static DBusGProxy *__bluetooth_telephony_get_connected_device_proxy(void);
+static GDBusProxy *__bluetooth_telephony_get_connected_device_proxy(void);
/*Function Definition*/
+static void __bt_telephony_method(GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ FN_START;
+
+ BT_INFO("method %s", method_name);
+ BT_INFO("object_path %s", object_path);
+
+ if (g_strcmp0(method_name, "SendDtmf") == 0) {
+ gchar *dtmf;
+ telephony_event_dtmf_t call_data = { 0, };
+
+ g_variant_get(parameters, "(&s)", &dtmf);
+
+ if (dtmf == NULL) {
+ BT_ERR("Number dial failed");
+ __bluetooth_telephony_error(invocation,
+ BLUETOOTH_TELEPHONY_ERROR_INVALID_DTMF,
+ "Invalid dtmf");
+ } else {
+ DBG_SECURE("Dtmf = %s", dtmf);
+
+ call_data.dtmf = g_strdup(dtmf);
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF,
+ BLUETOOTH_TELEPHONY_ERROR_NONE,
+ (void *)&call_data);
+
+ g_free(call_data.dtmf);
+
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ }
+ } else if (g_strcmp0(method_name, "VendorCmd") == 0) {
+ gchar *at_cmd;
+
+ g_variant_get(parameters, "(&s)", &at_cmd);
+ BT_INFO("Vendor %s", at_cmd);
+ if (at_cmd == NULL) {
+ BT_ERR("Vendor command is NULL\n");
+ __bluetooth_telephony_error(invocation,
+ BLUETOOTH_TELEPHONY_ERROR_APPLICATION,
+ "Invalid at vendor cmd");
+ } else {
+ DBG_SECURE("Vendor AT cmd = %s", at_cmd);
+
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_VENDOR_AT_CMD,
+ BLUETOOTH_TELEPHONY_ERROR_NONE,
+ at_cmd);
+
+ g_dbus_method_invocation_return_value(invocation, NULL);
+ }
+ }
+
+ BT_INFO("-");
+}
+
+static const GDBusInterfaceVTable method_table = {
+ __bt_telephony_method,
+ NULL,
+ NULL,
+};
+
static int __bt_telephony_get_error(const char *error_message)
{
if (error_message == NULL) {
- BT_DBG("Error message NULL\n");
+ BT_ERR("Error message NULL");
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- BT_DBG("Error message = %s \n", error_message);
+ BT_ERR("Error message = %s", error_message);
if (g_strcmp0(error_message, "NotAvailable") == 0)
return BLUETOOTH_TELEPHONY_ERROR_NOT_AVAILABLE;
else if (g_strcmp0(error_message, "NotConnected") == 0)
return BLUETOOTH_TELEPHONY_ERROR_NO_MEMORY;
else if (g_strcmp0(error_message, "I/O error") == 0)
return BLUETOOTH_TELEPHONY_ERROR_I_O_ERROR;
- else if (g_strcmp0(error_message, "Operation currently not available") == 0)
+ else if (g_strcmp0(error_message,
+ "Operation currently not available") == 0)
return BLUETOOTH_TELEPHONY_ERROR_OPERATION_NOT_AVAILABLE;
+ else if (g_strrstr(error_message, BT_ACCESS_DENIED_MSG))
+ return BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED;
else
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
+static int __bt_telephony_check_privilege(void)
+{
+ GVariant *reply;
+ GError *err = NULL;
+ int ret;
+
+ FN_START;
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "CheckPrivilege", &err, NULL);
+
+ if (!reply) {
+ BT_ERR("Error returned in method call");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
+ return ret;
+ }
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ }
+ g_variant_unref(reply);
+
+ FN_END;
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+}
+
static void __bt_telephony_event_cb(int event, int result, void *param_data)
{
telephony_event_param_t bt_event = { 0, };
return quark;
}
-static DBusMessage* __bluetooth_telephony_dbus_method_send(const char *path,
- const char *interface, const char *method, DBusError *err, int type, ...)
+static GVariant *__bluetooth_telephony_dbus_method_send(const char *path,
+ const char *interface, const char *method,
+ GError **err, GVariant *parameters)
{
- DBusMessage *msg;
- DBusMessage *reply;
- va_list args;
+ int timeout = -1;
- BT_DBG("+");
+ if (TIZEN_PROFILE_WEARABLE || TIZEN_PROFILE_IVI)
+ timeout = 4000;
- msg = dbus_message_new_method_call(HFP_AGENT_SERVICE,
- path, interface, method);
- if (!msg) {
- BT_ERR("Unable to allocate new D-Bus %s message \n", method);
- return NULL;
- }
+ GVariant *reply;
+ GDBusProxy *proxy;
+ GDBusConnection *conn;
+
+ FN_START;
- va_start(args, type);
+ conn = telephony_dbus_info.conn;
+ retv_if(conn == NULL, NULL);
- if (!dbus_message_append_args_valist(msg, type, args)) {
- dbus_message_unref(msg);
- va_end(args);
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL, HFP_AGENT_SERVICE, path, interface, NULL, err);
+ if (proxy == NULL) {
+ BT_ERR("Unable to allocate new proxy");
return NULL;
}
- va_end(args);
-
- dbus_error_init(err);
-
- reply = dbus_connection_send_with_reply_and_block(
- dbus_g_connection_get_connection(telephony_dbus_info.conn),
- msg, -1, err);
- dbus_message_unref(msg);
+ reply = g_dbus_proxy_call_sync(proxy, method, parameters,
+ G_DBUS_CALL_FLAGS_NONE, timeout, NULL, err);
- BT_DBG("-");
+ g_object_unref(proxy);
+ FN_END;
return reply;
}
static int __bluetooth_telephony_send_call_status(
bt_telephony_call_status_t call_status,
- unsigned int call_id)
+ unsigned int call_id, const char *ph_number)
{
- DBusMessage *reply;
- DBusError err;
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
char *path = g_strdup(telephony_info.call_path);
+ char *phone_number;
int ret;
- BT_DBG("+");
+ FN_START;
+
+ if (NULL == ph_number)
+ phone_number = g_strdup("");
+ else
+ phone_number = g_strdup(ph_number);
+ param = g_variant_new("(ssii)", path, phone_number,
+ call_status, call_id);
reply = __bluetooth_telephony_dbus_method_send(
HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
- "ChangeCallStatus", &err, DBUS_TYPE_STRING, &path,
- DBUS_TYPE_INT32, &call_status,
- DBUS_TYPE_INT32, &call_id, DBUS_TYPE_INVALID);
+ "ChangeCallStatus", &err, param);
+
g_free(path);
+ g_free(phone_number);
if (!reply) {
- BT_ERR("Error returned in method call\n");
- if (dbus_error_is_set(&err)) {
- ret = __bt_telephony_get_error(err.message);
- dbus_error_free(&err);
+ BT_ERR("Error returned in method call");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
return ret;
}
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- dbus_message_unref(reply);
+ g_variant_unref(reply);
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-static GError *__bluetooth_telephony_error(bluetooth_telephony_error_t error,
- const char *err_msg)
-{
- return g_error_new(BLUETOOTH_TELEPHONY_ERROR, error, err_msg, NULL);
-}
-
-static void bluetooth_telephony_method_init(BluetoothTelephonyMethod *object)
-{
- BT_DBG("+");
- BT_DBG("agent %p\n", object);
- BT_DBG("-");
-}
-
-static void __bluetooth_telephony_method_finalize(
- BluetoothTelephonyMethod *object)
-{
- BT_DBG("+");
- G_OBJECT_CLASS(bluetooth_telephony_method_parent_class)->finalize((
- GObject *)object);
- BT_DBG("-");
-}
-
-static BluetoothTelephonyMethod *__bluetooth_telephony_method_new(void)
-{
- BluetoothTelephonyMethod *obj;
-
- BT_DBG("+");
- obj = g_object_new(BLUETOOTH_TELEPHONY_METHOD, NULL);
- BT_DBG("-");
-
- return obj;
-}
-
-static void bluetooth_telephony_method_class_init(
- BluetoothTelephonyMethodClass *klass)
+static void __bluetooth_telephony_error(GDBusMethodInvocation *invocation,
+ bluetooth_telephony_error_t error, const char *err_msg)
{
- GObjectClass *object_class = NULL;
- BT_DBG("+");
-
- object_class = G_OBJECT_CLASS(klass);
- object_class->finalize = (void *)__bluetooth_telephony_method_finalize;
-
- /*Registration of the Framework methods */
- dbus_g_object_type_install_info(BLUETOOTH_TELEPHONY_METHOD,
- &dbus_glib_bluetooth_telephony_method_object_info);
- BT_DBG("-");
- return;
+ g_dbus_method_invocation_return_error(invocation,
+ BLUETOOTH_TELEPHONY_ERROR, error,
+ err_msg, NULL);
}
-static gboolean bluetooth_telephony_method_answer(
- BluetoothTelephonyMethod *object,
- guint callid, DBusGMethodInvocation *context)
+static void __bluetooth_telephony_answer_call(GVariant *var)
{
telephony_event_callid_t call_data = { 0, };
+ unsigned int callid;
- BT_DBG("+");
- BT_DBG("call_id = [%d]", callid);
+ FN_START;
+ g_variant_get(var, "(u)", &callid);
+ BT_DBG("call_id = [%d]", callid);
call_data.callid = callid;
__bt_telephony_event_cb(BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL,
BLUETOOTH_TELEPHONY_ERROR_NONE,
(void *)&call_data);
-
- dbus_g_method_return(context);
- BT_DBG("-");
- return TRUE;
+ FN_END;
}
-static gboolean bluetooth_telephony_method_release(
- BluetoothTelephonyMethod *object,
- guint callid, DBusGMethodInvocation *context)
+static void __bluetooth_telephony_release_call(GVariant *var)
{
telephony_event_callid_t call_data = { 0, };
+ unsigned int callid;
- BT_DBG("+");
- BT_DBG("call_id = [%d]\n", callid);
+ FN_START;
+ g_variant_get(var, "(u)", &callid);
+ BT_DBG("call_id = [%d]", callid);
call_data.callid = callid;
__bt_telephony_event_cb(BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL,
BLUETOOTH_TELEPHONY_ERROR_NONE,
(void *)&call_data);
-
- dbus_g_method_return(context);
- BT_DBG("-");
- return TRUE;
-
+ FN_END;
}
-static gboolean bluetooth_telephony_method_reject(
- BluetoothTelephonyMethod *object,
- guint callid, DBusGMethodInvocation *context)
+static void __bluetooth_telephony_reject_call(GVariant *var)
{
telephony_event_callid_t call_data = { 0, };
+ unsigned int callid;
- BT_DBG("+");
- BT_DBG("call_id = [%d]", callid);
+ FN_START;
+ g_variant_get(var, "(u)", &callid);
+ BT_DBG("call_id = [%d]", callid);
call_data.callid = callid;
__bt_telephony_event_cb(BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL,
BLUETOOTH_TELEPHONY_ERROR_NONE,
(void *)&call_data);
-
- dbus_g_method_return(context);
- BT_DBG("-");
- return TRUE;
+ FN_END;
}
-static gboolean bluetooth_telephony_method_threeway(
- BluetoothTelephonyMethod *object,
- guint value, DBusGMethodInvocation *context)
+static void __bluetooth_telephony_threeway_call(GVariant *var)
{
int event = 0;
- GError *err;
+ unsigned int chld_value;
- BT_DBG("+");
- BT_DBG("chld value = [%d]", value);
+ FN_START;
- switch (value) {
+ g_variant_get(var, "(u)", &chld_value);
+ BT_DBG("chld value = [%d]", chld_value);
+
+ switch (chld_value) {
case 0:
event = BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL;
break;
break;
default:
BT_ERR("Invalid CHLD command");
- err = __bluetooth_telephony_error(
- BLUETOOTH_TELEPHONY_ERROR_INVALID_CHLD_INDEX,
- "Invalid chld command");
- dbus_g_method_return_error(context, err);
- g_error_free(err);
- return FALSE;
+ return;
}
- BT_DBG("event = [%d]", event);
-
__bt_telephony_event_cb(event,
BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
- dbus_g_method_return(context);
- BT_DBG("-");
- return TRUE;
-}
-
-static gboolean bluetooth_telephony_method_send_dtmf(
- BluetoothTelephonyMethod *object,
- gchar *dtmf, DBusGMethodInvocation *context)
-{
- telephony_event_dtmf_t call_data = { 0, };
- GError *err;
-
- BT_DBG("+");
-
- if (dtmf == NULL) {
- BT_DBG("Number dial failed\n");
- err = __bluetooth_telephony_error(
- BLUETOOTH_TELEPHONY_ERROR_INVALID_DTMF,
- "Invalid dtmf");
- dbus_g_method_return_error(context, err);
- g_error_free(err);
- return FALSE;
- }
-
- BT_DBG("Dtmf = %s \n", dtmf);
-
- call_data.dtmf = g_strdup(dtmf);
-
- __bt_telephony_event_cb(BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF,
- BLUETOOTH_TELEPHONY_ERROR_NONE, (void *)&call_data);
-
- dbus_g_method_return(context);
- g_free(call_data.dtmf);
- BT_DBG("-");
- return TRUE;
+ FN_END;
}
-static void __bluetooth_handle_nrec_status_change(DBusMessage *msg)
+static void __bluetooth_handle_nrec_status_change(GVariant *var)
{
gboolean status = FALSE;
- if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_BOOLEAN, &status,
- DBUS_TYPE_INVALID)) {
- BT_DBG("Error Getting parameters\n");
- return;
- }
- BT_DBG("NREC status = %d\n", status);
+ g_variant_get(var, "(b)", &status);
+ BT_INFO("NREC status = %d", status);
__bt_telephony_event_cb(BLUETOOTH_EVENT_TELEPHONY_NREC_CHANGED,
BLUETOOTH_TELEPHONY_ERROR_NONE, (void *)&status);
}
-static DBusHandlerResult __bluetooth_telephony_event_filter(
- DBusConnection *conn,
- DBusMessage *msg, void *data)
+static void __bluetooth_telephony_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 *path = dbus_message_get_path(msg);
- char *dev_addr = NULL;
- DBusMessageIter item_iter;
- DBusMessageIter value_iter;
- const char *property;
-
- /* Check NREC status change Signal*/
- if (dbus_message_is_signal(msg, HFP_AGENT_SERVICE,
- HFP_NREC_STATUS_CHANGE)) {
- __bluetooth_handle_nrec_status_change(msg);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- if (!dbus_message_has_interface(msg, BLUEZ_HEADSET_INTERFACE))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- dbus_message_iter_init(msg, &item_iter);
- if (dbus_message_iter_get_arg_type(&item_iter) != DBUS_TYPE_STRING) {
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- dbus_message_iter_get_basic(&item_iter, &property);
+ BT_DBG("+");
- if (property == NULL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (strcasecmp(interface_name, BLUEZ_HEADSET_INTERFACE) == 0) {
+ if (strcasecmp(signal_name, "PropertyChanged") == 0) {
+ GVariant *values;
+ gchar *property;
- BT_DBG("Property (%s)\n", property);
+ g_variant_get(parameters, "(&sv)", &property, &values);
+ BT_DBG("Property: %s", property);
- if (g_strcmp0(property, "State") == 0) {
- char *state = NULL;
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &state);
- if (NULL == state) {
- BT_ERR("State is null\n");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- BT_DBG("State %s\n", state);
+ if (strcasecmp(property, "State") == 0) {
+ gchar *state;
+ state = (gchar *)g_variant_get_string(values, NULL);
- if (g_strcmp0(state, "connected") == 0) {
- telephony_info.headset_state = BLUETOOTH_STATE_CONNECTED;
- } else if (g_strcmp0(state, "playing") == 0) {
- telephony_info.headset_state = BLUETOOTH_STATE_PLAYING;
- } else if (g_strcmp0(state, "disconnected") == 0) {
- /* Headset state: playing -> disconnected */
- if (telephony_info.headset_state == BLUETOOTH_STATE_PLAYING) {
- if (!vconf_set_bool(VCONFKEY_BT_HEADSET_SCO, FALSE)) {
- BT_DBG("SVCONFKEY_BT_HEADSET_SCO - Set to FALSE\n");
- } else {
- BT_DBG("vconf_set_bool - Failed\n");
+ if (NULL == state) {
+ BT_ERR("State is null");
+ return;
}
+ BT_DBG("state: %s", state);
+ if (g_strcmp0(state, "connected") == 0) {
+ telephony_info.headset_state = BLUETOOTH_STATE_CONNECTED;
+ } else if (g_strcmp0(state, "playing") == 0) {
+ telephony_info.headset_state = BLUETOOTH_STATE_PLAYING;
+ } else if (g_strcmp0(state, "disconnected") == 0) {
+ /* Headset state: playing -> disconnected */
+ if (telephony_info.headset_state == BLUETOOTH_STATE_PLAYING) {
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED,
+ BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
+ }
+
+ telephony_info.headset_state = BLUETOOTH_STATE_DISCONNETED;
+ }
+ } else if (strcasecmp(property, "Connected") == 0) {
+ gboolean connected = FALSE;
+ char *dev_addr = NULL;
+ connected = g_variant_get_boolean(values);
+ BT_INFO("connected %d", connected);
+ if (connected) {
+ /*Get device address*/
+ if (object_path != NULL)
+ dev_addr = strstr(object_path, "dev_");
+
+ if (dev_addr != NULL) {
+ dev_addr += 4;
+ g_strlcpy(telephony_info.address,
+ dev_addr,
+ sizeof(telephony_info.address));
+ g_strdelimit(telephony_info.address, "_", ':');
+ BT_DBG("address is %s",
+ telephony_info.address);
+
+ telephony_info.headset_state =
+ BLUETOOTH_STATE_CONNECTED;
+
+ if (telephony_dbus_info.proxy != NULL) {
+ g_object_unref(telephony_dbus_info.proxy);
+ telephony_dbus_info.proxy = NULL;
+ }
+
+ telephony_dbus_info.proxy =
+ __bluetooth_telephony_get_connected_device_proxy();
+
+ BT_INFO("Headset Connected");
+
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_HFP_CONNECTED,
+ BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
+ }
+ } else { /*Device disconnected*/
+ memset(telephony_info.address, 0x00,
+ sizeof(telephony_info.address));
+ telephony_info.headset_state =
+ BLUETOOTH_STATE_DISCONNETED;
- __bt_telephony_event_cb(
- BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED,
- BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
- }
-
- telephony_info.headset_state = BLUETOOTH_STATE_DISCONNETED;
- }
+ if (telephony_dbus_info.proxy != NULL) {
+ g_object_unref(telephony_dbus_info.proxy);
+ telephony_dbus_info.proxy = NULL;
+ }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ BT_INFO("Headset Disconnected");
- if (g_strcmp0(property, "Connected") == 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);
- BT_DBG("Connected %d\n", connected);
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_HFP_DISCONNECTED,
+ BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
+ }
+ } else if (strcasecmp(property, "SpeakerGain") == 0) {
+ unsigned int spkr_gain;
+ guint16 gain = g_variant_get_uint16(values);
- if (connected) {
- /*Get device address*/
- if (path != NULL)
- dev_addr = strstr(path, "dev_");
+ spkr_gain = (unsigned int)gain;
+ BT_DBG("spk_gain[%d]", spkr_gain);
- if (dev_addr != NULL) {
- dev_addr += 4;
- g_strlcpy(telephony_info.address,
- dev_addr,
- sizeof(telephony_info.address));
- g_strdelimit(telephony_info.address, "_", ':');
- BT_DBG("address is %s",
- telephony_info.address);
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_SET_SPEAKER_GAIN,
+ BLUETOOTH_TELEPHONY_ERROR_NONE,
+ (void *)&spkr_gain);
+ } else if (strcasecmp(property, "MicrophoneGain") == 0) {
+ unsigned int mic_gain;
+ guint16 gain = g_variant_get_uint16(values);
- telephony_info.headset_state =
- BLUETOOTH_STATE_CONNECTED;
+ mic_gain = (unsigned int)gain;
+ BT_DBG("mic_gain[%d]", mic_gain);
- if (telephony_dbus_info.proxy != NULL) {
- g_object_unref(telephony_dbus_info.proxy);
- telephony_dbus_info.proxy = NULL;
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_SET_MIC_GAIN,
+ BLUETOOTH_TELEPHONY_ERROR_NONE,
+ (void *)&mic_gain);
+ } else if (strcasecmp(property, "Playing") == 0) {
+ gboolean audio_sink_playing;
+
+ audio_sink_playing = g_variant_get_boolean(values);
+ if (audio_sink_playing) {
+ telephony_info.headset_state = BLUETOOTH_STATE_PLAYING;
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_AUDIO_CONNECTED,
+ BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
+ } else {
+ telephony_info.headset_state =
+ BLUETOOTH_STATE_CONNECTED;
+ __bt_telephony_event_cb(
+ BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED,
+ BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
}
-
- telephony_dbus_info.proxy =
- __bluetooth_telephony_get_connected_device_proxy();
-
- BT_DBG("Headset Connected");
-
- __bt_telephony_event_cb(
- BLUETOOTH_EVENT_TELEPHONY_HFP_CONNECTED,
- BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
}
- } else { /*Device disconnected*/
- memset(telephony_info.address, 0x00,
- sizeof(telephony_info.address));
- telephony_info.headset_state =
- BLUETOOTH_STATE_DISCONNETED;
-
- if (telephony_dbus_info.proxy != NULL) {
- g_object_unref(telephony_dbus_info.proxy);
- telephony_dbus_info.proxy = NULL;
- }
-
- BT_DBG("Headset Disconnected");
- __bt_telephony_event_cb(
- BLUETOOTH_EVENT_TELEPHONY_HFP_DISCONNECTED,
- BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ g_variant_unref(values);
+ } else if (strcasecmp(signal_name, HFP_NREC_STATUS_CHANGE) == 0)
+ __bluetooth_handle_nrec_status_change(parameters);
+ else if (strcasecmp(signal_name, HFP_ANSWER_CALL) == 0)
+ __bluetooth_telephony_answer_call(parameters);
+ else if (strcasecmp(signal_name, HFP_REJECT_CALL) == 0)
+ __bluetooth_telephony_reject_call(parameters);
+ else if (strcasecmp(signal_name, HFP_RELEASE_CALL) == 0)
+ __bluetooth_telephony_release_call(parameters);
+ else if (strcasecmp(signal_name, HFP_THREEWAY_CALL) == 0)
+ __bluetooth_telephony_threeway_call(parameters);
}
+ BT_DBG("-");
+}
- if (g_strcmp0(property, "SpeakerGain") == 0) {
- unsigned int spkr_gain;
- guint16 gain;
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &gain);
+static GDBusNodeInfo *__bt_telephony_create_method_node_info
+ (const gchar *introspection_data)
+{
+ GError *err = NULL;
+ GDBusNodeInfo *node_info = NULL;
- spkr_gain = (unsigned int)gain;
- BT_DBG("spk_gain[%d]\n", spkr_gain);
+ if (introspection_data == NULL)
+ return NULL;
- __bt_telephony_event_cb(
- BLUETOOTH_EVENT_TELEPHONY_SET_SPEAKER_GAIN,
- BLUETOOTH_TELEPHONY_ERROR_NONE,
- (void *)&spkr_gain);
+ node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (err) {
+ BT_ERR("Unable to create node: %s", err->message);
+ g_clear_error(&err);
}
+ return node_info;
+}
- if (g_strcmp0(property, "MicrophoneGain") == 0) {
- unsigned int mic_gain;
- guint16 gain;
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &gain);
- mic_gain = (unsigned int)gain;
- BT_DBG("mic_gain[%d]\n", mic_gain);
+int __bluetooth_telephony_register_object(int reg, GDBusNodeInfo *node_info)
+{
+ static guint bt_tel_id = 0;
+ GError *error = NULL;
+ gchar *path;
- __bt_telephony_event_cb(
- BLUETOOTH_EVENT_TELEPHONY_SET_MIC_GAIN,
- BLUETOOTH_TELEPHONY_ERROR_NONE,
- (void *)&mic_gain);
+ if (reg == TRUE) {
+ if (node_info == NULL)
+ return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ path = g_strdup(telephony_info.call_path);
+ BT_DBG("path is [%s]", path);
- if (g_strcmp0(property, "Playing") == 0) {
- gboolean audio_sink_playing = FALSE;
- dbus_message_iter_next(&item_iter);
- dbus_message_iter_recurse(&item_iter, &value_iter);
- dbus_message_iter_get_basic(&value_iter, &audio_sink_playing);
+ bt_tel_id = g_dbus_connection_register_object(telephony_dbus_info.conn,
+ path, node_info->interfaces[0],
+ &method_table,
+ NULL, NULL, &error);
- if (audio_sink_playing) {
- if (!vconf_set_bool(VCONFKEY_BT_HEADSET_SCO, TRUE)) {
- BT_DBG("SVCONFKEY_BT_HEADSET_SCO -"
- "Set to TRUE\n");
- } else {
- BT_DBG("vconf_set_bool - Failed\n");
- }
- telephony_info.headset_state = BLUETOOTH_STATE_PLAYING;
- __bt_telephony_event_cb(
- BLUETOOTH_EVENT_TELEPHONY_AUDIO_CONNECTED,
- BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
- } else {
- if (!vconf_set_bool(VCONFKEY_BT_HEADSET_SCO, FALSE)) {
- BT_DBG("SVCONFKEY_BT_HEADSET_SCO -"
- "Set to FALSE\n");
- } else {
- BT_DBG("vconf_set_bool - Failed\n");
- }
- telephony_info.headset_state =
- BLUETOOTH_STATE_CONNECTED;
- __bt_telephony_event_cb(
- BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED,
- BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
+ g_free(path);
+ if (bt_tel_id == 0) {
+ BT_ERR("Failed to register: %s", error->message);
+ g_error_free(error);
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static void __bluetooth_telephony_adapter_added_cb(DBusGProxy *manager_proxy,
- const char *adapter_path, gpointer user_data)
-{
- int ret;
-
- BT_DBG("Adapter added [%s] \n", adapter_path);
-
- if (strstr(adapter_path, "hci0")) {
- BT_DBG("BlueZ is Activated and flag need to be reset");
- BT_DBG("Send enabled to application\n");
-
- ret = __bluetooth_telephony_register();
- if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
- BT_DBG("__bluetooth_telephony_register failed\n");
- return;
+ } else {
+ if (bt_tel_id > 0) {
+ g_dbus_connection_unregister_object(telephony_dbus_info.conn,
+ bt_tel_id);
+ bt_tel_id = 0;
}
}
+
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
static int __bluetooth_telephony_proxy_init(void)
{
- BT_DBG("+");
-
- object = (GObject *)__bluetooth_telephony_method_new();
-
- if (NULL == object)
+ FN_START;
+ GDBusNodeInfo *node_info;
+ gchar *name;
+
+ name = g_strdup_printf("org.tizen.csd.Call.Instance.p%d", getpid());
+ BT_DBG("well-known name: %s", name);
+
+ owner_id = g_bus_own_name_on_connection(telephony_dbus_info.conn,
+ name, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL);
+ BT_DBG("owner_id: %d", owner_id);
+ g_free(name);
+
+ node_info = __bt_telephony_create_method_node_info(
+ bt_telephony_introspection_xml);
+ if (node_info == NULL) {
+ BT_ERR("node_info NULL");
+ return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
+ }
+ if (__bluetooth_telephony_register_object(TRUE, node_info) !=
+ BLUETOOTH_TELEPHONY_ERROR_NONE) {
+ BT_ERR("Registation of Method Failed");
+ g_dbus_node_info_unref(node_info);
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ }
- BT_DBG("telephony_object = %x", object);
-
- dbus_g_connection_register_g_object(telephony_dbus_info.conn,
- telephony_info.call_path, G_OBJECT(object));
-
- BT_DBG("-");
+ FN_END;
+ g_dbus_node_info_unref(node_info);
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
static void __bluetooth_telephony_proxy_deinit(void)
{
- BT_DBG("+");
-
- dbus_g_connection_unregister_g_object(telephony_dbus_info.conn,
- G_OBJECT(object));
+ FN_START;
- g_object_unref(object);
- object = NULL;
+ __bluetooth_telephony_register_object(FALSE, NULL);
+ g_bus_unown_name(owner_id);
- BT_DBG("-");
- return;
+ FN_END;
}
static int __bluetooth_telephony_register(void)
{
- DBusMessage *reply;
- DBusError err;
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
char *path = g_strdup(telephony_info.call_path);
int ret;
- BT_DBG("+");
+ FN_START;
+
+ param = g_variant_new("(ss)", path, src_addr);
+ BT_DBG("Path[%s] Src_Address[%s]", path, src_addr);
reply = __bluetooth_telephony_dbus_method_send(
HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
- "RegisterApplication", &err, DBUS_TYPE_STRING, &path,
- DBUS_TYPE_INVALID);
+ "RegisterApplication", &err, param);
g_free(path);
+
if (!reply) {
- BT_ERR("Error returned in method call\n");
- if (dbus_error_is_set(&err)) {
- ret = __bt_telephony_get_error(err.message);
- dbus_error_free(&err);
+ BT_ERR("Error returned in method call");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(err);
return ret;
}
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- dbus_message_unref(reply);
- BT_DBG("-");
+ g_variant_unref(reply);
+ BT_DBG("__bluetooth_telephony_register completed");
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
static int __bluetooth_telephony_unregister(void)
{
- DBusMessage *reply;
- DBusError err;
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
char *path = g_strdup(telephony_info.call_path);
int ret;
- BT_DBG("+");
+ FN_START;
+ param = g_variant_new("(s)", path);
reply = __bluetooth_telephony_dbus_method_send(
HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
- "UnregisterApplication", &err, DBUS_TYPE_STRING, &path,
- DBUS_TYPE_INVALID);
+ "UnregisterApplication", &err, param);
g_free(path);
+
if (!reply) {
- BT_ERR("Error returned in method call\n");
- if (dbus_error_is_set(&err)) {
- ret = __bt_telephony_get_error(err.message);
- dbus_error_free(&err);
+ BT_ERR("Error returned in method call");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
return ret;
}
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- dbus_message_unref(reply);
- BT_DBG("+");
+ g_variant_unref(reply);
+ BT_DBG("__bluetooth_telephony_unregister completed");
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-static int __bluetooth_get_default_adapter_path(DBusGConnection *GConn,
- char *path)
+static void __bluetooth_telephony_init_headset_state(void)
{
+ GVariant *reply;
GError *err = NULL;
- char *adapter_path = NULL;
+ gboolean status = FALSE;
- BT_DBG("+");
+ FN_START;
+
+ if (telephony_dbus_info.conn == NULL) {
+ BT_ERR("Bluetooth telephony not initilized");
+ return;
+ }
- if (!dbus_g_proxy_call(telephony_dbus_info.manager_proxy,
- "DefaultAdapter", &err, G_TYPE_INVALID,
- DBUS_TYPE_G_OBJECT_PATH, &adapter_path,
- G_TYPE_INVALID)) {
- if (err != NULL) {
- BT_ERR("Getting DefaultAdapter failed: [%s]",
- err->message);
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "IsConnected", &err, NULL);
+ if (!reply) {
+ BT_ERR("Error returned in method call\n");
+ if (err) {
+ BT_ERR("Error message = %s", err->message);
g_error_free(err);
}
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ return;
}
- if (adapter_path == NULL) {
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- }
+ g_variant_get(reply, "(b)", &status);
+ g_variant_unref(reply);
- if (strlen(adapter_path) >= BT_ADAPTER_PATH_LEN) {
- BT_ERR("Path too long.\n");
- g_free(adapter_path);
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- }
+ BT_INFO("Headset Connected Status = [%d]", status);
+ if (status)
+ telephony_info.headset_state = BLUETOOTH_STATE_CONNECTED;
+ else
+ return;
- BT_DBG("path = %s", adapter_path);
- g_strlcpy(path, adapter_path, BT_ADAPTER_PATH_LEN);
- g_free(adapter_path);
- BT_DBG("-");
- return BLUETOOTH_TELEPHONY_ERROR_NONE;
+ if (bluetooth_telephony_is_sco_connected())
+ telephony_info.headset_state = BLUETOOTH_STATE_PLAYING;
+
+ FN_END;
}
static gboolean __bluetooth_telephony_is_headset(uint32_t device_class)
{
gboolean flag = FALSE;
- BT_DBG("+");
+ FN_START;
switch ((device_class & 0x1f00) >> 8) {
case 0x04:
break;
}
break;
- }
- BT_DBG("-");
- return flag;
-}
-static int __bluetooth_telephony_get_connected_device(void)
-{
- DBusGProxy *list_proxy = NULL;
- DBusGProxy *device_proxy = NULL;
- GPtrArray *gp_array = NULL;
- GError *error = NULL;
- gchar *gp_path = NULL;
- GHashTable *list_hash;
- GHashTable *device_hash;
- GValue *value = {0};
- uint32_t device_class;
- gboolean playing = FALSE;
- gboolean connected = FALSE;
- const gchar *address;
- char object_path[BT_ADAPTER_PATH_LEN] = {0};
- int i = 0;
- DBusGProxy *proxy = NULL;
+ /* Tizen Wearable device */
+ case 0x07:
+ switch ((device_class & 0xfc) >> 2) {
+ case 0x01: /* Wrist Watch */
+ flag = TRUE;
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ BT_DBG("[%d]", flag);
+ FN_END;
+ return flag;
+}
- BT_DBG("+");
+static gboolean __bluetooth_telephony_is_headset_by_uuid(gchar **uuids)
+{
+ int i;
+ char **parts;
+ unsigned int service = 0;
- /*Get default adapter path*/
- if (__bluetooth_get_default_adapter_path(telephony_dbus_info.conn,
- object_path) < 0)
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- /*Get List of All devices*/
- list_proxy = dbus_g_proxy_new_for_name(telephony_dbus_info.conn,
- BLUEZ_SERVICE_NAME, object_path,
- BLUEZ_ADAPTER_INTERFACE);
+ FN_START;
- if (list_proxy == NULL)
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ retv_if(uuids == NULL, FALSE);
- dbus_g_proxy_call(list_proxy, "ListDevices", &error, G_TYPE_INVALID,
- dbus_g_type_get_collection("GPtrArray",
- DBUS_TYPE_G_OBJECT_PATH),
- &gp_array, G_TYPE_INVALID);
+ for (i = 0; uuids[i] != NULL; i++) {
+ parts = g_strsplit(uuids[i], "-", -1);
- if (error != NULL) {
- g_error_free(error);
- goto done;
+ if (parts == NULL || parts[0] == NULL) {
+ g_strfreev(parts);
+ continue;
+ }
+
+ service = g_ascii_strtoull(parts[0], NULL, 16);
+ g_strfreev(parts);
+
+ if (service == BLUETOOTH_HS_PROFILE_UUID ||
+ service == BLUETOOTH_HF_PROFILE_UUID)
+ return TRUE;
}
- if (gp_array == NULL)
- goto done;
+ FN_END;
+ return FALSE;
+}
- /*Check for headset devices*/
- for (i = 0; i < gp_array->len; i++) {
- list_hash = NULL;
- device_hash = NULL;
- gp_path = g_ptr_array_index(gp_array, i);
- if (gp_path == NULL)
- goto done;
+static int __bluetooth_telephony_get_connected_device(void)
+{
+ GDBusConnection *conn;
+ GDBusProxy *headset_agent_proxy = NULL;
+ GDBusProxy *manager_proxy = NULL;
+ GDBusProxy *proxy = NULL;
+ GVariant *reply = NULL;
+ GVariant *getall = NULL;
+ GVariant *isPlayingReply = NULL;
+ GVariant *isConnectedReply = NULL;
+ GVariant *param = NULL;
+ GVariant *var_path = NULL;
+ GVariant *path_values = NULL;
+ GVariant *value = NULL;
+ GError *error = NULL;
+ GVariantIter iter;
+ GVariantIter iter_path;
+ GVariantIter property_iter;
+ int ret = BLUETOOTH_TELEPHONY_ERROR_NONE;
+
+ FN_START;
+ conn = _bt_get_system_private_conn();
+ retv_if(conn == NULL, BLUETOOTH_TELEPHONY_ERROR_INTERNAL);
- proxy = dbus_g_proxy_new_for_name(telephony_dbus_info.conn,
- BLUEZ_SERVICE_NAME, gp_path,
- BLUEZ_DEVICE_INTERFACE);
+ manager_proxy = g_dbus_proxy_new_sync(
+ conn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ BLUEZ_SERVICE_NAME, "/",
+ BLUEZ_MANAGER_INTERFACE, NULL, &error);
+ if (manager_proxy == NULL) {
+ BT_ERR("Unable to allocate new proxy \n");
+ ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
+ goto done;
+ }
- if (proxy == NULL)
- goto done;
+ /* Synchronous call */
+ reply = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ g_object_unref(manager_proxy);
- dbus_g_proxy_call(proxy, "GetProperties", NULL,
- G_TYPE_INVALID, dbus_g_type_get_map(
- "GHashTable", G_TYPE_STRING,
- G_TYPE_VALUE), &list_hash, G_TYPE_INVALID);
+ if (!reply) {
+ BT_ERR("Can't get managed objects");
+ ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
+ goto done;
+ }
- if (list_hash == NULL)
- goto done;
+ /* signature of GetManagedObjects: a{oa{sa{sv}}} */
+ g_variant_iter_init(&iter, reply);
+
+ while ((param = g_variant_iter_next_value(&iter))) {
+ g_variant_iter_init(&iter_path, param);
+
+ while ((var_path = g_variant_iter_next_value(&iter_path))) {
+ gsize len;
+ uint32_t device_class = 0;
+ gboolean playing = FALSE;
+ gboolean connected = FALSE;
+ char *object_path = NULL;
+ gchar *address = NULL;
+ const gchar *key;
+ gchar **uuids = NULL;
+ GVariant *getall_param = NULL;
+
+ g_variant_get(var_path, "{&o*}", &object_path,
+ &path_values);
+ g_variant_unref(path_values); /* path_values unused*/
+
+ proxy = g_dbus_proxy_new_sync(telephony_dbus_info.conn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ BLUEZ_SERVICE_NAME, object_path,
+ BLUEZ_PROPERTIES_INTERFACE, NULL, &error);
+ if (proxy == NULL) {
+ BT_ERR("Unable to allocate new proxy \n");
+ ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
+ goto done;
+ }
- value = g_hash_table_lookup(list_hash, "Class");
- device_class = value ? g_value_get_uint(value) : 0;
- if (!__bluetooth_telephony_is_headset(device_class)) {
+ getall_param = g_variant_new("s", BLUEZ_DEVICE_INTERFACE);
+ getall = g_dbus_proxy_call_sync(proxy,
+ "GetAll", getall_param,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
g_object_unref(proxy);
- proxy = NULL;
- g_free(gp_path);
- gp_path = NULL;
- g_hash_table_destroy(list_hash);
- continue;
- }
- /*Check for Connection*/
- device_proxy = dbus_g_proxy_new_for_name(
- telephony_dbus_info.conn,
- BLUEZ_SERVICE_NAME, gp_path,
- BLUEZ_HEADSET_INTERFACE);
+ if (!getall) {
+ BT_ERR("Can't get managed objects");
+ ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
+ goto done;
+ }
- if (device_proxy == NULL) {
- g_hash_table_destroy(list_hash);
- goto done;
- }
+ g_variant_iter_init(&property_iter, getall);
+
+ while (g_variant_iter_loop(&property_iter, "{&sv}", &key, &value)) {
+ if (!g_strcmp0(key, "Class")) {
+ device_class = g_variant_get_uint32(value);
+ BT_DBG("Device Class: %d", device_class);
+ } else if (!g_strcmp0(key, "UUID")) {
+ int i = 0;
+ uuids = (gchar **)g_variant_get_strv(value, &len);
+ BT_DBG_UUID(uuids, len, i);
+ } else if (!g_strcmp0(key, "Address")) {
+ address = (gchar *)g_variant_get_string(
+ value,
+ NULL);
+ BT_DBG("Device Class: %s", address);
+ }
+ g_variant_unref(value);
+ }
+ g_variant_unref(getall);
- dbus_g_proxy_call(device_proxy, "GetProperties",
- &error, G_TYPE_INVALID,
- dbus_g_type_get_map("GHashTable",
- G_TYPE_STRING, G_TYPE_VALUE),
- &device_hash, G_TYPE_INVALID);
-
- if (error == NULL) {
- value = g_hash_table_lookup(device_hash,
- "Connected");
- connected = value ? g_value_get_boolean(
- value) : FALSE;
- if (connected) {
- value = g_hash_table_lookup(list_hash,
- "Address");
- address = value ? g_value_get_string(
- value) : NULL;
- g_strlcpy(telephony_info.address, address,
- sizeof(telephony_info.address));
- value = g_hash_table_lookup(device_hash,
- "Playing");
- playing = value ? g_value_get_boolean(
- value) : FALSE;
- if (playing)
- telephony_info.headset_state =
- BLUETOOTH_STATE_PLAYING;
- else
- telephony_info.headset_state =
- BLUETOOTH_STATE_CONNECTED;
+ if (device_class == 0) {
+ BT_DBG("COD is NULL (maybe paired by nfc)... Checking UUIDs");
+ if (!__bluetooth_telephony_is_headset_by_uuid(uuids)) {
+ BT_DBG("UUID checking completed. None HF device");
+ continue;
+ }
+ BT_DBG("UUID checking completed. HF device");
+ } else {
+ if (!__bluetooth_telephony_is_headset(device_class))
+ continue;
+ }
- g_hash_table_destroy(device_hash);
- g_hash_table_destroy(list_hash);
+ /* this is headset; Check for Connection */
+ headset_agent_proxy = g_dbus_proxy_new_sync(telephony_dbus_info.conn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ HFP_AGENT_SERVICE, object_path,
+ HFP_AGENT_INTERFACE, NULL, &error);
+ if (headset_agent_proxy == NULL) {
+ BT_ERR("Unable to allocate new headset_agent_proxy");
+ ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
goto done;
}
- g_hash_table_destroy(device_hash);
- } else {
- g_error_free(error);
- }
- g_hash_table_destroy(list_hash);
- g_object_unref(proxy);
- proxy = NULL;
- g_free(gp_path);
- gp_path = NULL;
+ isConnectedReply = g_dbus_proxy_call_sync(headset_agent_proxy,
+ "IsConnected", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+
+ if (!isConnectedReply) {
+ BT_ERR("Can't get managed objects");
+ ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
+ goto done;
+ } else {
+ connected = g_variant_get_boolean(isConnectedReply);
+ g_variant_unref(isConnectedReply);
+
+ if (connected) {
+ g_strlcpy(telephony_info.address,
+ address,
+ sizeof(telephony_info.address));
+
+ isPlayingReply = g_dbus_proxy_call_sync(headset_agent_proxy,
+ "IsPlaying", NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (!isPlayingReply) {
+ BT_ERR("Can't get managed objects");
+ ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
+ } else {
+ playing = g_variant_get_boolean(isPlayingReply);
+ g_variant_unref(isPlayingReply);
+
+ if (playing)
+ telephony_info.headset_state =
+ BLUETOOTH_STATE_PLAYING;
+ else
+ telephony_info.headset_state =
+ BLUETOOTH_STATE_CONNECTED;
+ }
+
+ goto done;
+ }
+ }
+
+ g_object_unref(headset_agent_proxy);
+ g_variant_unref(var_path);
+ }
+ g_variant_unref(param);
}
+
done:
- if (list_proxy)
- g_object_unref(list_proxy);
- if (device_proxy)
- g_object_unref(device_proxy);
- if (proxy)
- g_object_unref(proxy);
- g_free(gp_path);
- g_ptr_array_free(gp_array, TRUE);
- BT_DBG("-");
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (headset_agent_proxy)
+ g_object_unref(headset_agent_proxy);
+ if (reply)
+ g_variant_unref(reply);
+ if (var_path)
+ g_variant_unref(var_path);
+ if (param)
+ g_variant_unref(param);
+ FN_END;
+ return ret;
}
-static DBusGProxy *__bluetooth_telephony_get_connected_device_proxy(void)
+static GDBusProxy *__bluetooth_telephony_get_connected_device_proxy(void)
{
- DBusGProxy *proxy = NULL;
- char object_path[BT_ADAPTER_PATH_LEN] = {0};
+ GDBusProxy *proxy = NULL;
GError *error = NULL;
- DBusGProxy *default_proxy;
-
- BT_DBG("+");
-
- /*Get default adapter path*/
- if (__bluetooth_get_default_adapter_path(telephony_dbus_info.conn,
- object_path) < 0)
- return NULL;
-
- /*Get List of All devices*/
- default_proxy = dbus_g_proxy_new_for_name(telephony_dbus_info.conn,
- BLUEZ_SERVICE_NAME, object_path,
- BLUEZ_ADAPTER_INTERFACE);
-
- if (default_proxy == NULL)
- return NULL;
+ int ret;
+ FN_START;
if (strlen(telephony_info.address) == 0)
__bluetooth_telephony_get_connected_device();
- if (strlen(telephony_info.address) == 0) {
- g_object_unref(default_proxy);
- return NULL;
- }
-
- if (telephony_info.obj_path) {
- g_free(telephony_info.obj_path);
- telephony_info.obj_path = NULL;
- }
-
- dbus_g_proxy_call(default_proxy, "FindDevice", &error,
- G_TYPE_STRING, telephony_info.address,
- G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH,
- &telephony_info.obj_path,
- G_TYPE_INVALID);
- if (error != NULL) {
- BT_ERR("dbus_g_proxy_call Failed!\n");
- g_error_free(error);
- g_object_unref(default_proxy);
+ if (strlen(telephony_info.address) == 0)
return NULL;
- }
- if (telephony_info.obj_path == NULL) {
- g_object_unref(default_proxy);
+ proxy = g_dbus_proxy_new_sync(telephony_dbus_info.conn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ HFP_AGENT_SERVICE, HFP_AGENT_PATH,
+ HFP_AGENT_INTERFACE, NULL, &error);
+ if (proxy == NULL) {
+ BT_ERR("Unable to allocate new proxy");
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
return NULL;
}
- proxy = dbus_g_proxy_new_for_name(telephony_dbus_info.conn,
- BLUEZ_SERVICE_NAME, telephony_info.obj_path,
- BLUEZ_HEADSET_INTERFACE);
+ FN_END;
+ return proxy;
+}
- g_object_unref(default_proxy);
+int __bt_telephony_subscribe_adapter_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
+
+ static guint subscribe_adapter_id = 0;
+
+ if (subscribe == TRUE) {
+ if (subscribe_adapter_id == 0) {
+ subscribe_adapter_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, "org.freedesktop.DBus.ObjectManager",
+ "InterfacesAdded", NULL, NULL, 0,
+ __bt_telephony_adapter_filter,
+ NULL, NULL);
+ }
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+ } else {
+ if (subscribe_adapter_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ subscribe_adapter_id);
+ subscribe_adapter_id = 0;
+ }
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+ }
+}
- return proxy;
+int __bt_telephony_event_subscribe_signal(GDBusConnection *conn,
+ int subscribe)
+{
+ if (conn == NULL)
+ return -1;
+
+ static guint event_id = 0;
+
+ if (subscribe == TRUE) {
+ if (event_id == 0) {
+ event_id = g_dbus_connection_signal_subscribe(conn,
+ NULL, BLUEZ_HEADSET_INTERFACE,
+ NULL, NULL, NULL, 0,
+ __bluetooth_telephony_event_filter,
+ NULL, NULL);
+ }
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+ } else {
+ if (event_id > 0) {
+ g_dbus_connection_signal_unsubscribe(conn,
+ event_id);
+ event_id = 0;
+ }
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+ }
}
BT_EXPORT_API int bluetooth_telephony_init(bt_telephony_func_ptr cb,
void *user_data)
{
- DBusError dbus_error;
- DBusConnection *conn;
+ bluetooth_device_address_t loc_address = { {0} };
+ char src_address[BT_ADDRESS_STRING_SIZE] = { 0 };
int ret = BLUETOOTH_TELEPHONY_ERROR_NONE;
GError *error = NULL;
- char object_path[BT_ADAPTER_PATH_LEN] = {0};
- BT_DBG("+");
- g_type_init();
+ FN_START;
if (is_initialized == TRUE) {
BT_ERR("Bluetooth telephony already initilized");
- return BLUETOOTH_TELEPHONY_ERROR_ALREADY_INITIALIZED;
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
is_initialized = TRUE;
- telephony_dbus_info.conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ /* As a result of discussion with system team, private connection is not
+ * suitable in here. It is better to use shared connection. */
+ //telephony_dbus_info.conn = _bt_gdbus_init_system_gconn();
+ telephony_dbus_info.conn = _bt_get_system_shared_conn();
if (!telephony_dbus_info.conn) {
- if (NULL != error) {
- BT_ERR("dbus_g_bus_get() failed:[%d:%s]\n",
- error->code, error->message);
- g_error_free(error);
- }
is_initialized = FALSE;
+ BT_ERR("Could not get DBus Connection");
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
/* Call Path */
snprintf(telephony_info.call_path, sizeof(telephony_info.call_path),
CSD_CALL_APP_PATH, getpid());
- BT_DBG("Call Path = %s", telephony_info.call_path);
+ BT_INFO("Call Path = %s", telephony_info.call_path);
memset(telephony_info.address, 0x00, sizeof(telephony_info.address));
if (__bluetooth_telephony_proxy_init()) {
BT_ERR("__bluetooth_telephony_proxy_init failed\n");
- dbus_g_connection_unref(telephony_dbus_info.conn);
telephony_dbus_info.conn = NULL;
is_initialized = FALSE;
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- telephony_dbus_info.manager_proxy = dbus_g_proxy_new_for_name(
- telephony_dbus_info.conn,
- BLUEZ_SERVICE_NAME,
- "/", BLUEZ_MANAGER_INTERFACE);
-
+ telephony_dbus_info.manager_proxy = g_dbus_proxy_new_sync(
+ telephony_dbus_info.conn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ BLUEZ_SERVICE_NAME, "/",
+ BLUEZ_MANAGER_INTERFACE, NULL, &error);
if (telephony_dbus_info.manager_proxy == NULL) {
- BT_ERR("Could not create a manager proxy\n");
+ BT_ERR("Could not create a manager proxy");
__bluetooth_telephony_proxy_deinit();
- dbus_g_connection_unref(telephony_dbus_info.conn);
telephony_dbus_info.conn = NULL;
is_initialized = FALSE;
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ return ret;
+ }
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- telephony_dbus_info.dbus_proxy = dbus_g_proxy_new_for_name(
- telephony_dbus_info.conn, DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
-
+ telephony_dbus_info.dbus_proxy = g_dbus_proxy_new_sync(
+ telephony_dbus_info.conn,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ BT_EVENT_FREEDESKTOP, BT_FREEDESKTOP_PATH,
+ BT_EVENT_FREEDESKTOP, NULL, &error);
if (NULL == telephony_dbus_info.dbus_proxy) {
__bluetooth_telephony_proxy_deinit();
- dbus_g_connection_unref(telephony_dbus_info.conn);
telephony_dbus_info.conn = NULL;
g_object_unref(telephony_dbus_info.manager_proxy);
telephony_dbus_info.manager_proxy = NULL;
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- /*Add Signal callback for BT enabled*/
- dbus_g_proxy_add_signal(telephony_dbus_info.manager_proxy,
- "AdapterAdded",
- DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(telephony_dbus_info.manager_proxy,
- "AdapterAdded",
- G_CALLBACK(__bluetooth_telephony_adapter_added_cb),
- NULL, NULL);
+ if (__bt_telephony_subscribe_adapter_signal(telephony_dbus_info.conn, TRUE) != 0) {
+ BT_ERR("Fail to Subscribe Adapter Signal");
+ goto fail;
+ }
/*Callback and user applicaton data*/
telephony_info.cb = cb;
telephony_info.user_data = user_data;
telephony_info.headset_state = BLUETOOTH_STATE_DISCONNETED;
- dbus_error_init(&dbus_error);
- conn = dbus_g_connection_get_connection(telephony_dbus_info.conn);
- dbus_connection_add_filter(conn, __bluetooth_telephony_event_filter,
- NULL, NULL);
-
- dbus_bus_add_match(conn,
- "type='signal',interface='" BLUEZ_HEADSET_INTERFACE
- "',member='PropertyChanged'", &dbus_error);
- dbus_bus_add_match(conn,
- "type='signal',interface='"HFP_AGENT_SERVICE
- "',member='"HFP_NREC_STATUS_CHANGE"'" , &dbus_error);
-
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add dbus filter signal\n");
- dbus_error_free(&dbus_error);
+ if (__bt_telephony_event_subscribe_signal(telephony_dbus_info.conn, TRUE) != 0) {
+ BT_ERR("Fail to Subscribe telephony event Signal");
goto fail;
}
- /*Check for BT status*/
- ret = __bluetooth_get_default_adapter_path(telephony_dbus_info.conn,
- object_path);
- if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
+ if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED)
return BLUETOOTH_TELEPHONY_ERROR_NONE;
/*Bluetooth is active, therefore set the flag */
is_active = TRUE;
-
+ if (!src_addr) {
+ ret = bluetooth_get_local_address(&loc_address);
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Fail to get local address\n");
+ ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ goto fail;
+ }
+ _bt_convert_addr_type_to_string(src_address, loc_address.addr);
+ src_addr = g_strdup(src_address);
+ }
ret = __bluetooth_telephony_register();
if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
BT_ERR("__bluetooth_telephony_register failed\n");
goto fail;
}
- BT_DBG("-");
+ if (TIZEN_PROFILE_WEARABLE || TIZEN_PROFILE_IVI)
+ __bluetooth_telephony_init_headset_state();
+
+ FN_END;
return ret;
fail:
bluetooth_telephony_deinit();
BT_EXPORT_API int bluetooth_telephony_deinit(void)
{
- BT_DBG("+");
- DBusConnection *conn;
-
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
is_initialized = FALSE;
- conn = dbus_g_connection_get_connection(telephony_dbus_info.conn);
+ if (__bt_telephony_event_subscribe_signal(telephony_dbus_info.conn, FALSE) != 0)
+ BT_ERR("Fail to UnSubscribe telephony event Signal");
- dbus_bus_remove_match(conn,
- "type='signal',interface='" BLUEZ_HEADSET_INTERFACE
- "',member='PropertyChanged'", NULL);
-
- dbus_bus_remove_match(conn,
- "type='signal',interface='"HFP_AGENT_SERVICE
- "',member='"HFP_NREC_STATUS_CHANGE"'", NULL);
-
- dbus_connection_remove_filter(conn, __bluetooth_telephony_event_filter,
- NULL);
-
- if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_ENABLED)
+ if (bluetooth_check_adapter() != BLUETOOTH_ADAPTER_DISABLED ||
+ bluetooth_check_adapter_le() != BLUETOOTH_ADAPTER_LE_DISABLED)
__bluetooth_telephony_unregister();
__bluetooth_telephony_proxy_deinit();
telephony_info.call_count = 0;
telephony_info.headset_state = BLUETOOTH_STATE_DISCONNETED;
- /*Remove BT enabled signal*/
- dbus_g_proxy_disconnect_signal(
- telephony_dbus_info.manager_proxy,
- "AdapterAdded",
- G_CALLBACK(__bluetooth_telephony_adapter_added_cb),
- NULL);
+ /* Remove BT enabled signal */
+ if (__bt_telephony_subscribe_adapter_signal(telephony_dbus_info.conn, FALSE) != 0)
+ BT_ERR("Fail to UnSubscribe Adapter event Signal");
- g_object_unref(telephony_dbus_info.manager_proxy);
- telephony_dbus_info.manager_proxy = NULL;
+ g_free(src_addr);
+ src_addr = NULL;
- dbus_g_connection_unref(telephony_dbus_info.conn);
- telephony_dbus_info.conn = NULL;
+ if (telephony_dbus_info.manager_proxy != NULL) {
+ g_object_unref(telephony_dbus_info.manager_proxy);
+ telephony_dbus_info.manager_proxy = NULL;
+ }
- g_object_unref(telephony_dbus_info.dbus_proxy);
- telephony_dbus_info.dbus_proxy = NULL;
+ if (telephony_dbus_info.conn != NULL)
+ telephony_dbus_info.conn = NULL;
- BT_DBG("-");
+ if (telephony_dbus_info.dbus_proxy != NULL) {
+ g_object_unref(telephony_dbus_info.dbus_proxy);
+ telephony_dbus_info.dbus_proxy = NULL;
+ }
+
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
BT_EXPORT_API gboolean bluetooth_telephony_is_sco_connected(void)
{
- BT_DBG("+");
+ GVariant *reply;
+ GError *err = NULL;
+ gboolean status = FALSE;
- if (telephony_dbus_info.conn == NULL) {
- BT_ERR("Bluetooth telephony not initilized");
- return FALSE;
- }
+ FN_START;
- /* To get the headset state */
- if (telephony_dbus_info.proxy == NULL)
- telephony_dbus_info.proxy =
- __bluetooth_telephony_get_connected_device_proxy();
+ retv_if(is_initialized == FALSE, FALSE);
+ retv_if(bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED, FALSE);
- if (telephony_dbus_info.proxy == NULL)
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "IsPlaying", &err, NULL);
+
+ if (!reply) {
+ BT_ERR("Error returned in method call\n");
+ if (err) {
+ BT_ERR("Error message = %s", err->message);
+ g_error_free(err);
+ }
return FALSE;
+ }
+ g_variant_get(reply, "(b)", &status);
+ g_variant_unref(reply);
- if (telephony_info.headset_state == BLUETOOTH_STATE_PLAYING)
- return TRUE;
+ if (TIZEN_PROFILE_WEARABLE || TIZEN_PROFILE_IVI)
+ if (status == TRUE && telephony_info.headset_state != BLUETOOTH_STATE_PLAYING)
+ telephony_info.headset_state = BLUETOOTH_STATE_PLAYING;
- BT_DBG("-");
- return FALSE;
+ BT_INFO("SCO Connected Status = [%d]", status);
+ return status;
}
BT_EXPORT_API int bluetooth_telephony_is_nrec_enabled(gboolean *status)
{
- DBusMessage* reply;
- DBusError err;
- DBusMessageIter reply_iter;
- DBusMessageIter reply_iter_entry;
- const char *property;
+ GVariant *reply;
+ GError *err = NULL;
+ GVariantIter iter;
+ GVariant *param_inner;
- BT_DBG("+");
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
if (status == NULL)
return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
+ if (telephony_info.headset_state == BLUETOOTH_STATE_DISCONNETED)
+ return BLUETOOTH_TELEPHONY_ERROR_AUDIO_NOT_CONNECTED;
+
reply = __bluetooth_telephony_dbus_method_send(
HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
- "GetProperties", &err, DBUS_TYPE_INVALID);
+ "GetProperties", &err, NULL);
if (!reply) {
BT_ERR("Error returned in method call\n");
- if (dbus_error_is_set(&err)) {
- BT_DBG("Error message = %s \n", err.message);
- dbus_error_free(&err);
+ if (err) {
+ BT_DBG("Error message = %s", err->message);
+ g_error_free(err);
}
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- dbus_message_iter_init(reply, &reply_iter);
+ g_variant_iter_init(&iter, reply);
+ while ((param_inner = g_variant_iter_next_value(&iter))) {
+ GVariant *value;
- if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_ARRAY) {
- BT_ERR("Can't get reply arguments - DBUS_TYPE_ARRAY\n");
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ value = g_variant_lookup_value(param_inner,
+ "nrec", G_VARIANT_TYPE_BOOLEAN);
+ if (value) {
+ BT_DBG("Property NREC Found");
+ *status = g_variant_get_boolean(value);
+ BT_DBG("NREC status = [%d]", *status);
+ g_variant_unref(value);
+ g_variant_unref(param_inner);
+ break;
+ }
+ g_variant_unref(param_inner);
}
+ BT_DBG("NREC status = [%d]", *status);
+ g_variant_unref(reply);
+
+ FN_END;
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+}
- dbus_message_iter_recurse(&reply_iter, &reply_iter_entry);
+BT_EXPORT_API int bluetooth_telephony_is_wbs_mode(gboolean *status)
+{
+ GVariant *reply;
+ GError *err = NULL;
+ unsigned int codec;
+ GVariantIter iter;
+ GVariant *param_inner;
+
+ FN_START;
+
+ BT_TELEPHONY_CHECK_INITIALIZED();
+ BT_TELEPHONY_CHECK_ENABLED();
- /*Parse the dict */
- while (dbus_message_iter_get_arg_type(&reply_iter_entry) ==
- DBUS_TYPE_DICT_ENTRY) {
+ if (status == NULL)
+ return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
+
+ *status = FALSE;
+
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "GetProperties", &err, NULL);
+
+ if (!reply) {
+ BT_ERR("Error returned in method call");
+ if (err) {
+ BT_ERR("Error message = %s", err->message);
+ g_error_free(err);
+ }
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ }
- DBusMessageIter dict_entry, dict_entry_val;
- dbus_message_iter_recurse(&reply_iter_entry, &dict_entry);
- dbus_message_iter_get_basic(&dict_entry, &property);
- BT_DBG("String received = %s\n", property);
+ g_variant_iter_init(&iter, reply);
+ while ((param_inner = g_variant_iter_next_value(&iter))) {
+ GVariant *value;
- if (g_strcmp0("nrec", property) == 0) {
- dbus_message_iter_next(&dict_entry);
- dbus_message_iter_recurse(&dict_entry, &dict_entry_val);
- if (dbus_message_iter_get_arg_type(&dict_entry_val) !=
- DBUS_TYPE_BOOLEAN)
- continue;
+ value = g_variant_lookup_value(param_inner,
+ "codec", G_VARIANT_TYPE_UINT32);
+ if (value) {
+ BT_DBG("Property CODEC Found");
+ codec = g_variant_get_uint32(value);
+ g_variant_unref(value);
+ BT_DBG("Codec = [%d]", codec);
- dbus_message_iter_get_basic(&dict_entry_val, status);
+ *status = codec == BT_MSBC_CODEC_ID ? TRUE : FALSE;
BT_DBG("NREC status = [%d]", *status);
+ g_variant_unref(value);
+ g_variant_unref(param_inner);
+ break;
}
- dbus_message_iter_next(&reply_iter_entry);
+ g_variant_unref(param_inner);
}
- dbus_message_unref(reply);
- BT_DBG("-");
+
+ g_variant_unref(reply);
+ BT_DBG("MSBC status = [%d]", *status);
+
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-BT_EXPORT_API int bluetooth_telephony_start_voice_recognition(void)
+BT_EXPORT_API int bluetooth_telephony_send_vendor_cmd(const char *cmd)
{
GError *error = NULL;
- int ret;
+ GVariant *reply, *parameters;
+ int ret = BLUETOOTH_TELEPHONY_ERROR_NONE;
- BT_DBG("+");
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
+ BT_DBG("Send Vendor %s", cmd);
+
if (telephony_dbus_info.proxy == NULL)
telephony_dbus_info.proxy =
__bluetooth_telephony_get_connected_device_proxy();
if (telephony_dbus_info.proxy == NULL)
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- if (!dbus_g_proxy_call(telephony_dbus_info.proxy, "SetVoiceDial",
- &error, G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID,
- G_TYPE_INVALID)) {
- if (error != NULL) {
- ret = __bt_telephony_get_error(error->message);
- g_error_free(error);
+ parameters = g_variant_new("s", cmd);
+ reply = g_dbus_proxy_call_sync(telephony_dbus_info.proxy,
+ "SendVendorAtCmd", parameters,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ g_variant_unref(reply);
+
+ if (error) {
+ g_dbus_error_strip_remote_error(error);
+ ret = __bt_telephony_get_error(error->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(error);
+ }
+
+ FN_END;
+ return ret;
+}
+
+BT_EXPORT_API int bluetooth_telephony_start_voice_recognition(void)
+{
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
+ int ret;
+ gboolean state = TRUE;
+
+ FN_START;
+
+ BT_TELEPHONY_CHECK_INITIALIZED();
+ BT_TELEPHONY_CHECK_ENABLED();
+
+ param = g_variant_new("(b)", &state);
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "SetVoiceDial", &err, param);
+
+ if (!reply) {
+ BT_ERR("Error returned in method call\n");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
return ret;
}
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- BT_DBG("-");
+ g_variant_unref(reply);
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
BT_EXPORT_API int bluetooth_telephony_stop_voice_recognition(void)
{
- GError *error = NULL;
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
int ret;
+ gboolean state = FALSE;
- BT_DBG("+");
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
- if (telephony_dbus_info.proxy == NULL)
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ param = g_variant_new("(b)", &state);
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "SetVoiceDial", &err, param);
- if (!dbus_g_proxy_call(telephony_dbus_info.proxy, "SetVoiceDial",
- &error, G_TYPE_BOOLEAN,
- FALSE, G_TYPE_INVALID, G_TYPE_INVALID)) {
- BT_ERR("Dbus Call Failed!\n");
- if (error != NULL) {
- ret = __bt_telephony_get_error(error->message);
- g_error_free(error);
+ if (!reply) {
+ BT_ERR("Error returned in method call\n");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
return ret;
}
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- BT_DBG("-");
+ g_variant_unref(reply);
+
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-BT_EXPORT_API int bluetooth_telephony_audio_open(void)
+static void __bluetooth_telephony_sco_start_cb(GDBusProxy *proxy,
+ GAsyncResult *res, gpointer user_data)
{
GError *error = NULL;
+ GVariant *value = NULL;
+
+ value = g_dbus_proxy_call_finish(proxy, res, &error);
+ if (value == NULL) {
+ if (error != NULL) {
+ BT_ERR("sco_close_cb error. errCode[%x],message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ } else {
+ BT_ERR("SCo Start Failed");
+ }
+ g_object_unref(proxy);
+ return;
+ }
+
+ BT_DBG("sco_start_cb : -");
+ g_object_unref(proxy);
+ g_variant_unref(value);
+}
+
+BT_EXPORT_API int bluetooth_telephony_audio_open(void)
+{
+ GDBusConnection *conn;
+ GDBusProxy *proxy;
+ GError *err = NULL;
int ret;
- BT_DBG("+");
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
- if (telephony_dbus_info.proxy == NULL)
- telephony_dbus_info.proxy =
- __bluetooth_telephony_get_connected_device_proxy();
+ /* Because this API is async call, so can't use dbus SMACK */
+ if (__bt_telephony_check_privilege() ==
+ BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED) {
+ BT_ERR("Don't have a privilege to use this API");
+ return BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED;
+ }
- if (telephony_dbus_info.proxy == NULL)
+ conn = _bt_get_system_private_conn();
+ if (!conn) {
+ BT_DBG("No System Bus found\n");
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ }
if (telephony_info.headset_state == BLUETOOTH_STATE_PLAYING)
return BLUETOOTH_TELEPHONY_ERROR_ALREADY_CONNECTED;
- if (!dbus_g_proxy_call(telephony_dbus_info.proxy, "Play", &error,
- G_TYPE_INVALID, G_TYPE_INVALID)) {
- BT_ERR("Dbus Call Failed!");
- if (error != NULL) {
- ret = __bt_telephony_get_error(error->message);
- g_error_free(error);
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ HFP_AGENT_SERVICE, HFP_AGENT_PATH,
+ HFP_AGENT_INTERFACE, NULL, &err);
+ if (proxy == NULL) {
+ BT_ERR("Unable to allocate new proxy");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(err);
return ret;
}
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- BT_DBG("-");
+
+ g_dbus_proxy_call(proxy, "Play", NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, (GAsyncReadyCallback)__bluetooth_telephony_sco_start_cb, NULL);
+
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-BT_EXPORT_API int bluetooth_telephony_audio_close(void)
+static void __bluetooth_telephony_sco_close_cb(GDBusProxy *proxy,
+ GAsyncResult *res, gpointer user_data)
{
GError *error = NULL;
+ GVariant *value = NULL;
+
+ value = g_dbus_proxy_call_finish(proxy, res, &error);
+ if (value == NULL) {
+ if (error != NULL) {
+ BT_ERR("sco_close_cb error. errCode[%x],message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ } else {
+ BT_ERR("SCo close Failed");
+ }
+ g_object_unref(proxy);
+ return;
+ }
+
+ BT_DBG("sco_close_cb : -");
+ g_object_unref(proxy);
+ g_variant_unref(value);
+}
+BT_EXPORT_API int bluetooth_telephony_audio_close(void)
+{
+ GDBusConnection *conn;
+ GDBusProxy *proxy;
+ GError *err = NULL;
int ret;
- BT_DBG("+");
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
- if (telephony_dbus_info.proxy == NULL)
- telephony_dbus_info.proxy =
- __bluetooth_telephony_get_connected_device_proxy();
+ /* Because this API is async call, so can't use dbus SMACK */
+ if (__bt_telephony_check_privilege() ==
+ BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED) {
+ BT_ERR("Don't have a privilege to use this API");
+ return BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED;
+ }
- if (telephony_dbus_info.proxy == NULL)
+ conn = _bt_get_system_private_conn();
+ if (!conn) {
+ BT_DBG("No System Bus found\n");
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ }
- if (telephony_info.headset_state != BLUETOOTH_STATE_PLAYING) {
+ if (telephony_info.headset_state != BLUETOOTH_STATE_PLAYING)
return BLUETOOTH_TELEPHONY_ERROR_NOT_CONNECTED;
- }
- if (!dbus_g_proxy_call(telephony_dbus_info.proxy, "Stop", &error,
- G_TYPE_INVALID, G_TYPE_INVALID)) {
- BT_ERR("Dbus Call Failed");
- if (error != NULL) {
- ret = __bt_telephony_get_error(error->message);
- g_error_free(error);
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
+ HFP_AGENT_SERVICE, HFP_AGENT_PATH,
+ HFP_AGENT_INTERFACE, NULL, &err);
+ if (proxy == NULL) {
+ BT_ERR("Unable to allocate new proxy");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ BT_ERR("Error here %d\n", ret);
+ g_error_free(err);
return ret;
}
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- BT_DBG("-");
+ g_dbus_proxy_call(proxy, "Stop", NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, (GAsyncReadyCallback)__bluetooth_telephony_sco_close_cb, NULL);
+
+ telephony_info.headset_state = BLUETOOTH_STATE_CONNECTED;
+
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
- BT_DBG("+");
+ FN_START;
+ BT_DBG("call_id = [%d]", call_id);
/*Make sure SCO is already connected */
ret = __bluetooth_telephony_send_call_status(
- CSD_CALL_STATUS_MO_ALERTING, call_id);
- if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
+ CSD_CALL_STATUS_MO_ALERTING, call_id, NULL);
+
+ if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
BT_ERR("send call status Failed = [%d]", ret);
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- }
- BT_DBG("-");
- return BLUETOOTH_TELEPHONY_ERROR_NONE;
+
+ FN_END;
+ return ret;
}
BT_EXPORT_API int bluetooth_telephony_call_answered(unsigned int call_id,
unsigned int bt_audio)
{
int ret;
- BT_DBG("+");
+
+ FN_START;
+ BT_DBG("call_id = [%d]", call_id);
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
ret = __bluetooth_telephony_send_call_status(CSD_CALL_STATUS_ACTIVE,
- call_id);
+ call_id, NULL);
if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
BT_ERR("send call status Failed = [%d]", ret);
return ret;
if (bt_audio) {
if (!bluetooth_telephony_is_sco_connected()) {
ret = bluetooth_telephony_audio_open();
- if (ret != 0) {
- BT_ERR("Audio connection call Failed = %d", ret);
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- }
+ if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
+ BT_ERR("Audio connection call Failed[%d]", ret);
}
}
- BT_DBG("-");
+ FN_END;
return ret;
}
BT_EXPORT_API int bluetooth_telephony_call_end(unsigned int call_id)
{
int ret;
- BT_DBG("+");
+
+ FN_START;
+ BT_DBG("call_id = [%d]", call_id);
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
- ret = __bluetooth_telephony_send_call_status(CSD_CALL_STATUS_MT_RELEASE,
- call_id);
- if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
- BT_ERR("send call status Failed = [%d]", ret);
- return ret;
- }
if (telephony_info.call_count > 0)
telephony_info.call_count = telephony_info.call_count - 1;
if (telephony_info.call_count == 0) {
if (bluetooth_telephony_is_sco_connected()) {
ret = bluetooth_telephony_audio_close();
- if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
+ if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
BT_ERR(" Failed = [%d]", ret);
- return ret;
- }
}
}
- BT_DBG("-");
+
+ ret = __bluetooth_telephony_send_call_status(CSD_CALL_STATUS_MT_RELEASE,
+ call_id, NULL);
+ if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
+ BT_ERR("send call status Failed = [%d]", ret);
+
+ FN_END;
return ret;
}
BT_EXPORT_API int bluetooth_telephony_call_held(unsigned int call_id)
{
int ret;
- BT_DBG("+");
+
+ FN_START;
+ BT_DBG("call_id = [%d]", call_id);
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
ret = __bluetooth_telephony_send_call_status(CSD_CALL_STATUS_HOLD,
- call_id);
- if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
+ call_id, NULL);
+ if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
BT_ERR("send call status Failed = [%d]", ret);
- }
- BT_DBG("-");
+
+ FN_END;
return ret;
}
BT_EXPORT_API int bluetooth_telephony_call_retrieved(unsigned int call_id)
{
int ret;
- BT_DBG("+");
+
+ FN_START;
+ BT_DBG("call_id = [%d]", call_id);
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
ret = __bluetooth_telephony_send_call_status(CSD_CALL_STATUS_ACTIVE,
- call_id);
- if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
+ call_id, NULL);
+ if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
BT_ERR("send call status Failed = [%d]", ret);
- }
- BT_DBG("-");
+
+ FN_END;
return ret;
}
GList *list = call_list;
bt_telephony_call_status_info_t *call_status;
- BT_DBG("+");
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
}
+ /* Because this API is async call, so can't use dbus SMACK */
+ if (__bt_telephony_check_privilege() ==
+ BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED) {
+ BT_ERR("Don't have a privilege to use this API");
+ return BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED;
+ }
+
BT_DBG(" call_count = [%d]", call_count);
for (i = 0; i < call_count; i++) {
call_status->call_id,
call_status->call_status);
+ if (NULL != call_status->phone_number)
+ DBG_SECURE("Number [%s]", call_status->phone_number);
+
switch (call_status->call_status) {
case BLUETOOTH_CALL_STATE_HELD:
ret = __bluetooth_telephony_send_call_status(
CSD_CALL_STATUS_HOLD,
- call_status->call_id);
+ call_status->call_id,
+ call_status->phone_number);
if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
BT_ERR("Failed = %d", ret);
return ret;
case BLUETOOTH_CALL_STATE_CONNECTED:
ret = __bluetooth_telephony_send_call_status(
CSD_CALL_STATUS_ACTIVE,
- call_status->call_id);
+ call_status->call_id,
+ call_status->phone_number);
if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
BT_ERR("Failed = [%d]", ret);
return ret;
break;
default:
- if ((call_status->call_status < BLUETOOTH_CALL_STATE_NONE) ||
- (call_status->call_status >= BLUETOOTH_CALL_STATE_ERROR)) {
+ if ((call_status->call_status <
+ BLUETOOTH_CALL_STATE_NONE) ||
+ (call_status->call_status >=
+ BLUETOOTH_CALL_STATE_ERROR)) {
BT_ERR("Unknown Call state");
return BLUETOOTH_TELEPHONY_ERROR_NOT_AVAILABLE;
}
}
}
- BT_DBG("-");
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
{
int ret;
- BT_DBG("+");
+ FN_START;
ret = bluetooth_telephony_call_swapped(call_list, call_count);
telephony_info.call_count = call_count;
- BT_DBG("-");
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
const char *ph_number, unsigned int call_id,
unsigned int bt_audio)
{
- DBusMessage *reply;
- DBusError err;
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
const char *path = telephony_info.call_path;
- int ret;
+ int ret = BLUETOOTH_TELEPHONY_ERROR_NONE;
- BT_DBG("+");
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
if (NULL == ph_number)
return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
+ param = g_variant_new("(ssi)", path, ph_number, call_id);
reply = __bluetooth_telephony_dbus_method_send(
HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
- "OutgoingCall", &err, DBUS_TYPE_STRING, &path,
- DBUS_TYPE_STRING, &ph_number, DBUS_TYPE_INT32,
- &call_id, DBUS_TYPE_INVALID);
+ "OutgoingCall", &err, param);
if (!reply) {
BT_ERR("Error returned in method call\n");
- if (dbus_error_is_set(&err)) {
- ret = __bt_telephony_get_error(err.message);
- dbus_error_free(&err);
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
return ret;
}
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- dbus_message_unref(reply);
+ g_variant_unref(reply);
telephony_info.call_count++;
BT_DBG(" ag_info.ag_call_count = [%d]", telephony_info.call_count);
if (bt_audio) {
if (!bluetooth_telephony_is_sco_connected()) {
ret = bluetooth_telephony_audio_open();
- if (ret != 0) {
- BT_ERR(" Audio connection call Failed = %d", ret);
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- }
+ if (ret != 0)
+ BT_ERR(" Audio connection Failed = %d", ret);
}
}
- BT_DBG("-");
- return BLUETOOTH_TELEPHONY_ERROR_NONE;
+ FN_END;
+ return ret;
}
BT_EXPORT_API int bluetooth_telephony_indicate_incoming_call(
const char *ph_number, unsigned int call_id)
{
- DBusMessage *reply;
- DBusError err;
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
const char *path = telephony_info.call_path;
int ret;
- BT_DBG("+");
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
if (NULL == ph_number)
return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
+ param = g_variant_new("(ssi)", path, ph_number, call_id);
reply = __bluetooth_telephony_dbus_method_send(
HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
- "IncomingCall", &err, DBUS_TYPE_STRING, &path,
- DBUS_TYPE_STRING, &ph_number, DBUS_TYPE_INT32,
- &call_id, DBUS_TYPE_INVALID);
+ "IncomingCall", &err, param);
if (!reply) {
BT_ERR("Error returned in method call\n");
- if (dbus_error_is_set(&err)) {
- ret = __bt_telephony_get_error(err.message);
- dbus_error_free(&err);
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
return ret;
}
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- dbus_message_unref(reply);
-
+ g_variant_unref(reply);
telephony_info.call_count++;
BT_DBG("telephony_info.call_count = [%d]", telephony_info.call_count);
- BT_DBG("-");
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-BT_EXPORT_API int bluetooth_telephony_set_speaker_gain(unsigned short speaker_gain)
+BT_EXPORT_API int bluetooth_telephony_set_speaker_gain(
+ unsigned short speaker_gain)
{
- DBusMessage *msg;
- DBusMessageIter iter;
- DBusMessageIter value;
- DBusConnection *conn;
- char *spkr_gain_str = "SpeakerGain";
- int ret = BLUETOOTH_TELEPHONY_ERROR_NONE;
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
+ int ret;
- BT_DBG("+");
- BT_DBG("set speaker_gain= [%d]", speaker_gain);
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
- conn = dbus_g_connection_get_connection(telephony_dbus_info.conn);
+ BT_DBG("set speaker_gain= [%d]", speaker_gain);
- if (telephony_info.obj_path == NULL)
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ param = g_variant_new("(q)", speaker_gain);
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "SetSpeakerGain", &err, param);
- msg = dbus_message_new_method_call(BLUEZ_SERVICE_NAME,
- telephony_info.obj_path, BLUEZ_HEADSET_INTERFACE,
- "SetProperty");
-
- if (NULL != msg) {
- char sig[2] = {DBUS_TYPE_UINT16, '\0'};
-
- dbus_message_iter_init_append(msg, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
- &spkr_gain_str);
- dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
- sig, &value);
- dbus_message_iter_append_basic(&value, DBUS_TYPE_UINT16,
- &speaker_gain);
- dbus_message_iter_close_container(&iter, &value);
-
- if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_CALL)
- dbus_message_set_no_reply(msg, TRUE);
- if (!dbus_connection_send(conn, msg, NULL)) {
- BT_ERR("bluetooth_telephony_set_speaker_gain : dbus sending failed");
- ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ if (!reply) {
+ BT_ERR("Error returned in method call\n");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
+ return ret;
}
- dbus_message_unref(msg);
- } else
- ret = BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ }
- BT_DBG("-");
- return ret;
+ g_variant_unref(reply);
+ FN_END;
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-BT_EXPORT_API int bluetooth_telephony_get_headset_volume(unsigned int *speaker_gain)
+BT_EXPORT_API int bluetooth_telephony_get_headset_volume(
+ unsigned int *speaker_gain)
{
- GHashTable *hash = NULL;
- GValue *value = NULL;
- GError *error = NULL;
+ GVariant *reply;
+ GError *err = NULL;
int ret;
+ guint16 gain;
+
+ FN_START;
- BT_DBG("+");
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
- if (telephony_dbus_info.proxy == NULL)
- telephony_dbus_info.proxy =
- __bluetooth_telephony_get_connected_device_proxy();
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "GetSpeakerGain", &err, NULL);
- if (telephony_dbus_info.proxy == NULL)
+ if (!reply) {
+ BT_ERR("Error returned in method call\n");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
+ return ret;
+ }
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ }
+ g_variant_get(reply, "(q)", &gain);
+ *speaker_gain = gain;
+ BT_DBG("Get speaker_gain= [%d]", *speaker_gain);
- if (!dbus_g_proxy_call(telephony_dbus_info.proxy, "GetProperties", &error,
- G_TYPE_INVALID,
- dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
- &hash, G_TYPE_INVALID)) {
- BT_ERR("Dbus Call Failed!");
- if (error != NULL) {
- ret = __bt_telephony_get_error(error->message);
- g_error_free(error);
+ g_variant_unref(reply);
+
+ FN_END;
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+}
+
+BT_EXPORT_API int bluetooth_telephony_is_connected(gboolean *ag_connected)
+{
+ GVariant *reply;
+ GError *err = NULL;
+ int ret;
+ gboolean ag_connected_from_bt_agent;
+
+ BT_CHECK_ENABLED(return);
+
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "IsConnected", &err, NULL);
+
+ if (!reply) {
+ BT_ERR("Error returned in method call\n");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
return ret;
}
+ return BLUETOOTH_ERROR_INTERNAL;
}
+ g_variant_get(reply, "(b)", &ag_connected_from_bt_agent);
+ *ag_connected = ag_connected_from_bt_agent;
+
+ BT_DBG("Conn Status: %s", *ag_connected ? "Connected" : "Disconnected");
- if (hash == NULL)
+ g_variant_unref(reply);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+BT_EXPORT_API int bluetooth_telephony_set_active_headset(const char *remote_addr)
+{
+#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
+ int ret;
+
+ BT_CHECK_ENABLED(return);
+
+ if (NULL == remote_addr)
+ return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
+
+ param = g_variant_new("(s)", remote_addr);
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "SwapHeadset", &err, param);
+
+ if (!reply) {
+ BT_ERR("Error returned in method call\n");
+ if (err) {
+ g_dbus_error_strip_remote_error(err);
+ ret = __bt_telephony_get_error(err->message);
+ g_error_free(err);
+ return ret;
+ }
return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ }
- value = g_hash_table_lookup(hash, "SpeakerGain");
- *speaker_gain = g_value_get_uint(value);
- g_hash_table_destroy(hash);
- BT_DBG("-");
+ g_variant_unref(reply);
return BLUETOOTH_TELEPHONY_ERROR_NONE;
+#else
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+#endif
+}
+
+static void __bt_telephony_adapter_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ FN_START;
+ int ret;
+ char *path = NULL;
+
+ if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
+ GVariant *optional_param = NULL;
+
+ g_variant_get(parameters, "(&o@a{sa{sv}})",
+ &path, &optional_param);
+
+ if (!path) {
+ BT_ERR("Invalid adapter path");
+ return;
+ }
+
+ BT_DBG("Adapter Path = [%s]", path);
+ if (strcasecmp(path, DEFAULT_ADAPTER_OBJECT_PATH) == 0) {
+ if (__bt_telephony_get_src_addr(optional_param))
+ BT_ERR("Fail to get the local adapter address");
+
+ ret = __bluetooth_telephony_register();
+ if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
+ BT_ERR("__bluetooth_telephony_register failed");
+ }
+
+ g_variant_unref(optional_param);
+ }
+
+ FN_END;
+}
+
+static int __bt_telephony_get_src_addr(GVariant *value)
+{
+ GVariantIter iter;
+ GVariant *param = NULL;
+ FN_START;
+
+ /* signature a{sa{sv}} */
+ g_variant_iter_init(&iter, value);
+ while ((param = g_variant_iter_next_value(&iter))) {
+ char *interface_name;
+ GVariant *interface_var = NULL;
+ GVariant *param_inner = NULL;
+
+ g_variant_get(param, "{&s*}", &interface_name, &interface_var);
+ g_variant_unref(param);
+
+ BT_DBG("interface_name: %s", interface_name);
+ /* format of interface_var: a{sv}*/
+ if (strcasecmp(interface_name, BLUEZ_ADAPTER_INTERFACE) == 0) {
+ GVariantIter iter_inner;
+
+ g_variant_iter_init(&iter_inner, interface_var);
+ while ((param_inner = g_variant_iter_next_value(&iter_inner))) {
+ char *property_name;
+ GVariant *property_var;
+
+ g_variant_get(param_inner, "{&sv}",
+ &property_name,
+ &property_var);
+ g_variant_unref(param_inner);
+
+ if (strcasecmp(property_name, "Address") == 0) {
+ const gchar *bd_addr;
+
+ bd_addr = g_variant_get_string(
+ property_var,
+ NULL);
+ src_addr = g_strdup(bd_addr);
+ BT_DBG("Address: %s", src_addr);
+
+ g_variant_unref(interface_var);
+ g_variant_unref(property_var);
+ goto done;
+ }
+ g_variant_unref(property_var);
+ }
+ }
+ g_variant_unref(interface_var);
+ }
+
+done:
+ return BLUETOOTH_ERROR_NONE;
}