2009-10-18 22:20:25 +00:00
|
|
|
/*
|
2010-10-01 04:51:34 +00:00
|
|
|
*
|
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
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
#include <drivers/hfpmodem/slc.h>
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
#include <ofono/dbus.h>
|
|
|
|
|
2010-06-14 18:04:22 +00:00
|
|
|
#include "bluetooth.h"
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
#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
|
|
|
|
|
|
|
#ifndef DBUS_TYPE_UNIX_FD
|
|
|
|
#define DBUS_TYPE_UNIX_FD -1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static DBusConnection *connection;
|
2010-06-20 08:51:23 +00:00
|
|
|
static GHashTable *modem_hash = NULL;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
struct hfp_data {
|
|
|
|
struct hfp_slc_info info;
|
|
|
|
char *handsfree_path;
|
|
|
|
DBusMessage *slc_msg;
|
|
|
|
gboolean agent_registered;
|
|
|
|
};
|
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
static void hfp_debug(const char *str, void *user_data)
|
|
|
|
{
|
2010-09-24 05:14:04 +00:00
|
|
|
const char *prefix = user_data;
|
|
|
|
|
|
|
|
ofono_info("%s%s", prefix, str);
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
static void slc_established(gpointer userdata)
|
2010-02-04 19:13:09 +00:00
|
|
|
{
|
2011-07-20 19:55:31 +00:00
|
|
|
struct ofono_modem *modem = userdata;
|
2010-02-04 19:13:09 +00:00
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
2010-01-27 19:12:49 +00:00
|
|
|
DBusMessage *msg;
|
2009-11-25 05:48:43 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
static void slc_failed(gpointer userdata)
|
2010-02-04 18:57:26 +00:00
|
|
|
{
|
2011-07-20 19:55:31 +00:00
|
|
|
struct ofono_modem *modem = userdata;
|
2010-02-04 18:57:26 +00:00
|
|
|
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);
|
2009-11-25 05:47:16 +00:00
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
g_at_chat_unref(data->info.chat);
|
|
|
|
data->info.chat = NULL;
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-15 20:40:25 +00:00
|
|
|
static void hfp_disconnected_cb(gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
2011-07-20 19:55:31 +00:00
|
|
|
struct hfp_data *data = ofono_modem_get_data(modem);
|
2010-02-15 20:40:25 +00:00
|
|
|
|
|
|
|
ofono_modem_set_powered(modem, FALSE);
|
2011-07-20 19:55:31 +00:00
|
|
|
|
|
|
|
g_at_chat_unref(data->info.chat);
|
|
|
|
data->info.chat = NULL;
|
2010-02-15 20:40:25 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2010-01-27 19:12:49 +00:00
|
|
|
io = g_io_channel_unix_new(fd);
|
2010-11-27 19:39:02 +00:00
|
|
|
if (io == NULL) {
|
2009-10-18 22:20:25 +00:00
|
|
|
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);
|
|
|
|
|
2010-11-27 19:39:02 +00:00
|
|
|
if (chat == NULL)
|
2009-10-18 22:20:25 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-02-15 20:40:25 +00:00
|
|
|
g_at_chat_set_disconnect_function(chat, hfp_disconnected_cb, modem);
|
|
|
|
|
2009-10-18 22:20:25 +00:00
|
|
|
if (getenv("OFONO_AT_DEBUG"))
|
2010-09-24 05:14:04 +00:00
|
|
|
g_at_chat_set_debug(chat, hfp_debug, "");
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
data->info.chat = chat;
|
|
|
|
hfp_slc_establish(&data->info, slc_established, slc_failed, modem);
|
2009-10-18 22:20:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2011-07-04 07:32:16 +00:00
|
|
|
static int hfp_hf_probe(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-06-20 08:51:23 +00:00
|
|
|
/* We already have this device in our hash, ignore */
|
|
|
|
if (g_hash_table_lookup(modem_hash, device) != NULL)
|
|
|
|
return -EALREADY;
|
|
|
|
|
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/");
|
2010-06-14 18:04:27 +00:00
|
|
|
bluetooth_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);
|
2010-11-27 19:39:02 +00:00
|
|
|
if (data == NULL)
|
2010-02-04 18:58:18 +00:00
|
|
|
goto free;
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
hfp_slc_info_init(&data->info);
|
2009-10-19 21:59:44 +00:00
|
|
|
|
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-06-20 08:51:23 +00:00
|
|
|
g_hash_table_insert(modem_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
|
|
|
}
|
|
|
|
|
2011-07-04 07:32:16 +00:00
|
|
|
static gboolean hfp_remove_modem(gpointer key, gpointer value,
|
2010-06-22 03:53:05 +00:00
|
|
|
gpointer user_data)
|
2012-01-14 20:00:55 +00:00
|
|
|
{
|
2010-06-20 08:51:23 +00:00
|
|
|
struct ofono_modem *modem = value;
|
2011-07-04 07:32:16 +00:00
|
|
|
const char *device = key;
|
|
|
|
const char *prefix = user_data;
|
|
|
|
|
|
|
|
if (prefix && g_str_has_prefix(device, prefix) == FALSE)
|
|
|
|
return FALSE;
|
2010-02-13 00:42:48 +00:00
|
|
|
|
2010-06-20 08:51:23 +00:00
|
|
|
ofono_modem_remove(modem);
|
2012-01-14 20:00:55 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-04 07:32:16 +00:00
|
|
|
static void hfp_hf_remove(const char *prefix)
|
2010-01-27 19:12:49 +00:00
|
|
|
{
|
2011-07-04 07:32:16 +00:00
|
|
|
DBG("%s", prefix);
|
|
|
|
|
2010-06-20 08:51:23 +00:00
|
|
|
if (modem_hash == NULL)
|
2010-02-12 21:05:52 +00:00
|
|
|
return;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2011-07-04 07:32:16 +00:00
|
|
|
g_hash_table_foreach_remove(modem_hash, hfp_remove_modem,
|
|
|
|
(gpointer) prefix);
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-04 07:32:16 +00:00
|
|
|
static void hfp_hf_set_alias(const char *device, const char *alias)
|
2010-02-15 20:40:26 +00:00
|
|
|
{
|
2010-06-20 08:51:23 +00:00
|
|
|
struct ofono_modem *modem;
|
2010-02-15 20:40:26 +00:00
|
|
|
|
2010-11-27 19:39:02 +00:00
|
|
|
if (device == NULL || alias == NULL)
|
2010-06-20 08:51:23 +00:00
|
|
|
return;
|
2010-02-15 20:40:26 +00:00
|
|
|
|
2010-06-20 08:51:23 +00:00
|
|
|
modem = g_hash_table_lookup(modem_hash, device);
|
2010-11-27 19:39:02 +00:00
|
|
|
if (modem == NULL)
|
2010-02-15 20:40:26 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-20 08:51:23 +00:00
|
|
|
ofono_modem_set_name(modem, alias);
|
2010-02-15 20:40:26 +00:00
|
|
|
}
|
|
|
|
|
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-06-14 18:04:26 +00:00
|
|
|
DBusMessage *msg;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("Registering oFono Agent to bluetooth daemon");
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-06-14 18:04:26 +00:00
|
|
|
msg = dbus_message_new_method_call(BLUEZ_SERVICE, data->handsfree_path,
|
|
|
|
BLUEZ_GATEWAY_INTERFACE, "RegisterAgent");
|
2010-11-27 19:39:02 +00:00
|
|
|
if (msg == NULL)
|
2010-06-14 18:04:26 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &obj_path,
|
2010-02-11 22:52:42 +00:00
|
|
|
DBUS_TYPE_INVALID);
|
2010-06-14 18:04:26 +00:00
|
|
|
|
|
|
|
g_dbus_send_message(connection, msg);
|
|
|
|
return 0;
|
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-06-14 18:04:26 +00:00
|
|
|
DBusMessage *msg;
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
DBG("Unregistering oFono Agent from bluetooth daemon");
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2010-06-14 18:04:26 +00:00
|
|
|
msg = dbus_message_new_method_call(BLUEZ_SERVICE, data->handsfree_path,
|
|
|
|
BLUEZ_GATEWAY_INTERFACE, "UnregisterAgent");
|
2010-11-27 19:39:02 +00:00
|
|
|
if (msg == NULL)
|
2010-06-14 18:04:26 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &obj_path,
|
2010-02-11 22:52:42 +00:00
|
|
|
DBUS_TYPE_INVALID);
|
2010-06-14 18:04:26 +00:00
|
|
|
|
|
|
|
g_dbus_send_message(connection, msg);
|
|
|
|
return 0;
|
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);
|
|
|
|
|
2010-11-27 19:39:02 +00:00
|
|
|
if (data == NULL)
|
2010-02-11 22:52:41 +00:00
|
|
|
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
|
|
|
|
2010-06-20 08:51:23 +00:00
|
|
|
g_hash_table_remove(modem_hash, data->handsfree_path);
|
2012-01-14 20:00:55 +00:00
|
|
|
|
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;
|
2010-06-14 18:04:26 +00:00
|
|
|
DBusMessage *reply, *msg;
|
2010-02-11 22:52:42 +00:00
|
|
|
|
|
|
|
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)) {
|
2010-06-14 18:04:26 +00:00
|
|
|
msg = dbus_message_new_method_call(BLUEZ_SERVICE,
|
|
|
|
data->handsfree_path,
|
|
|
|
BLUEZ_GATEWAY_INTERFACE, "Disconnect");
|
2010-11-27 19:39:02 +00:00
|
|
|
if (msg == NULL)
|
2010-06-14 18:04:26 +00:00
|
|
|
ofono_error("Disconnect failed");
|
|
|
|
else
|
|
|
|
g_dbus_send_message(connection, msg);
|
2010-02-11 22:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06-17 10:23:11 +00:00
|
|
|
status = bluetooth_send_with_reply(data->handsfree_path,
|
|
|
|
BLUEZ_GATEWAY_INTERFACE, "Connect",
|
|
|
|
hfp_connect_reply, modem, NULL,
|
2010-08-04 10:22:10 +00:00
|
|
|
DBUS_TIMEOUT, 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);
|
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
g_at_chat_unref(data->info.chat);
|
|
|
|
data->info.chat = NULL;
|
2009-10-18 22:20:25 +00:00
|
|
|
|
2010-02-13 02:10:29 +00:00
|
|
|
if (data->agent_registered) {
|
2010-06-17 10:23:11 +00:00
|
|
|
status = bluetooth_send_with_reply(data->handsfree_path,
|
2010-02-12 23:31:40 +00:00
|
|
|
BLUEZ_GATEWAY_INTERFACE, "Disconnect",
|
2010-08-04 10:22:10 +00:00
|
|
|
hfp_power_down, modem, NULL,
|
|
|
|
DBUS_TIMEOUT, 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
|
|
|
|
2011-07-20 19:55:31 +00:00
|
|
|
ofono_voicecall_create(modem, 0, "hfpmodem", &data->info);
|
|
|
|
ofono_netreg_create(modem, 0, "hfpmodem", &data->info);
|
|
|
|
ofono_call_volume_create(modem, 0, "hfpmodem", &data->info);
|
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,
|
|
|
|
};
|
|
|
|
|
2011-07-04 07:32:16 +00:00
|
|
|
static struct bluetooth_profile hfp_hf = {
|
|
|
|
.name = "hfp_hf",
|
|
|
|
.probe = hfp_hf_probe,
|
|
|
|
.remove = hfp_hf_remove,
|
|
|
|
.set_alias = hfp_hf_set_alias,
|
2010-06-20 08:51:23 +00:00
|
|
|
};
|
2010-01-27 19:12:49 +00:00
|
|
|
|
2011-01-12 10:52:16 +00:00
|
|
|
static int hfp_init(void)
|
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-06-20 08:51:23 +00:00
|
|
|
err = ofono_modem_driver_register(&hfp_driver);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2012-01-14 20:00:55 +00:00
|
|
|
|
2011-07-04 07:32:16 +00:00
|
|
|
err = bluetooth_register_uuid(HFP_AG_UUID, &hfp_hf);
|
2010-06-20 08:51:23 +00:00
|
|
|
if (err < 0) {
|
|
|
|
ofono_modem_driver_unregister(&hfp_driver);
|
|
|
|
return err;
|
2010-01-27 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-20 08:51:23 +00:00
|
|
|
modem_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-01-27 19:12:49 +00:00
|
|
|
return 0;
|
2009-10-18 22:20:25 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 10:52:16 +00:00
|
|
|
static void hfp_exit(void)
|
2009-10-18 22:20:25 +00:00
|
|
|
{
|
2010-06-20 08:51:23 +00:00
|
|
|
bluetooth_unregister_uuid(HFP_AG_UUID);
|
2009-10-18 22:20:25 +00:00
|
|
|
ofono_modem_driver_unregister(&hfp_driver);
|
2012-01-14 20:00:55 +00:00
|
|
|
|
2010-06-20 08:51:23 +00:00
|
|
|
g_hash_table_destroy(modem_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)
|