* [PATCH 1/2 v2] handsfree-audio: add type for our audio cards
@ 2015-10-05 11:33 Simon Fels
2015-10-05 11:33 ` [PATCH 2/2 v2] hfp_ag_bluez5: register audio card Simon Fels
2015-10-05 16:47 ` [PATCH 1/2 v2] handsfree-audio: add type for our audio cards Denis Kenzior
0 siblings, 2 replies; 4+ messages in thread
From: Simon Fels @ 2015-10-05 11:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 4230 bytes --]
When registering audio cards for the handsfree and gateway roles we
need a way for our users to differentiate between both to decide which
of them they start using for their purpose.
---
doc/handsfree-audio-api.txt | 4 ++++
include/handsfree-audio.h | 10 ++++++++--
plugins/hfp_hf_bluez5.c | 4 +++-
src/handsfree-audio.c | 24 ++++++++++++++++++++++--
4 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/doc/handsfree-audio-api.txt b/doc/handsfree-audio-api.txt
index 89b5aab..d82035c 100644
--- a/doc/handsfree-audio-api.txt
+++ b/doc/handsfree-audio-api.txt
@@ -89,6 +89,10 @@ Properties string RemoteAddress [readonly]
Bluetooth address of the local adapter.
+ string Type [readonly]
+
+ Type of the card. Valid values are "gateway" or
+ "handsfree".
Handsfree Audio Agent hierarchy [experimental]
===============================
diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index bfb8480..0e37dae 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -30,6 +30,11 @@ extern "C" {
struct ofono_handsfree_card;
+enum ofono_handsfree_card_type {
+ OFONO_HANDSFREE_CARD_TYPE_HANDSFREE,
+ OFONO_HANDSFREE_CARD_TYPE_GATEWAY,
+};
+
typedef void (*ofono_handsfree_card_connect_cb_t)(
const struct ofono_error *error, void *data);
@@ -45,8 +50,9 @@ struct ofono_handsfree_card_driver {
};
struct ofono_handsfree_card *ofono_handsfree_card_create(unsigned int vendor,
- const char *driver,
- void *data);
+ enum ofono_handsfree_card_type type,
+ const char *driver,
+ void *data);
int ofono_handsfree_card_register(struct ofono_handsfree_card *card);
void ofono_handsfree_card_remove(struct ofono_handsfree_card *card);
ofono_bool_t ofono_handsfree_card_set_codec(struct ofono_handsfree_card *card,
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 713c789..6ae98b3 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -589,7 +589,9 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
if (version >= HFP_VERSION_1_6)
driver = HFP16_HF_DRIVER;
- hfp->card = ofono_handsfree_card_create(0, driver, hfp);
+ hfp->card = ofono_handsfree_card_create(0,
+ OFONO_HANDSFREE_CARD_TYPE_HANDSFREE,
+ driver, hfp);
ofono_handsfree_card_set_data(hfp->card, hfp);
ofono_handsfree_card_set_local(hfp->card, local);
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index c990cc3..8db99e1 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -45,6 +45,7 @@
#define HFP_AUDIO_CARD_INTERFACE OFONO_SERVICE ".HandsfreeAudioCard"
struct ofono_handsfree_card {
+ enum ofono_handsfree_card_type type;
char *remote;
char *local;
char *path;
@@ -69,6 +70,17 @@ static ofono_bool_t has_wideband = FALSE;
static int defer_setup = 1;
static ofono_bool_t transparent_sco = FALSE;
+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 "";
+}
+
static uint16_t codec2setting(uint8_t codec)
{
switch (codec) {
@@ -255,6 +267,12 @@ static int sco_init(void)
static void card_append_properties(struct ofono_handsfree_card *card,
DBusMessageIter *dict)
{
+ const char *type;
+
+ type = card_type_to_string(card->type);
+ ofono_dbus_dict_append(dict, "Type",
+ DBUS_TYPE_STRING, &type);
+
ofono_dbus_dict_append(dict, "RemoteAddress",
DBUS_TYPE_STRING, &card->remote);
@@ -395,14 +413,16 @@ static const GDBusSignalTable card_signals[] = {
};
struct ofono_handsfree_card *ofono_handsfree_card_create(unsigned int vendor,
- const char *driver,
- void *data)
+ enum ofono_handsfree_card_type type,
+ const char *driver,
+ void *data)
{
struct ofono_handsfree_card *card;
GSList *l;
card = g_new0(struct ofono_handsfree_card, 1);
+ card->type = type;
card->selected_codec = HFP_CODEC_CVSD;
card_list = g_slist_prepend(card_list, card);
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2 v2] hfp_ag_bluez5: register audio card
2015-10-05 11:33 [PATCH 1/2 v2] handsfree-audio: add type for our audio cards Simon Fels
@ 2015-10-05 11:33 ` Simon Fels
2015-10-05 16:45 ` Denis Kenzior
2015-10-05 16:47 ` [PATCH 1/2 v2] handsfree-audio: add type for our audio cards Denis Kenzior
1 sibling, 1 reply; 4+ messages in thread
From: Simon Fels @ 2015-10-05 11:33 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 5173 bytes --]
To let others (PulseAudio) be notified when a handsfree device is
connected with us and can be used for audio routing we need to
expose this by registering a audio card with the correct type.
For now there is no need to provide a card driver and we just stick
to what the core provides.
---
plugins/hfp_ag_bluez5.c | 77 +++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 68 insertions(+), 9 deletions(-)
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 93de302..50238d8 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -22,6 +22,7 @@
#include <config.h>
#endif
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
@@ -35,21 +36,30 @@
#include <ofono/plugin.h>
#include <ofono/log.h>
#include <ofono/modem.h>
+#include <ofono/handsfree.h>
+#include <ofono/handsfree-audio.h>
#include "hfp.h"
#include "bluez5.h"
+#include "bluetooth.h"
#ifndef DBUS_TYPE_UNIX_FD
#define DBUS_TYPE_UNIX_FD -1
#endif
#define HFP_AG_EXT_PROFILE_PATH "/bluetooth/profile/hfp_ag"
+#define BT_ADDR_SIZE 18
static guint modemwatch_id;
static GList *modems;
static GHashTable *sim_hash = NULL;
static GHashTable *connection_hash;
+struct device_info {
+ int fd;
+ struct ofono_handsfree_card *card;
+};
+
static void connection_destroy(gpointer data)
{
int fd = GPOINTER_TO_INT(data);
@@ -76,9 +86,14 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
DBusMessageIter entry;
const char *device;
GIOChannel *io;
- int fd, fd_dup;
+ int fd;
+ struct sockaddr_rc saddr;
+ socklen_t optlen;
struct ofono_emulator *em;
struct ofono_modem *modem;
+ struct device_info *dev;
+ char local[BT_ADDR_SIZE], remote[BT_ADDR_SIZE];
+ int err;
DBG("Profile handler NewConnection");
@@ -95,7 +110,10 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
goto invalid;
dbus_message_iter_get_basic(&entry, &fd);
+
dbus_message_iter_next(&entry);
+ if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_ARRAY)
+ goto invalid;
if (fd < 0)
goto invalid;
@@ -111,8 +129,35 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
}
modem = modems->data;
+
DBG("Picked modem %p for emulator", modem);
+ memset(&saddr, 0, sizeof(saddr));
+ optlen = sizeof(saddr);
+
+ if (getsockname(fd, (struct sockaddr *) &saddr, &optlen) < 0) {
+ err = errno;
+ ofono_error("RFCOMM getsockname(): %s (%d)", strerror(err),
+ err);
+ close(fd);
+ goto invalid;
+ }
+
+ bt_ba2str(&saddr.rc_bdaddr, local);
+
+ memset(&saddr, 0, sizeof(saddr));
+ optlen = sizeof(saddr);
+
+ if (getpeername(fd, (struct sockaddr *) &saddr, &optlen) < 0) {
+ err = errno;
+ ofono_error("RFCOMM getpeername(): %s (%d)", strerror(err),
+ err);
+ close(fd);
+ goto invalid;
+ }
+
+ bt_ba2str(&saddr.rc_bdaddr, remote);
+
em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_HFP);
if (em == NULL) {
close(fd);
@@ -123,14 +168,24 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
ofono_emulator_register(em, fd);
- fd_dup = dup(fd);
- io = g_io_channel_unix_new(fd_dup);
+ io = g_io_channel_unix_new(fd);
g_io_add_watch_full(io, G_PRIORITY_DEFAULT, G_IO_HUP, io_hup_cb,
g_strdup(device), g_free);
g_io_channel_unref(io);
- g_hash_table_insert(connection_hash, g_strdup(device),
- GINT_TO_POINTER(fd_dup));
+ dev = g_new0(struct device_info, 1);
+ dev->fd = fd;
+
+ dev->card = ofono_handsfree_card_create(0,
+ OFONO_HANDSFREE_CARD_TYPE_GATEWAY,
+ NULL, NULL);
+
+ ofono_handsfree_card_set_local(dev->card, local);
+ ofono_handsfree_card_set_remote(dev->card, remote);
+
+ g_hash_table_insert(connection_hash, g_strdup(device), dev);
+
+ ofono_handsfree_card_register(dev->card);
return dbus_message_new_method_return(msg);
@@ -164,7 +219,7 @@ static DBusMessage *profile_disconnection(DBusConnection *conn,
{
DBusMessageIter iter;
const char *device;
- gpointer fd;
+ struct device_info *dev;
DBG("Profile handler RequestDisconnection");
@@ -178,11 +233,11 @@ static DBusMessage *profile_disconnection(DBusConnection *conn,
DBG("%s", device);
- fd = g_hash_table_lookup(connection_hash, device);
- if (fd == NULL)
+ dev = g_hash_table_lookup(connection_hash, device);
+ if (dev == NULL)
goto invalid;
- shutdown(GPOINTER_TO_INT(fd), SHUT_RDWR);
+ shutdown(dev->fd, SHUT_RDWR);
g_hash_table_remove(connection_hash, device);
@@ -346,6 +401,8 @@ static int hfp_ag_init(void)
connection_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, connection_destroy);
+ ofono_handsfree_audio_ref();
+
return 0;
}
@@ -362,6 +419,8 @@ static void hfp_ag_exit(void)
g_list_free(modems);
g_hash_table_foreach_remove(sim_hash, sim_watch_remove, NULL);
g_hash_table_destroy(sim_hash);
+
+ ofono_handsfree_audio_unref();
}
OFONO_PLUGIN_DEFINE(hfp_ag_bluez5, "Hands-Free Audio Gateway Profile Plugins",
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2 v2] hfp_ag_bluez5: register audio card
2015-10-05 11:33 ` [PATCH 2/2 v2] hfp_ag_bluez5: register audio card Simon Fels
@ 2015-10-05 16:45 ` Denis Kenzior
0 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2015-10-05 16:45 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1421 bytes --]
Hi Simon,
<snip>
> @@ -123,14 +168,24 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
>
> ofono_emulator_register(em, fd);
>
> - fd_dup = dup(fd);
> - io = g_io_channel_unix_new(fd_dup);
> + io = g_io_channel_unix_new(fd);
The comment in commit 9332299b indicates that a dup() was needed to
properly detect HUP events. Can you double check that this change is
indeed correct?
> g_io_add_watch_full(io, G_PRIORITY_DEFAULT, G_IO_HUP, io_hup_cb,
> g_strdup(device), g_free);
> g_io_channel_unref(io);
>
> - g_hash_table_insert(connection_hash, g_strdup(device),
> - GINT_TO_POINTER(fd_dup));
> + dev = g_new0(struct device_info, 1);
> + dev->fd = fd;
> +
> + dev->card = ofono_handsfree_card_create(0,
> + OFONO_HANDSFREE_CARD_TYPE_GATEWAY,
> + NULL, NULL);
> +
> + ofono_handsfree_card_set_local(dev->card, local);
> + ofono_handsfree_card_set_remote(dev->card, remote);
> +
> + g_hash_table_insert(connection_hash, g_strdup(device), dev);
> +
> + ofono_handsfree_card_register(dev->card);
>
On HFP 1.6 and 1.7, the audio should not be triggered until SLC is
established. Whats your plan to ensure that PulseAudio does not start
using the audio device until then? FYI, the earlier attempt to add AG
support had src/emulator.c make the ofono_handsfree_card_register() call
at the appropriate time.
Regards,
-Denis
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2 v2] handsfree-audio: add type for our audio cards
2015-10-05 11:33 [PATCH 1/2 v2] handsfree-audio: add type for our audio cards Simon Fels
2015-10-05 11:33 ` [PATCH 2/2 v2] hfp_ag_bluez5: register audio card Simon Fels
@ 2015-10-05 16:47 ` Denis Kenzior
1 sibling, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2015-10-05 16:47 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 553 bytes --]
Hi Simon,
On 10/05/2015 06:33 AM, Simon Fels wrote:
> When registering audio cards for the handsfree and gateway roles we
> need a way for our users to differentiate between both to decide which
> of them they start using for their purpose.
> ---
> doc/handsfree-audio-api.txt | 4 ++++
> include/handsfree-audio.h | 10 ++++++++--
> plugins/hfp_hf_bluez5.c | 4 +++-
> src/handsfree-audio.c | 24 ++++++++++++++++++++++--
> 4 files changed, 37 insertions(+), 5 deletions(-)
>
Applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-05 16:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-05 11:33 [PATCH 1/2 v2] handsfree-audio: add type for our audio cards Simon Fels
2015-10-05 11:33 ` [PATCH 2/2 v2] hfp_ag_bluez5: register audio card Simon Fels
2015-10-05 16:45 ` Denis Kenzior
2015-10-05 16:47 ` [PATCH 1/2 v2] handsfree-audio: add type for our audio cards Denis Kenzior
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.