2009-10-18 22:20:25 +00:00
|
|
|
/*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
2010-01-02 01:00:10 +00:00
|
|
|
* Copyright (C) 2008-2010 Intel Corporation. All rights reserved.
|
2010-02-11 22:52:40 +00:00
|
|
|
* Copyright (C) 2010 ProFUSION embedded systems
|
2009-10-18 22:20:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2009-10-19 21:59:44 +00:00
|
|
|
#include <stdio.h>
|
2009-10-18 22:20:25 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gatchat.h>
|
|
|
|
#include <gattty.h>
|
2010-01-27 19:12:49 +00:00
|
|
|
#include <gdbus.h>
|
|
|
|
#include <ofono.h>
|
2009-10-18 22:20:25 +00:00
|
|
|
|
|
|
|
#define OFONO_API_SUBJECT_TO_CHANGE
|
|
|
|
#include <ofono/plugin.h>
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/netreg.h>
|
|
|
|
#include <ofono/voicecall.h>
|
2009-11-08 17:15:59 +00:00
|
|
|
#include <ofono/call-volume.h>
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2009-10-20 03:13:19 +00:00
|
|
|
#include <drivers/hfpmodem/hfpmodem.h>
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
#include <ofono/dbus.h>
|
|
|
|
|
|
|
|
#define BLUEZ_SERVICE "org.bluez"
|
|
|
|
#define BLUEZ_MANAGER_INTERFACE BLUEZ_SERVICE ".Manager"
|
|
|
|
#define BLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE ".Adapter"
|
|
|
|
#define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device"
|
|
|
|
#define BLUEZ_GATEWAY_INTERFACE BLUEZ_SERVICE ".HandsfreeGateway"
|
|
|
|
|
|
|
|
#define HFP_AGENT_INTERFACE "org.bluez.HandsfreeAgent"
|
2010-02-04 18:57:26 +00:00
|
|
|
#define HFP_AGENT_ERROR_INTERFACE "org.bluez.Error"
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
#define HFP_AG_UUID "0000111F-0000-1000-8000-00805F9B34FB"
|
|
|
|
|
|
|
|
#ifndef DBUS_TYPE_UNIX_FD
|
|
|
|
#define DBUS_TYPE_UNIX_FD -1
|
|
|
|
#endif
|
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
static const char *brsf_prefix[] = { "+BRSF:", NULL };
|
|
|
|
static const char *cind_prefix[] = { "+CIND:", NULL };
|
|
|
|
static const char *cmer_prefix[] = { "+CMER:", NULL };
|
2009-11-25 05:48:43 +00:00
|
|
|
static const char *chld_prefix[] = { "+CHLD:", NULL };
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
static DBusConnection *connection;
|
2012-01-14 20:00:55 +00:00
|
|
|
static GHashTable *uuid_hash = NULL;
|
2010-02-12 22:33:53 +00:00
|
|
|
static GHashTable *adapter_address_hash;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
static void hfp_debug(const char *str, void *user_data)
|
|
|
|
{
|
2009-11-01 14:42:18 +00:00
|
|
|
ofono_info("%s", str);
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 19:13:09 +00:00
|
|
|
static void clear_data(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
if (!data->chat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_at_chat_unref(data->chat);
|
|
|
|
data->chat = NULL;
|
|
|
|
|
|
|
|
memset(data->cind_val, 0, sizeof(data->cind_val));
|
|
|
|
memset(data->cind_pos, 0, sizeof(data->cind_pos));
|
|
|
|
}
|
|
|
|
|
2009-11-25 05:48:43 +00:00
|
|
|
static void sevice_level_conn_established(struct ofono_modem *modem)
|
|
|
|
{
|
2010-01-27 19:12:49 +00:00
|
|
|
DBusMessage *msg;
|
2009-11-25 05:48:43 +00:00
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
ofono_modem_set_powered(modem, TRUE);
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
msg = dbus_message_new_method_return(data->slc_msg);
|
|
|
|
g_dbus_send_message(connection, msg);
|
|
|
|
dbus_message_unref(data->slc_msg);
|
2010-02-04 18:57:26 +00:00
|
|
|
data->slc_msg = NULL;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
ofono_info("Service level connection established");
|
|
|
|
|
2009-11-25 05:48:43 +00:00
|
|
|
g_at_chat_send(data->chat, "AT+CMEE=1", NULL, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2010-02-04 18:57:26 +00:00
|
|
|
static void service_level_conn_failed(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
DBusMessage *msg;
|
|
|
|
|
|
|
|
msg = g_dbus_create_error(data->slc_msg, HFP_AGENT_ERROR_INTERFACE
|
|
|
|
".Failed",
|
|
|
|
"HFP Handshake failed");
|
|
|
|
g_dbus_send_message(connection, msg);
|
|
|
|
dbus_message_unref(data->slc_msg);
|
|
|
|
data->slc_msg = NULL;
|
|
|
|
|
|
|
|
ofono_error("Service level connection failed");
|
2010-02-04 19:13:09 +00:00
|
|
|
ofono_modem_set_powered(modem, FALSE);
|
|
|
|
clear_data(modem);
|
2010-02-04 18:57:26 +00:00
|
|
|
}
|
|
|
|
|
2009-11-25 05:48:43 +00:00
|
|
|
static void chld_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
unsigned int ag_mpty_feature = 0;
|
|
|
|
GAtResultIter iter;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CHLD:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_open_list(&iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (g_at_result_iter_next_unquoted_string(&iter, &str)) {
|
|
|
|
if (!strcmp(str, "0"))
|
|
|
|
ag_mpty_feature |= AG_CHLD_0;
|
|
|
|
else if (!strcmp(str, "1"))
|
|
|
|
ag_mpty_feature |= AG_CHLD_1;
|
|
|
|
else if (!strcmp(str, "1x"))
|
|
|
|
ag_mpty_feature |= AG_CHLD_1x;
|
|
|
|
else if (!strcmp(str, "2"))
|
|
|
|
ag_mpty_feature |= AG_CHLD_2;
|
|
|
|
else if (!strcmp(str, "2x"))
|
|
|
|
ag_mpty_feature |= AG_CHLD_2x;
|
|
|
|
else if (!strcmp(str, "3"))
|
|
|
|
ag_mpty_feature |= AG_CHLD_3;
|
|
|
|
else if (!strcmp(str, "4"))
|
|
|
|
ag_mpty_feature |= AG_CHLD_4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_at_result_iter_close_list(&iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
data->ag_mpty_features = ag_mpty_feature;
|
|
|
|
|
|
|
|
sevice_level_conn_established(modem);
|
|
|
|
}
|
|
|
|
|
2009-11-25 05:47:16 +00:00
|
|
|
static void cmer_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
if (!ok) {
|
2010-02-04 19:13:09 +00:00
|
|
|
service_level_conn_failed(modem);
|
2009-11-25 05:47:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-25 05:48:43 +00:00
|
|
|
if (data->ag_features & AG_FEATURE_3WAY)
|
|
|
|
g_at_chat_send(data->chat, "AT+CHLD=?", chld_prefix,
|
|
|
|
chld_cb, modem, NULL);
|
|
|
|
else
|
|
|
|
sevice_level_conn_established(modem);
|
2009-11-25 05:47:16 +00:00
|
|
|
}
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
static int send_method_call(const char *dest, const char *path,
|
2010-02-11 22:52:42 +00:00
|
|
|
const char *interface, const char *method,
|
|
|
|
int type, ...)
|
|
|
|
{
|
|
|
|
DBusMessage *msg;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
msg = dbus_message_new_method_call(dest, path, interface, method);
|
|
|
|
if (!msg) {
|
|
|
|
ofono_error("Unable to allocate new D-Bus %s message", method);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(args, type);
|
|
|
|
|
|
|
|
if (!dbus_message_append_args_valist(msg, type, args)) {
|
|
|
|
dbus_message_unref(msg);
|
|
|
|
va_end(args);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
g_dbus_send_message(connection, msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int send_method_call_with_reply(const char *dest, const char *path,
|
2010-01-27 19:12:49 +00:00
|
|
|
const char *interface, const char *method,
|
|
|
|
DBusPendingCallNotifyFunction cb,
|
2010-02-12 22:29:59 +00:00
|
|
|
void *user_data, DBusFreeFunction free_func,
|
|
|
|
int timeout, int type, ...)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
|
|
|
DBusMessage *msg;
|
|
|
|
DBusPendingCall *call;
|
|
|
|
va_list args;
|
2010-02-12 23:51:23 +00:00
|
|
|
int err;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
msg = dbus_message_new_method_call(dest, path, interface, method);
|
|
|
|
if (!msg) {
|
|
|
|
ofono_error("Unable to allocate new D-Bus %s message", method);
|
2010-02-12 23:51:23 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto fail;
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
va_start(args, type);
|
|
|
|
|
|
|
|
if (!dbus_message_append_args_valist(msg, type, args)) {
|
|
|
|
va_end(args);
|
2010-02-12 23:51:23 +00:00
|
|
|
err = -EIO;
|
|
|
|
goto fail;
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
2010-02-11 22:52:42 +00:00
|
|
|
if (timeout > 0)
|
|
|
|
timeout *=1000;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-11 22:52:42 +00:00
|
|
|
if (!dbus_connection_send_with_reply(connection, msg, &call, timeout)) {
|
2010-01-27 19:12:49 +00:00
|
|
|
ofono_error("Sending %s failed", method);
|
2010-02-12 23:51:23 +00:00
|
|
|
err = -EIO;
|
|
|
|
goto fail;
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 22:29:59 +00:00
|
|
|
dbus_pending_call_set_notify(call, cb, user_data, free_func);
|
2010-01-27 19:12:49 +00:00
|
|
|
dbus_pending_call_unref(call);
|
|
|
|
dbus_message_unref(msg);
|
|
|
|
|
|
|
|
return 0;
|
2010-02-12 23:51:23 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
if (free_func && user_data)
|
|
|
|
free_func(user_data);
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
dbus_message_unref(msg);
|
|
|
|
|
|
|
|
return err;
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 21:05:27 +00:00
|
|
|
typedef void (*PropertyHandler)(DBusMessageIter *iter, gpointer user_data);
|
|
|
|
|
|
|
|
struct property_handler {
|
|
|
|
const char *property;
|
|
|
|
PropertyHandler callback;
|
|
|
|
gpointer user_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint property_handler_compare(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
const struct property_handler *handler = a;
|
|
|
|
const char *property = b;
|
|
|
|
|
|
|
|
return strcmp(handler->property, property);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_properties_reply(DBusMessage *reply,
|
|
|
|
const char *property, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
GSList *prop_handlers = NULL;
|
|
|
|
DBusMessageIter array, dict;
|
|
|
|
|
|
|
|
va_start(args, property);
|
|
|
|
|
|
|
|
while (property != NULL) {
|
|
|
|
struct property_handler *handler =
|
|
|
|
g_new0(struct property_handler, 1);
|
|
|
|
|
|
|
|
handler->property = property;
|
|
|
|
handler->callback = va_arg(args, PropertyHandler);
|
|
|
|
handler->user_data = va_arg(args, gpointer);
|
|
|
|
|
|
|
|
property = va_arg(args, const char *);
|
|
|
|
|
|
|
|
prop_handlers = g_slist_prepend(prop_handlers, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
if (dbus_message_iter_init(reply, &array) == FALSE)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&array, &dict);
|
|
|
|
|
|
|
|
while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
|
|
|
|
DBusMessageIter entry, value;
|
|
|
|
const char *key;
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&dict, &entry);
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&entry, &key);
|
|
|
|
|
|
|
|
dbus_message_iter_next(&entry);
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&entry, &value);
|
|
|
|
|
|
|
|
l = g_slist_find_custom(prop_handlers, key,
|
|
|
|
property_handler_compare);
|
|
|
|
|
|
|
|
if (l) {
|
|
|
|
struct property_handler *handler = l->data;
|
|
|
|
|
|
|
|
handler->callback(&value, handler->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_message_iter_next(&dict);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
g_slist_foreach(prop_handlers, (GFunc)g_free, NULL);
|
|
|
|
g_slist_free(prop_handlers);
|
|
|
|
}
|
|
|
|
|
2010-02-13 00:19:32 +00:00
|
|
|
static void parse_string(DBusMessageIter *iter, gpointer user_data)
|
|
|
|
{
|
|
|
|
char **str = user_data;
|
|
|
|
int arg_type = dbus_message_iter_get_arg_type(iter);
|
|
|
|
|
|
|
|
if (arg_type != DBUS_TYPE_OBJECT_PATH && arg_type != DBUS_TYPE_STRING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(iter, str);
|
|
|
|
}
|
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
static void cind_status_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
GAtResultIter iter;
|
2009-10-19 21:58:13 +00:00
|
|
|
int index;
|
|
|
|
int value;
|
2009-10-18 22:20:25 +00:00
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CIND:"))
|
|
|
|
goto error;
|
|
|
|
|
2009-10-19 21:58:13 +00:00
|
|
|
index = 1;
|
|
|
|
|
|
|
|
while (g_at_result_iter_next_number(&iter, &value)) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < HFP_INDICATOR_LAST; i++) {
|
|
|
|
if (index != data->cind_pos[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
data->cind_val[i] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
index += 1;
|
|
|
|
}
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2009-11-25 05:47:16 +00:00
|
|
|
g_at_chat_send(data->chat, "AT+CMER=3,0,0,1", cmer_prefix,
|
|
|
|
cmer_cb, modem, NULL);
|
2009-10-18 22:20:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2010-02-04 19:13:09 +00:00
|
|
|
service_level_conn_failed(modem);
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cind_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
GAtResultIter iter;
|
|
|
|
const char *str;
|
2009-10-19 21:58:13 +00:00
|
|
|
int index;
|
2009-10-18 22:20:25 +00:00
|
|
|
int min, max;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CIND:"))
|
|
|
|
goto error;
|
|
|
|
|
2009-10-19 21:58:13 +00:00
|
|
|
index = 1;
|
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
while (g_at_result_iter_open_list(&iter)) {
|
|
|
|
if (!g_at_result_iter_next_string(&iter, &str))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_open_list(&iter))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
while (g_at_result_iter_next_range(&iter, &min, &max))
|
|
|
|
;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_close_list(&iter))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_close_list(&iter))
|
|
|
|
goto error;
|
|
|
|
|
2009-10-19 21:58:13 +00:00
|
|
|
if (g_str_equal("service", str) == TRUE)
|
|
|
|
data->cind_pos[HFP_INDICATOR_SERVICE] = index;
|
|
|
|
else if (g_str_equal("call", str) == TRUE)
|
|
|
|
data->cind_pos[HFP_INDICATOR_CALL] = index;
|
|
|
|
else if (g_str_equal("callsetup", str) == TRUE)
|
|
|
|
data->cind_pos[HFP_INDICATOR_CALLSETUP] = index;
|
|
|
|
else if (g_str_equal("callheld", str) == TRUE)
|
|
|
|
data->cind_pos[HFP_INDICATOR_CALLHELD] = index;
|
|
|
|
else if (g_str_equal("signal", str) == TRUE)
|
|
|
|
data->cind_pos[HFP_INDICATOR_SIGNAL] = index;
|
|
|
|
else if (g_str_equal("roam", str) == TRUE)
|
|
|
|
data->cind_pos[HFP_INDICATOR_ROAM] = index;
|
|
|
|
else if (g_str_equal("battchg", str) == TRUE)
|
|
|
|
data->cind_pos[HFP_INDICATOR_BATTCHG] = index;
|
|
|
|
|
|
|
|
index += 1;
|
|
|
|
}
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2009-11-25 05:47:16 +00:00
|
|
|
g_at_chat_send(data->chat, "AT+CIND?", cind_prefix,
|
|
|
|
cind_status_cb, modem, NULL);
|
2009-10-18 22:20:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2010-02-04 19:13:09 +00:00
|
|
|
service_level_conn_failed(modem);
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void brsf_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+BRSF:"))
|
|
|
|
goto error;
|
|
|
|
|
2009-10-19 22:07:23 +00:00
|
|
|
g_at_result_iter_next_number(&iter, (gint *)&data->ag_features);
|
2009-10-18 22:20:25 +00:00
|
|
|
|
|
|
|
g_at_chat_send(data->chat, "AT+CIND=?", cind_prefix,
|
|
|
|
cind_cb, modem, NULL);
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2010-02-04 19:13:09 +00:00
|
|
|
service_level_conn_failed(modem);
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* either oFono or Phone could request SLC connection */
|
2010-01-27 19:12:49 +00:00
|
|
|
static int service_level_connection(struct ofono_modem *modem, int fd)
|
2009-10-18 22:20:25 +00:00
|
|
|
{
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
GIOChannel *io;
|
|
|
|
GAtSyntax *syntax;
|
|
|
|
GAtChat *chat;
|
2009-10-19 21:59:44 +00:00
|
|
|
char buf[64];
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
io = g_io_channel_unix_new(fd);
|
2009-10-18 22:20:25 +00:00
|
|
|
if (!io) {
|
|
|
|
ofono_error("Service level connection failed: %s (%d)",
|
|
|
|
strerror(errno), errno);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
syntax = g_at_syntax_new_gsmv1();
|
|
|
|
chat = g_at_chat_new(io, syntax);
|
|
|
|
g_at_syntax_unref(syntax);
|
|
|
|
g_io_channel_unref(io);
|
|
|
|
|
|
|
|
if (!chat)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (getenv("OFONO_AT_DEBUG"))
|
|
|
|
g_at_chat_set_debug(chat, hfp_debug, NULL);
|
|
|
|
|
2010-02-05 18:00:14 +00:00
|
|
|
snprintf(buf, sizeof(buf), "AT+BRSF=%d", data->hf_features);
|
2009-10-19 21:59:44 +00:00
|
|
|
g_at_chat_send(chat, buf, brsf_prefix,
|
2009-10-18 22:20:25 +00:00
|
|
|
brsf_cb, modem, NULL);
|
|
|
|
data->chat = chat;
|
|
|
|
|
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
|
2010-01-27 22:37:32 +00:00
|
|
|
static DBusMessage *hfp_agent_new_connection(DBusConnection *conn,
|
|
|
|
DBusMessage *msg, void *data)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
2010-01-28 17:12:52 +00:00
|
|
|
int fd, err;
|
2010-01-27 19:12:49 +00:00
|
|
|
struct ofono_modem *modem = data;
|
|
|
|
struct hfp_data *hfp_data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UNIX_FD, &fd,
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
2010-01-28 17:12:52 +00:00
|
|
|
err = service_level_connection(modem, fd);
|
|
|
|
if (err < 0 && err != -EINPROGRESS)
|
|
|
|
return __ofono_error_failed(msg);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
hfp_data->slc_msg = msg;
|
|
|
|
dbus_message_ref(msg);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-27 22:37:32 +00:00
|
|
|
static DBusMessage *hfp_agent_release(DBusConnection *conn,
|
|
|
|
DBusMessage *msg, void *data)
|
2009-10-18 22:20:25 +00:00
|
|
|
{
|
2010-01-27 19:12:49 +00:00
|
|
|
struct ofono_modem *modem = data;
|
2010-02-13 02:10:29 +00:00
|
|
|
struct hfp_data *hfp_data = ofono_modem_get_data(modem);
|
2012-01-14 20:00:56 +00:00
|
|
|
const char *obj_path = ofono_modem_get_path(modem);
|
|
|
|
|
|
|
|
g_dbus_unregister_interface(connection, obj_path, HFP_AGENT_INTERFACE);
|
2010-02-13 02:10:29 +00:00
|
|
|
hfp_data->agent_registered = FALSE;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
ofono_modem_remove(modem);
|
|
|
|
|
|
|
|
return dbus_message_new_method_return(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GDBusMethodTable agent_methods[] = {
|
|
|
|
{ "NewConnection", "h", "", hfp_agent_new_connection,
|
|
|
|
G_DBUS_METHOD_FLAG_ASYNC },
|
|
|
|
{ "Release", "", "", hfp_agent_release },
|
2010-01-27 22:37:50 +00:00
|
|
|
{ NULL, NULL, NULL, NULL }
|
2010-01-27 19:12:49 +00:00
|
|
|
};
|
|
|
|
|
2010-02-13 00:19:32 +00:00
|
|
|
static void create_path(const char *dev_addr, const char *adapter_addr,
|
|
|
|
char *buf, int size)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0, j = 0; adapter_addr[j] && i < size - 1; j++)
|
|
|
|
if (adapter_addr[j] >= '0' && adapter_addr[j] <= '9')
|
|
|
|
buf[i++] = adapter_addr[j];
|
|
|
|
else if (adapter_addr[j] >= 'A' && adapter_addr[j] <= 'F')
|
|
|
|
buf[i++] = adapter_addr[j];
|
|
|
|
|
|
|
|
if (i < size - 1)
|
|
|
|
buf[i++] = '_';
|
|
|
|
|
|
|
|
for (j = 0; dev_addr[j] && i < size - 1; j++)
|
|
|
|
if (dev_addr[j] >= '0' && dev_addr[j] <= '9')
|
|
|
|
buf[i++] = dev_addr[j];
|
|
|
|
else if (dev_addr[j] >= 'A' && dev_addr[j] <= 'F')
|
|
|
|
buf[i++] = dev_addr[j];
|
|
|
|
|
|
|
|
buf[i] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hfp_create_modem(const char *device, const char *dev_addr,
|
2010-02-13 00:30:03 +00:00
|
|
|
const char *adapter_addr, const char *alias)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
|
|
|
struct ofono_modem *modem;
|
2009-10-18 22:20:25 +00:00
|
|
|
struct hfp_data *data;
|
2010-02-13 00:19:32 +00:00
|
|
|
char buf[256];
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2010-02-13 00:19:32 +00:00
|
|
|
ofono_info("Using device: %s, devaddr: %s, adapter: %s",
|
|
|
|
device, dev_addr, adapter_addr);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-13 01:49:19 +00:00
|
|
|
strcpy(buf, "hfp/");
|
|
|
|
create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
|
2010-02-13 00:19:32 +00:00
|
|
|
|
|
|
|
modem = ofono_modem_create(buf, "hfp");
|
2010-02-04 18:58:18 +00:00
|
|
|
if (modem == NULL)
|
|
|
|
return -ENOMEM;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
data = g_try_new0(struct hfp_data, 1);
|
|
|
|
if (!data)
|
2010-02-04 18:58:18 +00:00
|
|
|
goto free;
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2009-10-19 21:59:44 +00:00
|
|
|
data->hf_features |= HF_FEATURE_3WAY;
|
|
|
|
data->hf_features |= HF_FEATURE_CLIP;
|
|
|
|
data->hf_features |= HF_FEATURE_REMOTE_VOLUME_CONTROL;
|
|
|
|
data->hf_features |= HF_FEATURE_ENHANCED_CALL_STATUS;
|
|
|
|
data->hf_features |= HF_FEATURE_ENHANCED_CALL_CONTROL;
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
data->handsfree_path = g_strdup(device);
|
2010-02-04 18:58:18 +00:00
|
|
|
if (data->handsfree_path == NULL)
|
|
|
|
goto free;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
ofono_modem_set_data(modem, data);
|
2010-02-13 00:30:03 +00:00
|
|
|
ofono_modem_set_name(modem, alias);
|
2010-01-27 19:12:49 +00:00
|
|
|
ofono_modem_register(modem);
|
|
|
|
|
2010-02-12 23:57:10 +00:00
|
|
|
g_hash_table_insert(uuid_hash, g_strdup(device), modem);
|
2012-01-14 20:00:55 +00:00
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
return 0;
|
2010-02-04 18:58:18 +00:00
|
|
|
|
|
|
|
free:
|
|
|
|
g_free(data);
|
|
|
|
ofono_modem_remove(modem);
|
|
|
|
|
|
|
|
return -ENOMEM;
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 23:52:55 +00:00
|
|
|
static void has_hfp_uuid(DBusMessageIter *array, gpointer user_data)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
2010-02-12 23:52:55 +00:00
|
|
|
gboolean *hfp = user_data;
|
2010-02-12 21:44:31 +00:00
|
|
|
DBusMessageIter value;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:44:31 +00:00
|
|
|
if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
|
2010-01-27 19:12:49 +00:00
|
|
|
return;
|
|
|
|
|
2010-02-12 21:44:31 +00:00
|
|
|
dbus_message_iter_recurse(array, &value);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:44:31 +00:00
|
|
|
while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
|
|
|
|
const char *uuid;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:44:31 +00:00
|
|
|
dbus_message_iter_get_basic(&value, &uuid);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:44:31 +00:00
|
|
|
if (!strcasecmp(uuid, HFP_AG_UUID)) {
|
2010-02-12 23:52:55 +00:00
|
|
|
*hfp = TRUE;
|
2010-02-12 21:44:31 +00:00
|
|
|
return;
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 21:44:31 +00:00
|
|
|
dbus_message_iter_next(&value);
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-12 21:44:31 +00:00
|
|
|
static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
2010-02-12 23:52:55 +00:00
|
|
|
char *path = user_data;
|
|
|
|
gboolean have_hfp = FALSE;
|
2010-02-13 00:19:32 +00:00
|
|
|
const char *adapter = NULL;
|
|
|
|
const char *adapter_addr = NULL;
|
|
|
|
const char *device_addr = NULL;
|
2010-02-13 00:30:03 +00:00
|
|
|
const char *alias = NULL;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
reply = dbus_pending_call_steal_reply(call);
|
|
|
|
|
|
|
|
if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) {
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("Bluetooth daemon is apparently not available.");
|
2010-01-27 19:12:49 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
|
|
|
|
if (!dbus_message_is_error(reply, DBUS_ERROR_UNKNOWN_METHOD))
|
|
|
|
ofono_info("Error from GetProperties reply: %s",
|
|
|
|
dbus_message_get_error_name(reply));
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-02-13 00:19:32 +00:00
|
|
|
parse_properties_reply(reply, "UUIDs", has_hfp_uuid, &have_hfp,
|
|
|
|
"Adapter", parse_string, &adapter,
|
2010-02-13 00:30:03 +00:00
|
|
|
"Address", parse_string, &device_addr,
|
|
|
|
"Alias", parse_string, &alias, NULL);
|
2010-02-13 00:19:32 +00:00
|
|
|
|
|
|
|
if (adapter)
|
|
|
|
adapter_addr = g_hash_table_lookup(adapter_address_hash,
|
|
|
|
adapter);
|
2010-02-12 23:52:55 +00:00
|
|
|
|
2010-02-13 00:19:32 +00:00
|
|
|
if (have_hfp && device_addr && adapter_addr)
|
2010-02-13 00:30:03 +00:00
|
|
|
hfp_create_modem(path, device_addr, adapter_addr, alias);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
dbus_message_unref(reply);
|
|
|
|
}
|
|
|
|
|
2010-02-12 21:32:53 +00:00
|
|
|
static void parse_devices(DBusMessageIter *array, gpointer user_data)
|
|
|
|
{
|
|
|
|
DBusMessageIter value;
|
|
|
|
GSList **device_list = user_data;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(array, &value);
|
|
|
|
|
|
|
|
while (dbus_message_iter_get_arg_type(&value)
|
|
|
|
== DBUS_TYPE_OBJECT_PATH) {
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&value, &path);
|
|
|
|
|
2010-02-12 23:52:55 +00:00
|
|
|
*device_list = g_slist_prepend(*device_list, (gpointer) path);
|
2010-02-12 21:32:53 +00:00
|
|
|
|
|
|
|
dbus_message_iter_next(&value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
2010-02-12 22:33:53 +00:00
|
|
|
const char *path = user_data;
|
2010-01-27 19:12:49 +00:00
|
|
|
DBusMessage *reply;
|
2010-02-12 21:32:53 +00:00
|
|
|
GSList *device_list = NULL;
|
|
|
|
GSList *l;
|
|
|
|
const char *addr;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
reply = dbus_pending_call_steal_reply(call);
|
|
|
|
|
|
|
|
if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) {
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("Bluetooth daemon is apparently not available.");
|
2010-01-27 19:12:49 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-02-12 21:32:53 +00:00
|
|
|
parse_properties_reply(reply, "Devices", parse_devices, &device_list,
|
|
|
|
"Address", parse_string, &addr, NULL);
|
|
|
|
|
2010-02-12 22:33:53 +00:00
|
|
|
DBG("Adapter Address: %s, Path: %s", addr, path);
|
|
|
|
g_hash_table_insert(adapter_address_hash,
|
|
|
|
g_strdup(path), g_strdup(addr));
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:32:53 +00:00
|
|
|
for (l = device_list; l; l = l->next) {
|
2010-02-12 23:52:55 +00:00
|
|
|
const char *device = l->data;
|
2010-02-12 21:32:53 +00:00
|
|
|
|
2010-02-12 23:52:55 +00:00
|
|
|
send_method_call_with_reply(BLUEZ_SERVICE, device,
|
2010-01-27 19:12:49 +00:00
|
|
|
BLUEZ_DEVICE_INTERFACE, "GetProperties",
|
2010-02-12 23:52:55 +00:00
|
|
|
device_properties_cb, g_strdup(device), g_free,
|
2010-02-12 22:29:59 +00:00
|
|
|
-1, DBUS_TYPE_INVALID);
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2010-02-12 21:32:53 +00:00
|
|
|
g_slist_free(device_list);
|
2010-01-27 19:12:49 +00:00
|
|
|
dbus_message_unref(reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
const char *path;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
|
2010-02-11 22:52:42 +00:00
|
|
|
ret = send_method_call_with_reply(BLUEZ_SERVICE, path,
|
2010-02-12 21:32:53 +00:00
|
|
|
BLUEZ_ADAPTER_INTERFACE, "GetProperties",
|
2010-02-12 22:33:53 +00:00
|
|
|
adapter_properties_cb, g_strdup(path), g_free,
|
2010-02-12 22:29:59 +00:00
|
|
|
-1, DBUS_TYPE_INVALID);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-12 22:33:53 +00:00
|
|
|
static gboolean adapter_removed(DBusConnection *connection,
|
|
|
|
DBusMessage *message, void *user_data)
|
|
|
|
{
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
if (dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
|
|
|
|
DBUS_TYPE_INVALID) == TRUE)
|
|
|
|
g_hash_table_remove(adapter_address_hash, path);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-13 00:42:48 +00:00
|
|
|
static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
|
2012-01-14 20:00:55 +00:00
|
|
|
void *user_data)
|
|
|
|
{
|
2010-02-12 23:52:55 +00:00
|
|
|
const char *property;
|
2012-01-14 20:00:55 +00:00
|
|
|
DBusMessageIter iter;
|
|
|
|
|
2010-02-13 00:42:48 +00:00
|
|
|
dbus_message_iter_init(msg, &iter);
|
2012-01-14 20:00:55 +00:00
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&iter, &property);
|
2010-02-12 23:52:55 +00:00
|
|
|
if (g_str_equal(property, "UUIDs") == TRUE) {
|
|
|
|
gboolean have_hfp = FALSE;
|
2010-02-13 00:42:48 +00:00
|
|
|
const char *path = dbus_message_get_path(msg);
|
|
|
|
DBusMessageIter variant;
|
2012-01-14 20:00:55 +00:00
|
|
|
|
2010-02-12 23:52:55 +00:00
|
|
|
/* We already have this device in our hash, ignore */
|
|
|
|
if (g_hash_table_lookup(uuid_hash, path) != NULL)
|
|
|
|
return TRUE;
|
2012-01-14 20:00:55 +00:00
|
|
|
|
2010-02-12 23:52:55 +00:00
|
|
|
if (!dbus_message_iter_next(&iter))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
|
|
|
|
return FALSE;
|
2012-01-14 20:00:55 +00:00
|
|
|
|
2010-02-13 00:42:48 +00:00
|
|
|
dbus_message_iter_recurse(&iter, &variant);
|
|
|
|
|
|
|
|
has_hfp_uuid(&variant, &have_hfp);
|
2010-02-12 21:44:31 +00:00
|
|
|
|
2010-02-12 23:52:55 +00:00
|
|
|
/* We need the full set of properties to be able to create
|
|
|
|
* the modem properly, including Adapter and Alias, so
|
|
|
|
* refetch everything again
|
|
|
|
*/
|
|
|
|
if (have_hfp)
|
|
|
|
send_method_call_with_reply(BLUEZ_SERVICE, path,
|
|
|
|
BLUEZ_DEVICE_INTERFACE, "GetProperties",
|
|
|
|
device_properties_cb, g_strdup(path), g_free,
|
|
|
|
-1, DBUS_TYPE_INVALID);
|
2010-02-13 00:42:48 +00:00
|
|
|
} else if (g_str_equal(property, "Alias") == TRUE) {
|
|
|
|
const char *path = dbus_message_get_path(msg);
|
|
|
|
struct ofono_modem *modem =
|
|
|
|
g_hash_table_lookup(uuid_hash, path);
|
|
|
|
const char *alias = NULL;
|
|
|
|
DBusMessageIter variant;
|
|
|
|
|
|
|
|
if (modem == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!dbus_message_iter_next(&iter))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&iter, &variant);
|
|
|
|
|
|
|
|
parse_string(&variant, &alias);
|
|
|
|
|
|
|
|
ofono_modem_set_name(modem, alias);
|
2010-02-12 23:52:55 +00:00
|
|
|
}
|
2012-01-14 20:00:55 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-12 21:05:52 +00:00
|
|
|
static void parse_adapters(DBusMessageIter *array, gpointer user_data)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
2010-02-12 21:05:52 +00:00
|
|
|
DBusMessageIter value;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:05:52 +00:00
|
|
|
DBG("");
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:05:52 +00:00
|
|
|
if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
|
|
|
|
return;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:05:52 +00:00
|
|
|
dbus_message_iter_recurse(array, &value);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:05:52 +00:00
|
|
|
while (dbus_message_iter_get_arg_type(&value)
|
|
|
|
== DBUS_TYPE_OBJECT_PATH) {
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&value, &path);
|
|
|
|
|
2010-02-12 21:32:53 +00:00
|
|
|
DBG("Calling GetProperties on %s", path);
|
2010-02-12 21:05:52 +00:00
|
|
|
|
|
|
|
send_method_call_with_reply(BLUEZ_SERVICE, path,
|
2010-02-12 21:32:53 +00:00
|
|
|
BLUEZ_ADAPTER_INTERFACE, "GetProperties",
|
2010-02-12 22:33:53 +00:00
|
|
|
adapter_properties_cb, g_strdup(path), g_free,
|
2010-02-12 22:29:59 +00:00
|
|
|
-1, DBUS_TYPE_INVALID);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 21:05:52 +00:00
|
|
|
dbus_message_iter_next(&value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void manager_properties_cb(DBusPendingCall *call, gpointer user_data)
|
|
|
|
{
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
|
|
|
reply = dbus_pending_call_steal_reply(call);
|
|
|
|
|
|
|
|
if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) {
|
|
|
|
DBG("Bluetooth daemon is apparently not available.");
|
|
|
|
goto done;
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 21:05:52 +00:00
|
|
|
parse_properties_reply(reply, "Adapters", parse_adapters, NULL, NULL);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
dbus_message_unref(reply);
|
|
|
|
}
|
|
|
|
|
2010-02-15 20:40:26 +00:00
|
|
|
static gboolean hfp_remove_each_modem(gpointer key, gpointer value, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = value;
|
|
|
|
|
|
|
|
ofono_modem_remove(modem);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
|
|
|
|
{
|
|
|
|
if (uuid_hash == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_hash_table_foreach_remove(uuid_hash, hfp_remove_each_modem, NULL);
|
|
|
|
}
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
static int hfp_register_ofono_handsfree(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
const char *obj_path = ofono_modem_get_path(modem);
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("Registering oFono Agent to bluetooth daemon");
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
return send_method_call(BLUEZ_SERVICE, data->handsfree_path,
|
|
|
|
BLUEZ_GATEWAY_INTERFACE, "RegisterAgent",
|
2010-02-11 22:52:42 +00:00
|
|
|
DBUS_TYPE_OBJECT_PATH, &obj_path,
|
|
|
|
DBUS_TYPE_INVALID);
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hfp_unregister_ofono_handsfree(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
const char *obj_path = ofono_modem_get_path(modem);
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("Unregistering oFono Agent from bluetooth daemon");
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
return send_method_call(BLUEZ_SERVICE, data->handsfree_path,
|
|
|
|
BLUEZ_GATEWAY_INTERFACE, "UnregisterAgent",
|
2010-02-11 22:52:42 +00:00
|
|
|
DBUS_TYPE_OBJECT_PATH, &obj_path,
|
|
|
|
DBUS_TYPE_INVALID);
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hfp_probe(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
const char *obj_path = ofono_modem_get_path(modem);
|
2010-02-11 22:52:41 +00:00
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return -EINVAL;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
g_dbus_register_interface(connection, obj_path, HFP_AGENT_INTERFACE,
|
|
|
|
agent_methods, NULL, NULL, modem, NULL);
|
|
|
|
|
2010-02-13 02:10:29 +00:00
|
|
|
data->agent_registered = TRUE;
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
if (hfp_register_ofono_handsfree(modem) != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_remove(struct ofono_modem *modem)
|
|
|
|
{
|
2010-01-27 19:12:49 +00:00
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
2012-01-14 20:00:56 +00:00
|
|
|
const char *obj_path = ofono_modem_get_path(modem);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2012-01-14 20:00:56 +00:00
|
|
|
if (g_dbus_unregister_interface(connection, obj_path,
|
|
|
|
HFP_AGENT_INTERFACE))
|
|
|
|
hfp_unregister_ofono_handsfree(modem);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2012-01-14 20:00:55 +00:00
|
|
|
g_hash_table_remove(uuid_hash, data->handsfree_path);
|
|
|
|
|
2010-02-04 19:13:09 +00:00
|
|
|
g_free(data->handsfree_path);
|
|
|
|
g_free(data);
|
2009-10-18 22:20:25 +00:00
|
|
|
|
|
|
|
ofono_modem_set_data(modem, NULL);
|
|
|
|
}
|
|
|
|
|
2010-02-11 22:52:42 +00:00
|
|
|
static void hfp_connect_reply(DBusPendingCall *call, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
DBusError derr;
|
|
|
|
DBusMessage *reply;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
reply = dbus_pending_call_steal_reply(call);
|
|
|
|
|
|
|
|
if (ofono_modem_get_powered(modem))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
dbus_error_init(&derr);
|
|
|
|
if (!dbus_set_error_from_message(&derr, reply))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
DBG("Connect reply: %s", derr.message);
|
|
|
|
|
|
|
|
if (dbus_error_has_name(&derr, DBUS_ERROR_NO_REPLY)) {
|
|
|
|
ret = send_method_call(BLUEZ_SERVICE, data->handsfree_path,
|
|
|
|
BLUEZ_GATEWAY_INTERFACE, "Disconnect",
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
if (ret < 0)
|
|
|
|
ofono_error("Disconnect failed(%d)", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
ofono_modem_set_powered(modem, FALSE);
|
|
|
|
|
|
|
|
dbus_error_free(&derr);
|
|
|
|
|
|
|
|
done:
|
|
|
|
dbus_message_unref(reply);
|
|
|
|
}
|
|
|
|
|
2010-02-12 18:02:39 +00:00
|
|
|
/* power up hardware */
|
|
|
|
static int hfp_enable(struct ofono_modem *modem)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
2010-02-12 18:02:39 +00:00
|
|
|
int status;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 18:02:39 +00:00
|
|
|
DBG("%p", modem);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-12 18:02:39 +00:00
|
|
|
status = send_method_call_with_reply(BLUEZ_SERVICE,
|
|
|
|
data->handsfree_path,
|
2010-01-27 19:12:49 +00:00
|
|
|
BLUEZ_GATEWAY_INTERFACE, "Connect",
|
2010-02-12 22:29:59 +00:00
|
|
|
hfp_connect_reply, modem, NULL,
|
|
|
|
15, DBUS_TYPE_INVALID);
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2010-02-12 18:02:39 +00:00
|
|
|
if (status < 0)
|
2009-10-18 22:20:25 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
|
2012-01-14 20:00:57 +00:00
|
|
|
static void hfp_power_down(DBusPendingCall *call, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
DBusMessage *reply;
|
|
|
|
DBusError derr;
|
|
|
|
|
|
|
|
reply = dbus_pending_call_steal_reply(call);
|
|
|
|
|
|
|
|
dbus_error_init(&derr);
|
|
|
|
if (dbus_set_error_from_message(&derr, reply)) {
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("Disconnect reply: %s", derr.message);
|
2012-01-14 20:00:57 +00:00
|
|
|
dbus_error_free(&derr);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofono_modem_set_powered(modem, FALSE);
|
|
|
|
|
|
|
|
done:
|
|
|
|
dbus_message_unref(reply);
|
|
|
|
}
|
|
|
|
|
2010-02-12 17:58:49 +00:00
|
|
|
static int hfp_disable(struct ofono_modem *modem)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
2010-02-12 17:58:49 +00:00
|
|
|
int status;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
DBG("%p", modem);
|
|
|
|
|
2010-02-04 19:13:09 +00:00
|
|
|
clear_data(modem);
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2010-02-13 02:10:29 +00:00
|
|
|
if (data->agent_registered) {
|
2010-02-12 23:31:40 +00:00
|
|
|
status = send_method_call_with_reply(BLUEZ_SERVICE,
|
|
|
|
data->handsfree_path,
|
|
|
|
BLUEZ_GATEWAY_INTERFACE, "Disconnect",
|
|
|
|
hfp_power_down, modem, NULL, 15,
|
|
|
|
DBUS_TYPE_INVALID);
|
2010-02-12 17:58:49 +00:00
|
|
|
|
2010-02-12 23:31:40 +00:00
|
|
|
if (status < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-01-14 20:00:57 +00:00
|
|
|
|
|
|
|
return -EINPROGRESS;
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_pre_sim(struct ofono_modem *modem)
|
|
|
|
{
|
2009-10-28 11:01:24 +00:00
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
DBG("%p", modem);
|
2009-11-03 17:57:43 +00:00
|
|
|
|
2009-10-28 11:01:24 +00:00
|
|
|
ofono_voicecall_create(modem, 0, "hfpmodem", data);
|
2009-11-03 17:44:36 +00:00
|
|
|
ofono_netreg_create(modem, 0, "hfpmodem", data);
|
2009-11-08 17:15:59 +00:00
|
|
|
ofono_call_volume_create(modem, 0, "hfpmodem", data);
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_post_sim(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
DBG("%p", modem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ofono_modem_driver hfp_driver = {
|
|
|
|
.name = "hfp",
|
|
|
|
.probe = hfp_probe,
|
|
|
|
.remove = hfp_remove,
|
|
|
|
.enable = hfp_enable,
|
|
|
|
.disable = hfp_disable,
|
|
|
|
.pre_sim = hfp_pre_sim,
|
|
|
|
.post_sim = hfp_post_sim,
|
|
|
|
};
|
|
|
|
|
2010-02-15 20:40:26 +00:00
|
|
|
static guint bluetooth_exit_watch;
|
2010-02-12 22:33:53 +00:00
|
|
|
static guint adapter_added_watch;
|
|
|
|
static guint adapter_removed_watch;
|
2012-01-14 20:00:55 +00:00
|
|
|
static guint uuid_watch;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-05 23:24:18 +00:00
|
|
|
static int hfp_init()
|
2009-10-18 22:20:25 +00:00
|
|
|
{
|
2010-01-27 19:12:49 +00:00
|
|
|
int err;
|
|
|
|
|
2010-01-27 20:16:26 +00:00
|
|
|
if (DBUS_TYPE_UNIX_FD < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
connection = ofono_dbus_get_connection();
|
|
|
|
|
2010-02-15 20:40:26 +00:00
|
|
|
bluetooth_exit_watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
|
|
|
|
NULL, bluetooth_disconnect, NULL, NULL);
|
|
|
|
|
2010-02-12 22:33:53 +00:00
|
|
|
adapter_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
|
2010-01-27 19:12:49 +00:00
|
|
|
BLUEZ_MANAGER_INTERFACE,
|
|
|
|
"AdapterAdded",
|
|
|
|
adapter_added, NULL, NULL);
|
|
|
|
|
2010-02-12 22:33:53 +00:00
|
|
|
adapter_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
|
|
|
|
BLUEZ_MANAGER_INTERFACE,
|
|
|
|
"AdapterRemoved",
|
|
|
|
adapter_removed, NULL, NULL);
|
|
|
|
|
2012-01-14 20:00:55 +00:00
|
|
|
uuid_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
|
|
|
|
BLUEZ_DEVICE_INTERFACE,
|
|
|
|
"PropertyChanged",
|
2010-02-13 00:42:48 +00:00
|
|
|
property_changed, NULL, NULL);
|
2012-01-14 20:00:55 +00:00
|
|
|
|
2010-02-15 20:40:26 +00:00
|
|
|
if (bluetooth_exit_watch == 0 || adapter_added_watch == 0 ||
|
|
|
|
adapter_removed_watch == 0|| uuid_watch == 0) {
|
2010-01-27 19:12:49 +00:00
|
|
|
err = -EIO;
|
|
|
|
goto remove;
|
|
|
|
}
|
|
|
|
|
2010-02-12 22:05:09 +00:00
|
|
|
uuid_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
|
2010-02-12 23:57:10 +00:00
|
|
|
g_free, NULL);
|
2010-02-12 22:05:09 +00:00
|
|
|
|
2010-02-12 22:33:53 +00:00
|
|
|
adapter_address_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
|
|
g_free, g_free);
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
err = ofono_modem_driver_register(&hfp_driver);
|
|
|
|
if (err < 0)
|
|
|
|
goto remove;
|
|
|
|
|
2010-02-12 17:27:02 +00:00
|
|
|
send_method_call_with_reply(BLUEZ_SERVICE, "/",
|
2010-02-12 21:05:52 +00:00
|
|
|
BLUEZ_MANAGER_INTERFACE, "GetProperties",
|
2010-02-12 22:33:53 +00:00
|
|
|
manager_properties_cb, NULL, NULL, -1,
|
2010-02-12 21:05:52 +00:00
|
|
|
DBUS_TYPE_INVALID);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
remove:
|
2010-02-15 20:40:26 +00:00
|
|
|
g_dbus_remove_watch(connection, bluetooth_exit_watch);
|
2010-02-12 22:33:53 +00:00
|
|
|
g_dbus_remove_watch(connection, adapter_added_watch);
|
|
|
|
g_dbus_remove_watch(connection, adapter_removed_watch);
|
2012-01-14 20:00:55 +00:00
|
|
|
g_dbus_remove_watch(connection, uuid_watch);
|
2010-02-12 22:33:53 +00:00
|
|
|
|
|
|
|
if (uuid_hash)
|
|
|
|
g_hash_table_destroy(uuid_hash);
|
|
|
|
|
|
|
|
if (adapter_address_hash)
|
|
|
|
g_hash_table_destroy(adapter_address_hash);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
|
|
|
return err;
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-05 23:24:18 +00:00
|
|
|
static void hfp_exit()
|
2009-10-18 22:20:25 +00:00
|
|
|
{
|
2010-02-15 20:40:26 +00:00
|
|
|
g_dbus_remove_watch(connection, bluetooth_exit_watch);
|
2010-02-12 22:33:53 +00:00
|
|
|
g_dbus_remove_watch(connection, adapter_added_watch);
|
|
|
|
g_dbus_remove_watch(connection, adapter_removed_watch);
|
2012-01-14 20:00:55 +00:00
|
|
|
g_dbus_remove_watch(connection, uuid_watch);
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
ofono_modem_driver_unregister(&hfp_driver);
|
2012-01-14 20:00:55 +00:00
|
|
|
|
|
|
|
g_hash_table_destroy(uuid_hash);
|
2010-02-12 22:33:53 +00:00
|
|
|
g_hash_table_destroy(adapter_address_hash);
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OFONO_PLUGIN_DEFINE(hfp, "Hands-Free Profile Plugins", VERSION,
|
|
|
|
OFONO_PLUGIN_PRIORITY_DEFAULT, hfp_init, hfp_exit)
|