2013-02-20 21:55:45 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 <errno.h>
|
|
|
|
#include <stdio.h>
|
2013-03-04 20:48:49 +00:00
|
|
|
#include <stdint.h>
|
2013-03-12 12:42:05 +00:00
|
|
|
#include <stdlib.h>
|
2013-02-20 21:55:50 +00:00
|
|
|
#include <string.h>
|
2013-03-04 20:48:49 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/socket.h>
|
2013-02-20 21:55:45 +00:00
|
|
|
|
|
|
|
#include <gdbus.h>
|
|
|
|
|
2013-02-21 14:27:55 +00:00
|
|
|
#include <ofono/handsfree-audio.h>
|
|
|
|
|
2013-03-04 20:48:49 +00:00
|
|
|
#include "bluetooth.h"
|
2013-04-09 04:58:49 +00:00
|
|
|
#include "hfp.h"
|
2013-02-20 21:55:45 +00:00
|
|
|
#include "ofono.h"
|
|
|
|
|
2013-02-21 03:28:01 +00:00
|
|
|
#define HFP_AUDIO_MANAGER_INTERFACE OFONO_SERVICE ".HandsfreeAudioManager"
|
|
|
|
#define HFP_AUDIO_AGENT_INTERFACE OFONO_SERVICE ".HandsfreeAudioAgent"
|
2013-02-26 19:22:02 +00:00
|
|
|
#define HFP_AUDIO_CARD_INTERFACE OFONO_SERVICE ".HandsfreeAudioCard"
|
2013-02-20 21:55:45 +00:00
|
|
|
|
2013-02-26 17:03:00 +00:00
|
|
|
struct ofono_handsfree_card {
|
2015-10-05 11:33:09 +00:00
|
|
|
enum ofono_handsfree_card_type type;
|
2013-02-26 17:03:00 +00:00
|
|
|
char *remote;
|
|
|
|
char *local;
|
2013-02-26 19:22:02 +00:00
|
|
|
char *path;
|
2013-03-25 22:05:18 +00:00
|
|
|
DBusMessage *msg;
|
2013-04-15 13:54:49 +00:00
|
|
|
unsigned char selected_codec;
|
2013-03-18 18:42:00 +00:00
|
|
|
const struct ofono_handsfree_card_driver *driver;
|
2013-03-13 18:14:39 +00:00
|
|
|
void *driver_data;
|
2013-02-26 17:03:00 +00:00
|
|
|
};
|
|
|
|
|
2013-02-20 21:55:46 +00:00
|
|
|
struct agent {
|
|
|
|
char *owner;
|
|
|
|
char *path;
|
2013-02-20 21:55:51 +00:00
|
|
|
guint watch;
|
2013-02-20 21:55:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct agent *agent = NULL;
|
2013-02-21 14:27:55 +00:00
|
|
|
static int ref_count = 0;
|
2013-02-26 17:03:00 +00:00
|
|
|
static GSList *card_list = 0;
|
2013-03-04 20:48:49 +00:00
|
|
|
static guint sco_watch = 0;
|
2013-03-13 18:01:55 +00:00
|
|
|
static GSList *drivers = 0;
|
2013-04-08 22:41:00 +00:00
|
|
|
static ofono_bool_t has_wideband = FALSE;
|
2013-04-15 13:54:52 +00:00
|
|
|
static int defer_setup = 1;
|
2013-09-11 00:09:41 +00:00
|
|
|
static ofono_bool_t transparent_sco = FALSE;
|
2013-03-04 20:48:49 +00:00
|
|
|
|
2015-10-05 11:33:09 +00:00
|
|
|
static const char *card_type_to_string(enum ofono_handsfree_card_type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case OFONO_HANDSFREE_CARD_TYPE_HANDSFREE:
|
|
|
|
return "handsfree";
|
|
|
|
case OFONO_HANDSFREE_CARD_TYPE_GATEWAY:
|
|
|
|
return "gateway";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-09-11 00:09:40 +00:00
|
|
|
static uint16_t codec2setting(uint8_t codec)
|
|
|
|
{
|
|
|
|
switch (codec) {
|
2014-09-20 14:13:45 +00:00
|
|
|
case HFP_CODEC_CVSD:
|
|
|
|
return BT_VOICE_CVSD_16BIT;
|
|
|
|
default:
|
|
|
|
return BT_VOICE_TRANSPARENT;
|
2013-09-11 00:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ofono_bool_t apply_settings_from_codec(int fd, uint8_t codec)
|
|
|
|
{
|
|
|
|
struct bt_voice voice;
|
|
|
|
|
|
|
|
memset(&voice, 0, sizeof(voice));
|
|
|
|
voice.setting = codec2setting(codec);
|
|
|
|
|
2013-09-12 18:07:33 +00:00
|
|
|
/* CVSD is the default, no need to set BT_VOICE. */
|
|
|
|
if (voice.setting == BT_VOICE_CVSD_16BIT)
|
|
|
|
return TRUE;
|
|
|
|
|
2013-09-11 00:09:40 +00:00
|
|
|
if (setsockopt(fd, SOL_BLUETOOTH, BT_VOICE, &voice, sizeof(voice)) < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:54:51 +00:00
|
|
|
static void send_new_connection(const char *card, int fd, uint8_t codec)
|
2013-03-04 20:48:50 +00:00
|
|
|
{
|
|
|
|
DBusMessage *msg;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
2015-04-22 22:12:48 +00:00
|
|
|
DBG("%p, fd: %d, codec: %hu", card, fd, codec);
|
|
|
|
|
2013-03-04 20:48:50 +00:00
|
|
|
msg = dbus_message_new_method_call(agent->owner, agent->path,
|
|
|
|
HFP_AUDIO_AGENT_INTERFACE, "NewConnection");
|
|
|
|
if (msg == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dbus_message_iter_init_append(msg, &iter);
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &card);
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_UNIX_FD, &fd);
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &codec);
|
|
|
|
|
|
|
|
g_dbus_send_message(ofono_dbus_get_connection(), msg);
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:48:51 +00:00
|
|
|
static struct ofono_handsfree_card *card_find(const char *remote,
|
|
|
|
const char *local)
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
for (list = card_list; list; list = g_slist_next(list)) {
|
|
|
|
struct ofono_handsfree_card *card = list->data;
|
|
|
|
|
|
|
|
if (g_str_equal(card->remote, remote) &&
|
|
|
|
g_str_equal(card->local, local))
|
|
|
|
return card;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:48:49 +00:00
|
|
|
static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2013-03-04 20:48:50 +00:00
|
|
|
struct ofono_handsfree_card *card;
|
2013-03-04 20:48:49 +00:00
|
|
|
struct sockaddr_sco saddr;
|
|
|
|
socklen_t alen;
|
|
|
|
int sk, nsk;
|
2013-03-04 20:48:51 +00:00
|
|
|
char local[18], remote[18];
|
2013-03-04 20:48:49 +00:00
|
|
|
|
|
|
|
if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
sk = g_io_channel_unix_get_fd(io);
|
|
|
|
|
|
|
|
memset(&saddr, 0, sizeof(saddr));
|
|
|
|
alen = sizeof(saddr);
|
|
|
|
|
|
|
|
nsk = accept(sk, (struct sockaddr *) &saddr, &alen);
|
|
|
|
if (nsk < 0)
|
|
|
|
return TRUE;
|
|
|
|
|
2013-03-04 20:48:53 +00:00
|
|
|
if (agent == NULL) {
|
|
|
|
ofono_error("Reject SCO: Agent not registered");
|
|
|
|
close(nsk);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:48:49 +00:00
|
|
|
bt_ba2str(&saddr.sco_bdaddr, remote);
|
|
|
|
|
2013-03-04 20:48:51 +00:00
|
|
|
memset(&saddr, 0, sizeof(saddr));
|
|
|
|
alen = sizeof(saddr);
|
|
|
|
|
|
|
|
if (getsockname(nsk, (struct sockaddr *) &saddr, &alen) < 0) {
|
|
|
|
ofono_error("SCO getsockname(): %s (%d)",
|
|
|
|
strerror(errno), errno);
|
|
|
|
close(nsk);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_ba2str(&saddr.sco_bdaddr, local);
|
|
|
|
|
|
|
|
card = card_find(remote, local);
|
2013-03-04 20:48:52 +00:00
|
|
|
if (card == NULL || card->path == NULL) {
|
2013-03-04 20:48:49 +00:00
|
|
|
ofono_error("Rejecting SCO: Audio Card not found!");
|
|
|
|
close(nsk);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-09-11 00:09:40 +00:00
|
|
|
if (apply_settings_from_codec(nsk, card->selected_codec) == FALSE) {
|
|
|
|
close(nsk);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:12:48 +00:00
|
|
|
DBG("SCO connection setup between local: %s and remote: %s",
|
|
|
|
local, remote);
|
|
|
|
|
2013-04-15 13:54:51 +00:00
|
|
|
send_new_connection(card->path, nsk, card->selected_codec);
|
2013-03-04 20:48:50 +00:00
|
|
|
close(nsk);
|
|
|
|
|
2016-08-24 01:34:52 +00:00
|
|
|
if (card->driver && card->driver->sco_connected_hint)
|
2015-04-22 22:58:50 +00:00
|
|
|
card->driver->sco_connected_hint(card);
|
|
|
|
|
2013-03-04 20:48:49 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sco_init(void)
|
|
|
|
{
|
|
|
|
GIOChannel *sco_io;
|
|
|
|
struct sockaddr_sco saddr;
|
2013-09-11 00:09:41 +00:00
|
|
|
struct bt_voice voice;
|
2013-04-15 13:54:52 +00:00
|
|
|
int sk;
|
2013-09-11 00:09:41 +00:00
|
|
|
socklen_t len;
|
2013-03-04 20:48:49 +00:00
|
|
|
|
|
|
|
sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | O_NONBLOCK | SOCK_CLOEXEC,
|
|
|
|
BTPROTO_SCO);
|
|
|
|
if (sk < 0)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
/* Bind to local address */
|
|
|
|
memset(&saddr, 0, sizeof(saddr));
|
|
|
|
saddr.sco_family = AF_BLUETOOTH;
|
|
|
|
bt_bacpy(&saddr.sco_bdaddr, BDADDR_ANY);
|
|
|
|
|
|
|
|
if (bind(sk, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
|
|
|
|
close(sk);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setsockopt(sk, SOL_BLUETOOTH, BT_DEFER_SETUP,
|
2013-04-15 13:54:52 +00:00
|
|
|
&defer_setup, sizeof(defer_setup)) < 0) {
|
2013-09-11 00:09:44 +00:00
|
|
|
int err = -errno;
|
2013-04-15 13:54:52 +00:00
|
|
|
defer_setup = 0;
|
2013-03-04 20:48:49 +00:00
|
|
|
ofono_warn("Can't enable deferred setup: %s (%d)",
|
|
|
|
strerror(errno), errno);
|
2013-09-11 00:09:44 +00:00
|
|
|
close(sk);
|
|
|
|
return err;
|
2013-04-15 13:54:52 +00:00
|
|
|
}
|
2013-03-04 20:48:49 +00:00
|
|
|
|
2013-09-11 00:09:41 +00:00
|
|
|
memset(&voice, 0, sizeof(voice));
|
|
|
|
len = sizeof(voice);
|
|
|
|
|
|
|
|
if (defer_setup && getsockopt(sk, SOL_BLUETOOTH, BT_VOICE,
|
|
|
|
&voice, &len) == 0)
|
|
|
|
transparent_sco = TRUE;
|
|
|
|
|
2013-03-04 20:48:49 +00:00
|
|
|
if (listen(sk, 5) < 0) {
|
|
|
|
close(sk);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
sco_io = g_io_channel_unix_new(sk);
|
|
|
|
sco_watch = g_io_add_watch(sco_io,
|
|
|
|
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
|
|
|
|
sco_accept, NULL);
|
|
|
|
|
|
|
|
g_io_channel_unref(sco_io);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-26 17:03:00 +00:00
|
|
|
|
2013-02-26 19:35:38 +00:00
|
|
|
static void card_append_properties(struct ofono_handsfree_card *card,
|
|
|
|
DBusMessageIter *dict)
|
|
|
|
{
|
2015-10-05 11:33:09 +00:00
|
|
|
const char *type;
|
|
|
|
|
|
|
|
type = card_type_to_string(card->type);
|
|
|
|
ofono_dbus_dict_append(dict, "Type",
|
|
|
|
DBUS_TYPE_STRING, &type);
|
|
|
|
|
2013-02-26 19:35:38 +00:00
|
|
|
ofono_dbus_dict_append(dict, "RemoteAddress",
|
|
|
|
DBUS_TYPE_STRING, &card->remote);
|
|
|
|
|
|
|
|
ofono_dbus_dict_append(dict, "LocalAddress",
|
|
|
|
DBUS_TYPE_STRING, &card->local);
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:22:02 +00:00
|
|
|
static DBusMessage *card_get_properties(DBusConnection *conn,
|
|
|
|
DBusMessage *msg, void *data)
|
|
|
|
{
|
2013-02-26 19:35:38 +00:00
|
|
|
struct ofono_handsfree_card *card = data;
|
|
|
|
DBusMessage *reply;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
DBusMessageIter dict;
|
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (reply == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
|
|
|
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
|
|
|
OFONO_PROPERTIES_ARRAY_SIGNATURE,
|
|
|
|
&dict);
|
|
|
|
|
|
|
|
card_append_properties(card, &dict);
|
|
|
|
|
|
|
|
dbus_message_iter_close_container(&iter, &dict);
|
|
|
|
|
|
|
|
return reply;
|
2013-02-26 19:22:02 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 22:05:18 +00:00
|
|
|
static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
|
|
|
|
gpointer user_data)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct ofono_handsfree_card *card = user_data;
|
|
|
|
DBusMessage *reply;
|
|
|
|
int sk;
|
|
|
|
|
|
|
|
if (agent == NULL) {
|
|
|
|
/* There's no agent, so there's no one to reply to */
|
|
|
|
reply = NULL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
|
2013-05-03 00:47:16 +00:00
|
|
|
if (card->msg)
|
|
|
|
reply = __ofono_error_failed(card->msg);
|
2013-03-25 22:05:18 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
sk = g_io_channel_unix_get_fd(io);
|
|
|
|
|
2017-05-04 08:22:36 +00:00
|
|
|
if (card->msg && dbus_message_has_member(card->msg, "Acquire")) {
|
|
|
|
reply = g_dbus_create_reply(card->msg, DBUS_TYPE_UNIX_FD, &sk,
|
|
|
|
DBUS_TYPE_BYTE, &card->selected_codec,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:54:51 +00:00
|
|
|
send_new_connection(card->path, sk, card->selected_codec);
|
2013-03-25 22:05:19 +00:00
|
|
|
|
2013-03-25 22:05:18 +00:00
|
|
|
close(sk);
|
|
|
|
|
2013-05-03 00:47:16 +00:00
|
|
|
if (card->msg)
|
|
|
|
reply = dbus_message_new_method_return(card->msg);
|
2013-03-25 22:05:18 +00:00
|
|
|
|
|
|
|
done:
|
2013-05-03 00:47:16 +00:00
|
|
|
if (card->msg == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-03-25 22:05:18 +00:00
|
|
|
if (reply)
|
|
|
|
g_dbus_send_message(ofono_dbus_get_connection(), reply);
|
|
|
|
|
|
|
|
dbus_message_unref(card->msg);
|
|
|
|
card->msg = NULL;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-03-28 00:13:01 +00:00
|
|
|
static void card_connect_reply_cb(const struct ofono_error *error, void *data)
|
|
|
|
{
|
|
|
|
struct ofono_handsfree_card *card = data;
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
|
|
|
if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
|
|
|
|
reply = dbus_message_new_method_return(card->msg);
|
|
|
|
else
|
|
|
|
reply = __ofono_error_failed(card->msg);
|
|
|
|
|
|
|
|
__ofono_dbus_pending_reply(&card->msg, reply);
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:22:02 +00:00
|
|
|
static DBusMessage *card_connect(DBusConnection *conn,
|
|
|
|
DBusMessage *msg, void *data)
|
|
|
|
{
|
2013-03-25 22:05:18 +00:00
|
|
|
struct ofono_handsfree_card *card = data;
|
2013-03-28 00:13:01 +00:00
|
|
|
const struct ofono_handsfree_card_driver *driver = card->driver;
|
2013-03-25 22:05:20 +00:00
|
|
|
const char *sender;
|
2013-03-28 00:13:00 +00:00
|
|
|
int err;
|
2013-03-25 22:05:18 +00:00
|
|
|
|
|
|
|
if (agent == NULL)
|
|
|
|
return __ofono_error_not_available(msg);
|
|
|
|
|
2013-03-25 22:05:20 +00:00
|
|
|
sender = dbus_message_get_sender(msg);
|
|
|
|
|
|
|
|
if (!g_str_equal(sender, agent->owner))
|
|
|
|
return __ofono_error_not_allowed(msg);
|
|
|
|
|
2013-03-25 22:05:18 +00:00
|
|
|
if (card->msg)
|
|
|
|
return __ofono_error_busy(msg);
|
|
|
|
|
2013-03-28 00:13:01 +00:00
|
|
|
if (!driver || !driver->connect)
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
card->msg = dbus_message_ref(msg);
|
|
|
|
|
|
|
|
driver->connect(card, card_connect_reply_cb, card);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fallback:
|
|
|
|
/* There's no driver, fallback to direct SCO connection */
|
2013-03-28 00:13:00 +00:00
|
|
|
err = ofono_handsfree_card_connect_sco(card);
|
|
|
|
if (err < 0)
|
2013-03-25 22:05:18 +00:00
|
|
|
return __ofono_error_failed(msg);
|
|
|
|
|
|
|
|
card->msg = dbus_message_ref(msg);
|
|
|
|
|
|
|
|
return NULL;
|
2013-02-26 19:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const GDBusMethodTable card_methods[] = {
|
|
|
|
{ GDBUS_METHOD("GetProperties",
|
|
|
|
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
|
|
|
|
card_get_properties) },
|
|
|
|
{ GDBUS_ASYNC_METHOD("Connect", NULL, NULL, card_connect) },
|
2017-05-04 08:22:36 +00:00
|
|
|
{ GDBUS_ASYNC_METHOD("Acquire", NULL,
|
|
|
|
GDBUS_ARGS({"sco", "h"}, {"codec", "y"}),
|
|
|
|
card_connect) },
|
2013-02-26 19:22:02 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GDBusSignalTable card_signals[] = {
|
|
|
|
{ GDBUS_SIGNAL("PropertyChanged",
|
|
|
|
GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2013-03-18 18:42:00 +00:00
|
|
|
struct ofono_handsfree_card *ofono_handsfree_card_create(unsigned int vendor,
|
2015-10-05 11:33:09 +00:00
|
|
|
enum ofono_handsfree_card_type type,
|
|
|
|
const char *driver,
|
|
|
|
void *data)
|
2013-02-26 17:03:00 +00:00
|
|
|
{
|
|
|
|
struct ofono_handsfree_card *card;
|
2013-03-18 18:42:00 +00:00
|
|
|
GSList *l;
|
2013-02-26 17:03:00 +00:00
|
|
|
|
|
|
|
card = g_new0(struct ofono_handsfree_card, 1);
|
|
|
|
|
2015-10-05 11:33:09 +00:00
|
|
|
card->type = type;
|
2013-04-15 13:54:49 +00:00
|
|
|
card->selected_codec = HFP_CODEC_CVSD;
|
|
|
|
|
2013-02-26 17:03:00 +00:00
|
|
|
card_list = g_slist_prepend(card_list, card);
|
|
|
|
|
2013-03-18 18:42:00 +00:00
|
|
|
for (l = drivers; l; l = l->next) {
|
|
|
|
const struct ofono_handsfree_card_driver *drv = l->data;
|
|
|
|
|
|
|
|
if (g_strcmp0(drv->name, driver))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (drv->probe(card, vendor, data) < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
card->driver = drv;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-26 17:03:00 +00:00
|
|
|
return card;
|
|
|
|
}
|
|
|
|
|
2013-03-13 18:14:39 +00:00
|
|
|
void ofono_handsfree_card_set_data(struct ofono_handsfree_card *card,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
card->driver_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *ofono_handsfree_card_get_data(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
return card->driver_data;
|
|
|
|
}
|
|
|
|
|
2013-03-18 18:42:00 +00:00
|
|
|
void ofono_handsfree_card_set_remote(struct ofono_handsfree_card *card,
|
|
|
|
const char *remote)
|
|
|
|
{
|
|
|
|
if (card->remote)
|
|
|
|
g_free(card->remote);
|
|
|
|
|
|
|
|
card->remote = g_strdup(remote);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ofono_handsfree_card_get_remote(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
return card->remote;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ofono_handsfree_card_set_local(struct ofono_handsfree_card *card,
|
|
|
|
const char *local)
|
|
|
|
{
|
|
|
|
if (card->local)
|
|
|
|
g_free(card->local);
|
|
|
|
|
|
|
|
card->local = g_strdup(local);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ofono_handsfree_card_get_local(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
return card->local;
|
|
|
|
}
|
|
|
|
|
2013-03-28 00:13:00 +00:00
|
|
|
int ofono_handsfree_card_connect_sco(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
GIOChannel *io;
|
|
|
|
struct sockaddr_sco addr;
|
|
|
|
int sk, ret;
|
|
|
|
|
|
|
|
sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | O_NONBLOCK | SOCK_CLOEXEC,
|
|
|
|
BTPROTO_SCO);
|
|
|
|
if (sk < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Bind to local address */
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sco_family = AF_BLUETOOTH;
|
|
|
|
bt_str2ba(card->local, &addr.sco_bdaddr);
|
|
|
|
|
|
|
|
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
|
|
|
ofono_error("Could not bind SCO socket");
|
|
|
|
close(sk);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connect to remote device */
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sco_family = AF_BLUETOOTH;
|
|
|
|
bt_str2ba(card->remote, &addr.sco_bdaddr);
|
|
|
|
|
2013-09-11 00:09:42 +00:00
|
|
|
if (apply_settings_from_codec(sk, card->selected_codec) == FALSE) {
|
|
|
|
close(sk);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-03-28 00:13:00 +00:00
|
|
|
ret = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
|
|
|
|
if (ret < 0 && errno != EINPROGRESS) {
|
|
|
|
close(sk);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
io = g_io_channel_unix_new(sk);
|
|
|
|
g_io_add_watch(io, G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
|
|
|
|
sco_connect_cb, card);
|
|
|
|
g_io_channel_unref(io);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-26 20:03:04 +00:00
|
|
|
static void emit_card_added(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
DBusMessage *signal;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
DBusMessageIter dict;
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
signal = dbus_message_new_signal(OFONO_MANAGER_PATH,
|
|
|
|
HFP_AUDIO_MANAGER_INTERFACE,
|
|
|
|
"CardAdded");
|
|
|
|
|
|
|
|
if (signal == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dbus_message_iter_init_append(signal, &iter);
|
|
|
|
|
|
|
|
path = card->path;
|
|
|
|
dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
|
|
|
|
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
|
|
|
OFONO_PROPERTIES_ARRAY_SIGNATURE,
|
|
|
|
&dict);
|
|
|
|
card_append_properties(card, &dict);
|
|
|
|
dbus_message_iter_close_container(&iter, &dict);
|
|
|
|
|
|
|
|
g_dbus_send_message(ofono_dbus_get_connection(), signal);
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:22:02 +00:00
|
|
|
int ofono_handsfree_card_register(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
static int next_card_id = 1;
|
|
|
|
char path[64];
|
|
|
|
|
|
|
|
if (card == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "/card_%d", next_card_id);
|
|
|
|
|
|
|
|
if (!g_dbus_register_interface(ofono_dbus_get_connection(), path,
|
|
|
|
HFP_AUDIO_CARD_INTERFACE,
|
|
|
|
card_methods, card_signals, NULL,
|
|
|
|
card, NULL))
|
|
|
|
return -EIO;
|
|
|
|
|
2013-02-26 21:46:43 +00:00
|
|
|
next_card_id += 1;
|
|
|
|
|
2013-02-26 19:22:02 +00:00
|
|
|
card->path = g_strdup(path);
|
2013-02-26 20:03:04 +00:00
|
|
|
emit_card_added(card);
|
2013-02-26 19:22:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-26 20:12:09 +00:00
|
|
|
static void emit_card_removed(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
const char *path = card->path;
|
|
|
|
|
|
|
|
g_dbus_emit_signal(conn, OFONO_MANAGER_PATH,
|
|
|
|
HFP_AUDIO_MANAGER_INTERFACE,
|
|
|
|
"CardRemoved", DBUS_TYPE_OBJECT_PATH, &path,
|
|
|
|
DBUS_TYPE_INVALID);
|
|
|
|
}
|
|
|
|
|
2013-02-26 20:09:15 +00:00
|
|
|
static void card_unregister(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
DBusConnection *conn = ofono_dbus_get_connection();
|
|
|
|
|
|
|
|
g_dbus_unregister_interface(conn, card->path, HFP_AUDIO_CARD_INTERFACE);
|
|
|
|
|
2013-02-26 20:12:09 +00:00
|
|
|
emit_card_removed(card);
|
|
|
|
|
2013-02-26 20:09:15 +00:00
|
|
|
g_free(card->path);
|
|
|
|
card->path = NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-26 17:03:00 +00:00
|
|
|
void ofono_handsfree_card_remove(struct ofono_handsfree_card *card)
|
|
|
|
{
|
|
|
|
DBG("%p", card);
|
|
|
|
|
|
|
|
if (card == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-02-26 20:09:15 +00:00
|
|
|
if (card->path)
|
|
|
|
card_unregister(card);
|
|
|
|
|
2013-02-26 17:03:00 +00:00
|
|
|
card_list = g_slist_remove(card_list, card);
|
|
|
|
|
|
|
|
g_free(card->remote);
|
|
|
|
g_free(card->local);
|
|
|
|
|
2013-03-18 19:06:56 +00:00
|
|
|
if (card->driver && card->driver->remove)
|
|
|
|
card->driver->remove(card);
|
|
|
|
|
2013-02-26 17:03:00 +00:00
|
|
|
g_free(card);
|
|
|
|
}
|
2013-02-20 21:55:46 +00:00
|
|
|
|
2013-04-15 13:54:49 +00:00
|
|
|
ofono_bool_t ofono_handsfree_card_set_codec(struct ofono_handsfree_card *card,
|
|
|
|
unsigned char codec)
|
|
|
|
{
|
|
|
|
if (codec == HFP_CODEC_CVSD)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (codec == HFP_CODEC_MSBC && has_wideband)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
card->selected_codec = codec;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-04-08 22:41:00 +00:00
|
|
|
ofono_bool_t ofono_handsfree_audio_has_wideband(void)
|
|
|
|
{
|
|
|
|
return has_wideband;
|
|
|
|
}
|
|
|
|
|
2013-09-11 00:09:41 +00:00
|
|
|
ofono_bool_t ofono_handsfree_audio_has_transparent_sco(void)
|
2013-04-25 19:05:16 +00:00
|
|
|
{
|
2013-09-11 00:09:41 +00:00
|
|
|
return transparent_sco;
|
2013-04-25 19:05:16 +00:00
|
|
|
}
|
|
|
|
|
2013-02-20 21:55:48 +00:00
|
|
|
static void agent_free(struct agent *agent)
|
|
|
|
{
|
2013-02-20 21:55:51 +00:00
|
|
|
if (agent->watch > 0)
|
|
|
|
g_dbus_remove_watch(ofono_dbus_get_connection(), agent->watch);
|
|
|
|
|
2013-02-20 21:55:48 +00:00
|
|
|
g_free(agent->owner);
|
|
|
|
g_free(agent->path);
|
|
|
|
g_free(agent);
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:55:49 +00:00
|
|
|
static void agent_release(struct agent *agent)
|
|
|
|
{
|
|
|
|
DBusMessage *msg;
|
|
|
|
|
|
|
|
msg = dbus_message_new_method_call(agent->owner, agent->path,
|
|
|
|
HFP_AUDIO_AGENT_INTERFACE, "Release");
|
|
|
|
|
|
|
|
g_dbus_send_message(ofono_dbus_get_connection(), msg);
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:55:51 +00:00
|
|
|
static void agent_disconnect(DBusConnection *conn, void *user_data)
|
|
|
|
{
|
|
|
|
DBG("Agent %s disconnected", agent->owner);
|
|
|
|
|
|
|
|
agent_free(agent);
|
|
|
|
agent = NULL;
|
2013-08-07 21:37:23 +00:00
|
|
|
|
|
|
|
has_wideband = FALSE;
|
2013-02-20 21:55:51 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 19:48:46 +00:00
|
|
|
static void append_card(void *data, void *userdata)
|
|
|
|
{
|
|
|
|
struct ofono_handsfree_card *card = data;
|
|
|
|
struct DBusMessageIter *array = userdata;
|
|
|
|
DBusMessageIter entry, dict;
|
|
|
|
|
|
|
|
dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
|
|
|
|
NULL, &entry);
|
|
|
|
dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
|
|
|
|
&card->path);
|
|
|
|
dbus_message_iter_open_container(&entry, DBUS_TYPE_ARRAY,
|
|
|
|
OFONO_PROPERTIES_ARRAY_SIGNATURE,
|
|
|
|
&dict);
|
|
|
|
|
|
|
|
card_append_properties(card, &dict);
|
|
|
|
|
|
|
|
dbus_message_iter_close_container(&entry, &dict);
|
|
|
|
dbus_message_iter_close_container(array, &entry);
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:55:45 +00:00
|
|
|
static DBusMessage *am_get_cards(DBusConnection *conn,
|
|
|
|
DBusMessage *msg, void *user_data)
|
|
|
|
{
|
2013-02-26 19:48:46 +00:00
|
|
|
DBusMessage *reply;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
DBusMessageIter array;
|
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (reply == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
|
|
|
|
|
|
|
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
|
|
|
DBUS_STRUCT_BEGIN_CHAR_AS_STRING
|
|
|
|
DBUS_TYPE_OBJECT_PATH_AS_STRING
|
|
|
|
DBUS_TYPE_ARRAY_AS_STRING
|
|
|
|
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
|
|
|
|
DBUS_TYPE_STRING_AS_STRING
|
|
|
|
DBUS_TYPE_VARIANT_AS_STRING
|
|
|
|
DBUS_DICT_ENTRY_END_CHAR_AS_STRING
|
|
|
|
DBUS_STRUCT_END_CHAR_AS_STRING,
|
|
|
|
&array);
|
|
|
|
g_slist_foreach(card_list, append_card, &array);
|
|
|
|
dbus_message_iter_close_container(&iter, &array);
|
|
|
|
|
|
|
|
return reply;
|
2013-02-20 21:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBusMessage *am_agent_register(DBusConnection *conn,
|
|
|
|
DBusMessage *msg, void *user_data)
|
|
|
|
{
|
2013-02-20 21:55:46 +00:00
|
|
|
const char *sender, *path;
|
|
|
|
unsigned char *codecs;
|
|
|
|
DBusMessageIter iter, array;
|
2013-02-20 21:55:47 +00:00
|
|
|
int length, i;
|
2013-04-15 13:54:53 +00:00
|
|
|
gboolean has_cvsd = FALSE, has_msbc = FALSE;
|
2013-02-20 21:55:46 +00:00
|
|
|
|
|
|
|
if (agent)
|
|
|
|
return __ofono_error_in_use(msg);
|
|
|
|
|
|
|
|
sender = dbus_message_get_sender(msg);
|
|
|
|
|
|
|
|
if (dbus_message_iter_init(msg, &iter) == FALSE)
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&iter, &path);
|
|
|
|
|
|
|
|
dbus_message_iter_next(&iter);
|
|
|
|
dbus_message_iter_recurse(&iter, &array);
|
|
|
|
dbus_message_iter_get_fixed_array(&array, &codecs, &length);
|
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
2013-02-20 21:55:47 +00:00
|
|
|
for (i = 0; i < length; i++) {
|
2013-02-28 18:52:50 +00:00
|
|
|
if (codecs[i] == HFP_CODEC_CVSD)
|
|
|
|
has_cvsd = TRUE;
|
2013-04-15 13:54:53 +00:00
|
|
|
else if (codecs[i] == HFP_CODEC_MSBC)
|
|
|
|
has_msbc = TRUE;
|
|
|
|
else
|
2013-02-20 21:55:47 +00:00
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
}
|
|
|
|
|
2013-04-16 22:32:21 +00:00
|
|
|
DBG("Agent %s registered with the CODECs:%s%s", sender,
|
|
|
|
has_cvsd ? " CVSD" : "", has_msbc ? " mSBC" : "");
|
|
|
|
|
2013-09-11 00:09:41 +00:00
|
|
|
if (has_msbc && transparent_sco)
|
2013-04-15 13:54:53 +00:00
|
|
|
has_wideband = TRUE;
|
2013-04-16 22:32:21 +00:00
|
|
|
else {
|
2013-04-15 13:54:53 +00:00
|
|
|
has_wideband = FALSE;
|
2013-04-16 22:32:21 +00:00
|
|
|
DBG("Wideband speech disabled: %s", has_msbc ?
|
2013-09-11 00:09:41 +00:00
|
|
|
"no Transparent SCO support" : "no mSBC support");
|
2013-04-16 22:32:21 +00:00
|
|
|
}
|
2013-04-15 13:54:53 +00:00
|
|
|
|
2013-02-28 18:52:50 +00:00
|
|
|
if (has_cvsd == FALSE) {
|
|
|
|
ofono_error("CVSD codec is mandatory");
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:55:46 +00:00
|
|
|
agent = g_new0(struct agent, 1);
|
|
|
|
agent->owner = g_strdup(sender);
|
|
|
|
agent->path = g_strdup(path);
|
2013-02-20 21:55:51 +00:00
|
|
|
agent->watch = g_dbus_add_disconnect_watch(conn, sender,
|
|
|
|
agent_disconnect, NULL, NULL);
|
2013-02-20 21:55:46 +00:00
|
|
|
|
|
|
|
return dbus_message_new_method_return(msg);
|
2013-02-20 21:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBusMessage *am_agent_unregister(DBusConnection *conn,
|
|
|
|
DBusMessage *msg, void *user_data)
|
|
|
|
{
|
2013-02-20 21:55:50 +00:00
|
|
|
const char *sender, *path;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
|
|
|
if (agent == NULL)
|
|
|
|
return __ofono_error_not_found(msg);
|
|
|
|
|
|
|
|
sender = dbus_message_get_sender(msg);
|
|
|
|
|
|
|
|
if (dbus_message_iter_init(msg, &iter) == FALSE)
|
|
|
|
return __ofono_error_invalid_args(msg);
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&iter, &path);
|
|
|
|
|
|
|
|
if (strcmp(sender, agent->owner) != 0)
|
|
|
|
return __ofono_error_not_allowed(msg);
|
|
|
|
|
|
|
|
if (strcmp(path, agent->path) != 0)
|
|
|
|
return __ofono_error_not_found(msg);
|
|
|
|
|
|
|
|
agent_free(agent);
|
|
|
|
agent = NULL;
|
|
|
|
|
2013-08-07 21:37:23 +00:00
|
|
|
has_wideband = FALSE;
|
|
|
|
|
2013-04-16 22:32:21 +00:00
|
|
|
DBG("Agent %s unregistered", sender);
|
|
|
|
|
2013-02-20 21:55:50 +00:00
|
|
|
return dbus_message_new_method_return(msg);
|
2013-02-20 21:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const GDBusMethodTable am_methods[] = {
|
|
|
|
{ GDBUS_METHOD("GetCards",
|
|
|
|
NULL, GDBUS_ARGS({"cards", "a{oa{sv}}"}),
|
|
|
|
am_get_cards) } ,
|
|
|
|
{ GDBUS_METHOD("Register",
|
|
|
|
GDBUS_ARGS({"path", "o"}, {"codecs", "ay"}), NULL,
|
|
|
|
am_agent_register) },
|
|
|
|
{ GDBUS_METHOD("Unregister",
|
|
|
|
GDBUS_ARGS({"path", "o"}), NULL,
|
|
|
|
am_agent_unregister) },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2013-02-26 20:03:04 +00:00
|
|
|
static const GDBusSignalTable am_signals[] = {
|
|
|
|
{ GDBUS_SIGNAL("CardAdded",
|
|
|
|
GDBUS_ARGS({ "path", "o" }, { "properties", "a{sv}" })) },
|
2013-02-26 20:12:09 +00:00
|
|
|
{ GDBUS_SIGNAL("CardRemoved",
|
|
|
|
GDBUS_ARGS({ "path", "o" })) },
|
2013-02-26 20:03:04 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2013-03-13 18:01:55 +00:00
|
|
|
int ofono_handsfree_card_driver_register(
|
|
|
|
const struct ofono_handsfree_card_driver *d)
|
|
|
|
{
|
|
|
|
DBG("driver: %p", d);
|
|
|
|
|
2013-09-11 00:09:43 +00:00
|
|
|
if (defer_setup == 0)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
2013-03-13 18:01:55 +00:00
|
|
|
if (d->probe == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
drivers = g_slist_prepend(drivers, (void *) d);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ofono_handsfree_card_driver_unregister(
|
|
|
|
const struct ofono_handsfree_card_driver *d)
|
|
|
|
{
|
|
|
|
DBG("driver: %p", d);
|
|
|
|
|
|
|
|
drivers = g_slist_remove(drivers, (void *) d);
|
|
|
|
}
|
|
|
|
|
2013-02-21 14:27:55 +00:00
|
|
|
void ofono_handsfree_audio_ref(void)
|
2013-02-20 21:55:45 +00:00
|
|
|
{
|
2013-02-21 14:27:55 +00:00
|
|
|
ref_count += 1;
|
|
|
|
|
|
|
|
if (ref_count != 1)
|
|
|
|
return;
|
|
|
|
|
2015-02-02 12:43:06 +00:00
|
|
|
__ofono_handsfree_audio_manager_init();
|
|
|
|
|
2013-02-20 21:55:45 +00:00
|
|
|
if (!g_dbus_register_interface(ofono_dbus_get_connection(),
|
2013-02-26 20:01:47 +00:00
|
|
|
OFONO_MANAGER_PATH,
|
|
|
|
HFP_AUDIO_MANAGER_INTERFACE,
|
2013-02-26 20:03:04 +00:00
|
|
|
am_methods, am_signals, NULL,
|
|
|
|
NULL, NULL))
|
2013-02-21 14:27:55 +00:00
|
|
|
ofono_error("Unable to register Handsfree Audio Manager");
|
2013-02-20 21:55:45 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 14:27:55 +00:00
|
|
|
void ofono_handsfree_audio_unref(void)
|
2013-02-20 21:55:45 +00:00
|
|
|
{
|
2013-02-21 14:27:55 +00:00
|
|
|
if (ref_count == 0) {
|
|
|
|
ofono_error("Error in handsfree audio manager ref counting");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref_count -= 1;
|
|
|
|
|
|
|
|
if (ref_count > 0)
|
|
|
|
return;
|
|
|
|
|
2013-02-26 20:01:47 +00:00
|
|
|
g_dbus_unregister_interface(ofono_dbus_get_connection(),
|
|
|
|
OFONO_MANAGER_PATH,
|
|
|
|
HFP_AUDIO_MANAGER_INTERFACE);
|
2013-02-20 21:55:48 +00:00
|
|
|
|
2013-02-20 21:55:49 +00:00
|
|
|
if (agent) {
|
|
|
|
agent_release(agent);
|
2013-02-20 21:55:48 +00:00
|
|
|
agent_free(agent);
|
2013-02-20 21:55:49 +00:00
|
|
|
}
|
2015-02-02 12:43:06 +00:00
|
|
|
|
|
|
|
__ofono_handsfree_audio_manager_cleanup();
|
2013-02-20 21:55:45 +00:00
|
|
|
}
|
2013-02-21 14:27:55 +00:00
|
|
|
|
|
|
|
int __ofono_handsfree_audio_manager_init(void)
|
|
|
|
{
|
2013-03-04 20:48:49 +00:00
|
|
|
return sco_init();
|
2013-02-21 14:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __ofono_handsfree_audio_manager_cleanup(void)
|
|
|
|
{
|
2015-02-02 12:43:06 +00:00
|
|
|
if (ref_count != 0)
|
2013-02-21 14:27:55 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-02 12:43:06 +00:00
|
|
|
if (sco_watch > 0) {
|
2013-03-04 20:48:49 +00:00
|
|
|
g_source_remove(sco_watch);
|
2015-02-02 12:43:06 +00:00
|
|
|
sco_watch = 0;
|
|
|
|
}
|
2013-02-21 14:27:55 +00:00
|
|
|
}
|