/*
- * 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.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_SERVICE "org.bluez.hfp_agent"
-#define HFP_AGENT_PATH "/org/bluez/hfp_ag"
+#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 HFP_HF_BATTERY_LEVEL_CHANGE "HfBatteryLevelChanged"
+
+#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 DBusHandlerResult __bt_telephony_adapter_filter(DBusConnection *conn,
- DBusMessage *msg, void *data);
-
-static int __bt_telephony_get_object_path(DBusMessage *msg, char **path);
-
-static char *__bt_extract_device_path(DBusMessageIter *msg_iter, char *address);
-
-static char *_bt_get_device_object_path(char *address);
+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 void _bt_convert_device_path_to_address(const char *device_path,
- char *device_address);
+static int __bt_telephony_get_src_addr(GVariant *value);
-static char *__bt_get_default_adapter_path(DBusMessageIter *msg_iter);
-
-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 gboolean bluetooth_telephony_method_send_dtmf(
- BluetoothTelephonyMethod *object,
- gchar *dtmf, DBusGMethodInvocation *context);
-
-#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);
+ 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_proxy_init(void);
-static void __bluetooth_telephony_proxy_deinit(void);
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 = g_dbus_proxy_call_sync(proxy, method, parameters,
+ G_DBUS_CALL_FLAGS_NONE, timeout, NULL, 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);
-
- 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_hf_battery_level_change(GVariant *var)
{
- const char *path = dbus_message_get_path(msg);
- char *dev_addr = NULL;
- DBusMessageIter item_iter;
- DBusMessageIter value_iter;
- const char *property;
+ telephony_event_hf_battery_level_t param;
+ char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- /* 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;
- }
+ g_variant_get(var, "(&su)", ¶m.remote_address, ¶m.battery_level);
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ _bt_convert_addr_string_to_secure_string(secure_address, param.remote_address);
+ BT_INFO("address(%s) battery level(%u)", secure_address, param.battery_level);
- 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;
- }
+ __bt_telephony_event_cb(BLUETOOTH_EVENT_TELEPHONY_HF_BATTERY_LEVEL_CHANGED,
+ BLUETOOTH_TELEPHONY_ERROR_NONE, (void *)¶m);
+}
- dbus_message_iter_get_basic(&item_iter, &property);
+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)
+{
+ 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);
- __bt_telephony_event_cb(
- BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED,
- BLUETOOTH_TELEPHONY_ERROR_NONE, NULL);
- }
-
- telephony_info.headset_state = BLUETOOTH_STATE_DISCONNETED;
- }
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- 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);
+ 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;
+
+ if (telephony_dbus_info.proxy != NULL) {
+ g_object_unref(telephony_dbus_info.proxy);
+ telephony_dbus_info.proxy = NULL;
+ }
+
+ BT_INFO("Headset Disconnected");
+
+ __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);
+ else if (strcasecmp(signal_name, HFP_HF_BATTERY_LEVEL_CHANGE) == 0)
+ __bluetooth_telephony_hf_battery_level_change(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);
- 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;
+ }
+ } else {
+ if (bt_tel_id > 0) {
+ g_dbus_connection_unregister_object(telephony_dbus_info.conn,
+ bt_tel_id);
+ bt_tel_id = 0;
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
static int __bluetooth_telephony_proxy_init(void)
{
- BT_DBG("+");
-
- object = (GObject *)__bluetooth_telephony_method_new();
+ FN_START;
+ GDBusNodeInfo *node_info;
+ gchar *name;
- if (NULL == object)
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ name = g_strdup_printf("org.tizen.csd.Call.Instance.p%d", getpid());
- BT_DBG("telephony_object = %x", object);
+ 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("well-known name: %s, owner_id: %d", name, owner_id);
+ g_free(name);
- dbus_g_connection_register_g_object(telephony_dbus_info.conn,
- telephony_info.call_path, G_OBJECT(object));
+ 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("-");
+ 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);
+ 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);
- dbus_error_free(&err);
+ 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)
{
- DBusMessage *msg;
- DBusMessage *reply;
- DBusMessageIter reply_iter;
- DBusMessageIter value_iter;
- DBusError err;
- DBusConnection *conn;
- char *adapter_path = NULL;
-
- BT_DBG("+");
-
- conn = dbus_g_connection_get_connection(telephony_dbus_info.conn);
-
- retv_if(conn == NULL, NULL);
+ GVariant *reply;
+ GError *err = NULL;
+ gboolean status = FALSE;
- msg = dbus_message_new_method_call(BT_BLUEZ_NAME, BT_MANAGER_PATH,
- BT_MANAGER_INTERFACE,
- "GetManagedObjects");
+ FN_START;
- retv_if(msg == NULL, NULL);
- /* Synchronous call */
- dbus_error_init(&err);
- reply = dbus_connection_send_with_reply_and_block(
- conn, msg, -1, &err);
- dbus_message_unref(msg);
+ if (telephony_dbus_info.conn == NULL) {
+ BT_ERR("Bluetooth telephony not initilized");
+ return;
+ }
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "IsConnected", &err, NULL);
if (!reply) {
- BT_ERR("Can't get managed objects");
-
- if (dbus_error_is_set(&err)) {
- BT_ERR("%s", err.message);
- dbus_error_free(&err);
+ 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;
- }
-
- if (dbus_message_iter_init(reply, &reply_iter) == FALSE) {
- BT_ERR("Fail to iterate the reply");
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
+ return;
}
- dbus_message_iter_recurse(&reply_iter, &value_iter);
-
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter msg_iter;
-
- dbus_message_iter_recurse(&value_iter, &msg_iter);
-
- adapter_path = __bt_get_default_adapter_path(&msg_iter);
- if (adapter_path != NULL) {
- BT_DBG("Found the adapter path");
- break;
- }
- dbus_message_iter_next(&value_iter);
- }
+ g_variant_get(reply, "(b)", &status);
+ g_variant_unref(reply);
- if (adapter_path == NULL) {
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- }
+ BT_INFO("Headset Connected Status = [%d]", status);
+ if (status)
+ telephony_info.headset_state = BLUETOOTH_STATE_CONNECTED;
+ else
+ return;
- if (strlen(adapter_path) >= BT_ADAPTER_PATH_LEN) {
- BT_ERR("Path too long.\n");
- g_free(adapter_path);
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- }
+ if (bluetooth_telephony_is_sco_connected())
+ telephony_info.headset_state = BLUETOOTH_STATE_PLAYING;
- BT_DBG("object path = %s", adapter_path);
- g_strlcpy(path, adapter_path, BT_ADAPTER_PATH_LEN);
- g_free(adapter_path);
- BT_DBG("-");
- return BLUETOOTH_TELEPHONY_ERROR_NONE;
+ 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)
-{
- DBusMessage *msg;
- DBusMessage *reply;
- DBusMessageIter reply_iter;
- DBusMessageIter value_iter;
- DBusError err;
- DBusConnection *conn;
- DBusGProxy *headset_agent_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;
+}
- GError *error = NULL;
- uint32_t device_class;
- gboolean playing = FALSE;
- gboolean connected = FALSE;
- GHashTable *list_hash;
- GValue *value = {0};
- char *object_path = NULL;
- DBusGProxy *proxy = NULL;
- const gchar *address;
+static gboolean __bluetooth_telephony_is_headset_by_uuid(gchar **uuids)
+{
+ int i;
+ char **parts;
+ unsigned int service = 0;
- conn = _bt_get_system_conn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+ FN_START;
- msg = dbus_message_new_method_call(BLUEZ_SERVICE_NAME, "/",
- BLUEZ_MANAGER_INTERFACE,
- "GetManagedObjects");
+ retv_if(uuids == NULL, FALSE);
- retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
+ for (i = 0; uuids[i] != NULL; i++) {
+ parts = g_strsplit(uuids[i], "-", -1);
- /* Synchronous call */
- dbus_error_init(&err);
- reply = dbus_connection_send_with_reply_and_block(
- conn, msg,
- -1, &err);
- dbus_message_unref(msg);
+ if (parts == NULL || parts[0] == NULL) {
+ g_strfreev(parts);
+ continue;
+ }
- if (!reply) {
- BT_ERR("Can't get managed objects");
+ service = g_ascii_strtoull(parts[0], NULL, 16);
+ g_strfreev(parts);
- if (dbus_error_is_set(&err)) {
- BT_ERR("%s", err.message);
- dbus_error_free(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
+ if (service == BLUETOOTH_HS_PROFILE_UUID ||
+ service == BLUETOOTH_HF_PROFILE_UUID)
+ return TRUE;
}
- if (dbus_message_iter_init(reply, &reply_iter) == FALSE) {
- BT_ERR("Fail to iterate the reply");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+ FN_END;
+ return FALSE;
+}
- dbus_message_iter_recurse(&reply_iter, &value_iter);
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter msg_iter;
+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;
- dbus_message_iter_recurse(&value_iter, &msg_iter);
+ FN_START;
+ conn = _bt_get_system_private_conn();
+ retv_if(conn == NULL, BLUETOOTH_TELEPHONY_ERROR_INTERNAL);
+
+ 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;
+ }
- /* Parse the signature: oa{sa{sv}}} */
- retv_if(dbus_message_iter_get_arg_type(&msg_iter) !=
- DBUS_TYPE_OBJECT_PATH, NULL);
+ /* 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_message_iter_get_basic(&msg_iter, &object_path);
+ 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;
+ }
+ /* 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;
+ }
- if (object_path) {
- proxy = dbus_g_proxy_new_for_name(telephony_dbus_info.conn,
- BLUEZ_SERVICE_NAME, object_path,
- BLUEZ_PROPERTIES_INTERFACE);
- if (proxy == NULL)
- goto done;
+ 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);
- dbus_g_proxy_call(proxy, "GetAll", &err,
- G_TYPE_STRING, BLUEZ_DEVICE_INTERFACE,
- G_TYPE_INVALID,
- dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
- G_TYPE_VALUE), &list_hash, G_TYPE_INVALID);
+ 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 (list_hash != NULL) {
- value = g_hash_table_lookup(list_hash, "Class");
- device_class = value ? g_value_get_uint(value) : 0;
+ 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);
- if (!__bluetooth_telephony_is_headset(device_class)) {
- g_object_unref(proxy);
- proxy = NULL;
- g_hash_table_destroy(list_hash);
- dbus_message_iter_next(&value_iter);
- continue;
+ 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;
}
- /* this is headset; Check for Connection */
- headset_agent_proxy = dbus_g_proxy_new_for_name(
- telephony_dbus_info.conn,
- HFP_AGENT_SERVICE, object_path,
- HFP_AGENT_INTERFACE);
+ /* 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) {
- g_hash_table_destroy(list_hash);
+ 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;
}
- dbus_g_proxy_call(headset_agent_proxy, "IsConnected",
- &error, G_TYPE_INVALID,
- &connected, G_TYPE_INVALID);
+ 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 (error == NULL) {
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));
- dbus_g_proxy_call(headset_agent_proxy, "IsPlaying",
- &error, G_TYPE_INVALID,
- &playing, G_TYPE_INVALID);
-
- if (playing)
- telephony_info.headset_state =
- BLUETOOTH_STATE_PLAYING;
- else
- telephony_info.headset_state =
- BLUETOOTH_STATE_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;
+ }
- g_hash_table_destroy(list_hash);
goto done;
}
- } else {
- g_error_free(error);
}
- g_hash_table_destroy(list_hash);
- g_object_unref(proxy);
- proxy = NULL;
- } /* end of if(object_path) */
-
- dbus_message_iter_next(&value_iter);
- } /* end of while */
+ g_object_unref(headset_agent_proxy);
+ g_variant_unref(var_path);
+ }
+ g_variant_unref(param);
+ }
done:
- if (proxy)
- g_object_unref(proxy);
- 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 = NULL;
-
- BT_DBG("+");
+ GDBusProxy *proxy = NULL;
+ GError *error = NULL;
+ int ret;
+ FN_START;
if (strlen(telephony_info.address) == 0)
__bluetooth_telephony_get_connected_device();
- if (strlen(telephony_info.address) == 0) {
+ if (strlen(telephony_info.address) == 0)
return NULL;
- }
- if (telephony_info.obj_path) {
- g_free(telephony_info.obj_path);
- telephony_info.obj_path = NULL;
+ 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;
}
- object_path = _bt_get_device_object_path(telephony_info.address);
- g_strlcpy(telephony_info.obj_path, object_path, BT_ADAPTER_PATH_LEN);
+ FN_END;
+ return proxy;
+}
- proxy = dbus_g_proxy_new_for_name(telephony_dbus_info.conn,
- HFP_AGENT_SERVICE, telephony_info.obj_path,
- HFP_AGENT_INTERFACE);
+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("+");
- DBusConnection *dbus_conn;
- 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;
}
- dbus_conn = dbus_g_connection_get_connection(telephony_dbus_info.conn);
-
- /*Add Signal callback for BT enabled*/
- if (!dbus_connection_add_filter(dbus_conn, __bt_telephony_adapter_filter,
- NULL, NULL)) {
- BT_ERR("Fail to add filter");
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
- }
-
- dbus_error_init(&dbus_error);
-
- dbus_bus_add_match(dbus_conn,
- "type='signal',interface='org.freedesktop.DBus.ObjectManager'"
- ",member='InterfacesAdded'",
- &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);
+ if (__bt_telephony_subscribe_adapter_signal(telephony_dbus_info.conn, TRUE) != 0) {
+ BT_ERR("Fail to Subscribe Adapter Signal");
goto fail;
}
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='"HFP_AGENT_SERVICE
- "',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("-");
- return ret;
+ if (TIZEN_PROFILE_WEARABLE || TIZEN_PROFILE_IVI)
+ __bluetooth_telephony_init_headset_state();
+ FN_END;
+ return ret;
fail:
bluetooth_telephony_deinit();
return ret;
BT_EXPORT_API int bluetooth_telephony_deinit(void)
{
- DBusConnection *conn;
- DBusError error;
-
- BT_DBG("+");
-
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
is_initialized = FALSE;
- conn = dbus_g_connection_get_connection(telephony_dbus_info.conn);
-
- dbus_error_init(&error);
- dbus_bus_remove_match(conn,
- "type='signal',interface='"HFP_AGENT_SERVICE
- "',member='PropertyChanged'", &error);
- dbus_bus_remove_match(conn,
- "type='signal',interface='"HFP_AGENT_SERVICE
- "',member='"HFP_NREC_STATUS_CHANGE"'", &error);
- if (dbus_error_is_set(&error)) {
- BT_ERR("Fail to remove dbus filter signal\n");
- dbus_error_free(&error);
- }
-
- dbus_connection_remove_filter(conn, __bluetooth_telephony_event_filter,
- NULL);
+ if (__bt_telephony_event_subscribe_signal(telephony_dbus_info.conn, FALSE) != 0)
+ BT_ERR("Fail to UnSubscribe telephony event Signal");
- 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_bus_remove_match(conn,
- "type='signal',interface='org.freedesktop.DBus.ObjectManager'"
- ",member='InterfacesAdded'",
- &error);
- if (dbus_error_is_set(&error)) {
- BT_ERR("Fail to remove dbus filter signal\n");
- dbus_error_free(&error);
- }
+ /* Remove BT enabled signal */
+ if (__bt_telephony_subscribe_adapter_signal(telephony_dbus_info.conn, FALSE) != 0)
+ BT_ERR("Fail to UnSubscribe Adapter event Signal");
- dbus_connection_remove_filter(dbus_g_connection_get_connection(
- telephony_dbus_info.conn), __bt_telephony_adapter_filter,
- NULL);
+ g_free(src_addr);
+ src_addr = NULL;
- g_object_unref(telephony_dbus_info.manager_proxy);
- telephony_dbus_info.manager_proxy = NULL;
+ if (telephony_dbus_info.manager_proxy != NULL) {
+ g_object_unref(telephony_dbus_info.manager_proxy);
+ telephony_dbus_info.manager_proxy = NULL;
+ }
- dbus_g_connection_unref(telephony_dbus_info.conn);
- telephony_dbus_info.conn = NULL;
+ if (telephony_dbus_info.conn != NULL)
+ telephony_dbus_info.conn = NULL;
- g_object_unref(telephony_dbus_info.dbus_proxy);
- telephony_dbus_info.dbus_proxy = NULL;
+ if (telephony_dbus_info.dbus_proxy != NULL) {
+ g_object_unref(telephony_dbus_info.dbus_proxy);
+ telephony_dbus_info.dbus_proxy = NULL;
+ }
- BT_DBG("-");
+ 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);
- dbus_message_iter_recurse(&reply_iter, &reply_iter_entry);
+ FN_END;
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+}
- /*Parse the dict */
- while (dbus_message_iter_get_arg_type(&reply_iter_entry) ==
- DBUS_TYPE_DICT_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;
- 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);
+ FN_START;
+
+ BT_TELEPHONY_CHECK_INITIALIZED();
+ BT_TELEPHONY_CHECK_ENABLED();
+
+ 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;
+ }
- 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;
+ g_variant_iter_init(&iter, reply);
+ while ((param_inner = g_variant_iter_next_value(&iter))) {
+ GVariant *value;
- dbus_message_iter_get_basic(&dict_entry_val, status);
+ 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);
+
+ *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)
{
- GError *error = NULL;
- int ret = BLUETOOTH_TELEPHONY_ERROR_NONE;
- DBusGProxy *headset_agent_proxy = NULL;
- BT_DBG("+");
- BT_DBG("set speaker_gain= [%d]", speaker_gain);
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
+ int ret;
+
+ FN_START;
BT_TELEPHONY_CHECK_INITIALIZED();
BT_TELEPHONY_CHECK_ENABLED();
- if (telephony_info.obj_path == NULL)
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
-
- if (telephony_dbus_info.proxy == NULL)
- telephony_dbus_info.proxy =
- __bluetooth_telephony_get_connected_device_proxy();
+ BT_DBG("set speaker_gain= [%d]", speaker_gain);
- if (telephony_dbus_info.proxy == 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);
- if (!dbus_g_proxy_call(headset_agent_proxy, "SetSpeakerGain",
- &error, G_TYPE_UINT, speaker_gain, G_TYPE_INVALID,
- G_TYPE_INVALID)) {
- if (error != NULL) {
- BT_ERR("Calling SetSpeakerGain failed: [%s]",
- 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("-");
- 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)
{
- DBusGProxy *headset_agent_proxy = 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();
-
- if (telephony_dbus_info.proxy == NULL)
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
-
- if (telephony_info.obj_path == NULL)
- return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
-
- 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;
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "GetSpeakerGain", &err, NULL);
- if (!dbus_g_proxy_call(headset_agent_proxy, "GetSpeakerGain",
- &error, G_TYPE_INVALID, G_TYPE_UINT, &speaker_gain,
- G_TYPE_INVALID)) {
- if (error != NULL) {
- BT_ERR("Calling G`etSpeakerGain failed: [%s]",
- 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;
}
+ g_variant_get(reply, "(q)", &gain);
+ *speaker_gain = gain;
+ BT_DBG("Get speaker_gain= [%d]", *speaker_gain);
- BT_DBG("-");
+ g_variant_unref(reply);
+
+ FN_END;
return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-static char *_bt_get_device_object_path(char *address)
+BT_EXPORT_API int bluetooth_telephony_get_battery_level(
+ const char *remote_address, unsigned int *level)
{
- DBusMessage *msg;
- DBusMessage *reply;
- DBusMessageIter reply_iter;
- DBusMessageIter value_iter;
- DBusError err;
- DBusConnection *conn;
- char *object_path = NULL;
- BT_DBG("+");
+ GVariant *reply;
+ GError *err = NULL;
+ GVariant *param = NULL;
+ int ret;
- conn = _bt_get_system_conn();
- retv_if(conn == NULL, NULL);
+ FN_START;
- msg = dbus_message_new_method_call(BLUEZ_SERVICE_NAME, BT_MANAGER_PATH,
- BLUEZ_MANAGER_INTERFACE,
- "GetManagedObjects");
+ BT_TELEPHONY_CHECK_INITIALIZED();
+ BT_TELEPHONY_CHECK_ENABLED();
- retv_if(msg == NULL, NULL);
+ param = g_variant_new("(s)", remote_address);
- /* Synchronous call */
- dbus_error_init(&err);
- reply = dbus_connection_send_with_reply_and_block(
- conn, msg,
- -1, &err);
- dbus_message_unref(msg);
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "GetHfBatteryLevel", &err, param);
if (!reply) {
- BT_ERR("Can't get managed objects");
-
- if (dbus_error_is_set(&err)) {
- BT_ERR("%s", err.message);
- dbus_error_free(&err);
- }
- return NULL;
- }
-
- if (dbus_message_iter_init(reply, &reply_iter) == FALSE) {
- BT_ERR("Fail to iterate the reply");
- return NULL;
- }
-
- dbus_message_iter_recurse(&reply_iter, &value_iter);
-
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter msg_iter;
-
- dbus_message_iter_recurse(&value_iter, &msg_iter);
-
- object_path = __bt_extract_device_path(&msg_iter, address);
- if (object_path != NULL) {
- BT_DBG("Found the device path");
- break;
+ 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_iter_next(&value_iter);
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- BT_DBG("-");
- return object_path;
-}
-
-static char *__bt_extract_device_path(DBusMessageIter *msg_iter, char *address)
-{
- char *object_path = NULL;
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- BT_DBG("+");
- /* Parse the signature: oa{sa{sv}}} */
- retv_if(dbus_message_iter_get_arg_type(msg_iter) !=
- DBUS_TYPE_OBJECT_PATH, NULL);
+ g_variant_get(reply, "(u)", level);
- dbus_message_iter_get_basic(msg_iter, &object_path);
- retv_if(object_path == NULL, NULL);
+ g_variant_unref(reply);
- _bt_convert_device_path_to_address(object_path, device_address);
-
- if (g_strcmp0(address, device_address) == 0) {
- return g_strdup(object_path);
- }
- BT_DBG("-");
- return NULL;
+ FN_END;
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
}
-static DBusHandlerResult __bt_telephony_adapter_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+BT_EXPORT_API int bluetooth_telephony_is_connected(gboolean *ag_connected)
{
+ GVariant *reply;
+ GError *err = NULL;
int ret;
- char *object_path = NULL;
- const char *member = dbus_message_get_member(msg);
- BT_DBG("+");
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ gboolean ag_connected_from_bt_agent;
- if (member == NULL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ BT_CHECK_ENABLED(return);
- if (strcasecmp(member, "InterfacesAdded") == 0) {
- if (__bt_telephony_get_object_path(msg, &object_path)) {
- BT_ERR("Fail to get the path");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- if (strcasecmp(object_path, "/org/bluez/hci0") == 0) {
- BT_DBG("Adapter added [%s] \n", object_path);
- BT_DBG("BlueZ is Activated and flag need to be reset");
- BT_DBG("Send enabled to application\n");
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "IsConnected", &err, NULL);
- ret = __bluetooth_telephony_register();
- if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
- BT_DBG("__bluetooth_telephony_register failed\n");
- }
+ 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;
}
- }
- BT_DBG("-");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static int __bt_telephony_get_object_path(DBusMessage *msg, char **path)
-{
- DBusMessageIter item_iter;
- dbus_message_iter_init(msg, &item_iter);
- BT_DBG("+");
-
- 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;
}
+ g_variant_get(reply, "(b)", &ag_connected_from_bt_agent);
+ *ag_connected = ag_connected_from_bt_agent;
- dbus_message_iter_get_basic(&item_iter, path);
+ BT_DBG("Conn Status: %s", *ag_connected ? "Connected" : "Disconnected");
- if (*path == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
+ g_variant_unref(reply);
- BT_DBG("-");
return BLUETOOTH_ERROR_NONE;
}
-static void _bt_convert_device_path_to_address(const char *device_path,
- char *device_address)
+BT_EXPORT_API int bluetooth_telephony_set_active_headset(const char *remote_addr)
{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *dev_addr;
- BT_DBG("+");
+#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
+ GVariant *reply;
+ GVariant *param;
+ GError *err = NULL;
+ int ret;
- ret_if(device_path == NULL);
- ret_if(device_address == NULL);
+ BT_CHECK_ENABLED(return);
+
+ if (NULL == remote_addr)
+ return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM;
- dev_addr = strstr(device_path, "dev_");
- if (dev_addr != NULL) {
- char *pos = NULL;
- dev_addr += 4;
- g_strlcpy(address, dev_addr, sizeof(address));
+ param = g_variant_new("(s)", remote_addr);
+ reply = __bluetooth_telephony_dbus_method_send(
+ HFP_AGENT_PATH, HFP_AGENT_INTERFACE,
+ "SwapHeadset", &err, param);
- while ((pos = strchr(address, '_')) != NULL) {
- *pos = ':';
+ 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;
}
- g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
+ return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
}
- BT_DBG("-");
+
+ g_variant_unref(reply);
+ return BLUETOOTH_TELEPHONY_ERROR_NONE;
+#else
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+#endif
}
-static char *__bt_get_default_adapter_path(DBusMessageIter *msg_iter)
+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)
{
- char *object_path = NULL;
- DBusMessageIter value_iter;
- BT_DBG("+");
-
- /* Parse the signature: oa{sa{sv}}} */
- retv_if(dbus_message_iter_get_arg_type(msg_iter) !=
- DBUS_TYPE_OBJECT_PATH, NULL);
+ FN_START;
+ int ret;
+ char *path = NULL;
- dbus_message_iter_get_basic(msg_iter, &object_path);
+ if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
+ GVariant *optional_param = NULL;
- retv_if(dbus_message_iter_next(msg_iter) == FALSE, NULL);
- retv_if(dbus_message_iter_get_arg_type(msg_iter) !=
- DBUS_TYPE_ARRAY, NULL);
+ g_variant_get(parameters, "(&o@a{sa{sv}})",
+ &path, &optional_param);
- dbus_message_iter_recurse(msg_iter, &value_iter);
+ if (!path) {
+ BT_ERR("Invalid adapter path");
+ return;
+ }
- while (dbus_message_iter_get_arg_type(&value_iter) ==
- DBUS_TYPE_DICT_ENTRY) {
- char *interface_name = NULL;
- DBusMessageIter interface_iter;
+ 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");
- dbus_message_iter_recurse(&value_iter, &interface_iter);
+ ret = __bluetooth_telephony_register();
+ if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
+ BT_ERR("__bluetooth_telephony_register failed");
+ }
- retv_if(dbus_message_iter_get_arg_type(&interface_iter) !=
- DBUS_TYPE_STRING, NULL);
+ g_variant_unref(optional_param);
+ }
- dbus_message_iter_get_basic(&interface_iter, &interface_name);
+ FN_END;
+}
- if (g_strcmp0(interface_name, "org.bluez.Adapter1") == 0) {
- return g_strdup(object_path);
+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);
+ }
}
- dbus_message_iter_next(&value_iter);
+ g_variant_unref(interface_var);
}
- BT_DBG("Adapter Not Found");
- BT_DBG("-");
- return NULL;
-}
+done:
+ return BLUETOOTH_ERROR_NONE;
+}