* [PATCH 2/5] include: Add ofono_handsfree_card_connect_sco()
2013-03-28 0:12 [PATCH 1/5] hfp_hf_bluez5: Add a card driver for HFP 1.6 Vinicius Costa Gomes
@ 2013-03-28 0:12 ` Vinicius Costa Gomes
2013-03-28 14:37 ` Denis Kenzior
2013-03-28 0:13 ` [PATCH 3/5] handsfree-audio: Add ofono_handsfree_card_connect_sco Vinicius Costa Gomes
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-28 0:12 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 718 bytes --]
This will be used by HFP plugins to tell the core that a SCO connection
needs to be established.
---
include/handsfree-audio.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index 8c16b22..49b0605 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -61,6 +61,8 @@ void ofono_handsfree_card_set_local(struct ofono_handsfree_card *card,
const char *local);
const char *ofono_handsfree_card_get_local(struct ofono_handsfree_card *card);
+int ofono_handsfree_card_connect_sco(struct ofono_handsfree_card *card);
+
void ofono_handsfree_audio_ref(void);
void ofono_handsfree_audio_unref(void);
--
1.8.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 3/5] handsfree-audio: Add ofono_handsfree_card_connect_sco
2013-03-28 0:12 [PATCH 1/5] hfp_hf_bluez5: Add a card driver for HFP 1.6 Vinicius Costa Gomes
2013-03-28 0:12 ` [PATCH 2/5] include: Add ofono_handsfree_card_connect_sco() Vinicius Costa Gomes
@ 2013-03-28 0:13 ` Vinicius Costa Gomes
2013-03-28 14:37 ` Denis Kenzior
2013-03-28 0:13 ` [PATCH 4/5] handsfree-audio: Add .Connect using the card driver Vinicius Costa Gomes
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-28 0:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3404 bytes --]
---
src/handsfree-audio.c | 87 ++++++++++++++++++++++++++-------------------------
1 file changed, 44 insertions(+), 43 deletions(-)
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index f8df6d6..571ed54 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -236,40 +236,6 @@ static DBusMessage *card_get_properties(DBusConnection *conn,
return reply;
}
-static int card_connect_sco(struct ofono_handsfree_card *card)
-{
- 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) {
- 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);
-
- ret = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
- if (ret < 0 && errno != EINPROGRESS) {
- close(sk);
- return -1;
- }
-
- return sk;
-}
-
static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
@@ -311,9 +277,8 @@ static DBusMessage *card_connect(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ofono_handsfree_card *card = data;
- GIOChannel *io;
const char *sender;
- int sk;
+ int err;
if (agent == NULL)
return __ofono_error_not_available(msg);
@@ -326,15 +291,10 @@ static DBusMessage *card_connect(DBusConnection *conn,
if (card->msg)
return __ofono_error_busy(msg);
- sk = card_connect_sco(card);
- if (sk < 0)
+ err = ofono_handsfree_card_connect_sco(card);
+ if (err < 0)
return __ofono_error_failed(msg);
- 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);
-
card->msg = dbus_message_ref(msg);
return NULL;
@@ -420,6 +380,47 @@ const char *ofono_handsfree_card_get_local(struct ofono_handsfree_card *card)
return card->local;
}
+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);
+
+ 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;
+}
+
static void emit_card_added(struct ofono_handsfree_card *card)
{
DBusMessage *signal;
--
1.8.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 4/5] handsfree-audio: Add .Connect using the card driver
2013-03-28 0:12 [PATCH 1/5] hfp_hf_bluez5: Add a card driver for HFP 1.6 Vinicius Costa Gomes
2013-03-28 0:12 ` [PATCH 2/5] include: Add ofono_handsfree_card_connect_sco() Vinicius Costa Gomes
2013-03-28 0:13 ` [PATCH 3/5] handsfree-audio: Add ofono_handsfree_card_connect_sco Vinicius Costa Gomes
@ 2013-03-28 0:13 ` Vinicius Costa Gomes
2013-03-28 14:38 ` Denis Kenzior
2013-03-28 0:13 ` [PATCH 5/5] handsfree-audio: Handle when .Connect() was already replied to Vinicius Costa Gomes
2013-03-28 14:37 ` [PATCH 1/5] hfp_hf_bluez5: Add a card driver for HFP 1.6 Denis Kenzior
4 siblings, 1 reply; 11+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-28 0:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1520 bytes --]
Now each handsfree implementation may be notified that a card wants
its audio to be connected.
---
src/handsfree-audio.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 571ed54..3f24a2a 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -273,10 +273,24 @@ done:
return FALSE;
}
+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);
+}
+
static DBusMessage *card_connect(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct ofono_handsfree_card *card = data;
+ const struct ofono_handsfree_card_driver *driver = card->driver;
const char *sender;
int err;
@@ -291,6 +305,17 @@ static DBusMessage *card_connect(DBusConnection *conn,
if (card->msg)
return __ofono_error_busy(msg);
+ 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 */
err = ofono_handsfree_card_connect_sco(card);
if (err < 0)
return __ofono_error_failed(msg);
--
1.8.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 5/5] handsfree-audio: Handle when .Connect() was already replied to
2013-03-28 0:12 [PATCH 1/5] hfp_hf_bluez5: Add a card driver for HFP 1.6 Vinicius Costa Gomes
` (2 preceding siblings ...)
2013-03-28 0:13 ` [PATCH 4/5] handsfree-audio: Add .Connect using the card driver Vinicius Costa Gomes
@ 2013-03-28 0:13 ` Vinicius Costa Gomes
2013-03-28 14:41 ` Denis Kenzior
2013-03-28 14:37 ` [PATCH 1/5] hfp_hf_bluez5: Add a card driver for HFP 1.6 Denis Kenzior
4 siblings, 1 reply; 11+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-28 0:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1573 bytes --]
In some cases, it is possible that when sco_connect_cb() is called
the .Connect() message (stored in card->msg) is not valid anymore.
---
src/handsfree-audio.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 3f24a2a..841cc3f 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -242,16 +242,19 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
{
struct ofono_handsfree_card *card = user_data;
DBusMessage *reply;
- int sk;
+ int sk, err;
if (agent == NULL) {
/* There's no agent, so there's no one to reply to */
- reply = NULL;
+ if (card->msg)
+ dbus_message_unref(card->msg);
+
+ card->msg = NULL;
goto done;
}
if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
- reply = __ofono_error_failed(card->msg);
+ err = -EIO;
goto done;
}
@@ -261,14 +264,19 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
close(sk);
- reply = dbus_message_new_method_return(card->msg);
+ err = 0;
done:
- if (reply)
- g_dbus_send_message(ofono_dbus_get_connection(), reply);
+ /* Or the msg was already replied to, or the agent exited */
+ if (card->msg == NULL)
+ return FALSE;
- dbus_message_unref(card->msg);
- card->msg = NULL;
+ if (err < 0)
+ reply = __ofono_error_failed(card->msg);
+ else
+ reply = dbus_message_new_method_return(card->msg);
+
+ __ofono_dbus_pending_reply(&card->msg, reply);
return FALSE;
}
--
1.8.2
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 5/5] handsfree-audio: Handle when .Connect() was already replied to
2013-03-28 0:13 ` [PATCH 5/5] handsfree-audio: Handle when .Connect() was already replied to Vinicius Costa Gomes
@ 2013-03-28 14:41 ` Denis Kenzior
2013-04-02 21:11 ` Vinicius Costa Gomes
0 siblings, 1 reply; 11+ messages in thread
From: Denis Kenzior @ 2013-03-28 14:41 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2081 bytes --]
Hi Vinicius,
On 03/27/2013 07:13 PM, Vinicius Costa Gomes wrote:
> In some cases, it is possible that when sco_connect_cb() is called
> the .Connect() message (stored in card->msg) is not valid anymore.
Can you tell me what cases these are?
My thinking is that we will treat the connect callback specially.
If the driver calls the callback function, then it is assumed that no
further action is necessary. If the driver calls connect_sco(), then we
assume that the callback function will never be called.
> ---
> src/handsfree-audio.c | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
> index 3f24a2a..841cc3f 100644
> --- a/src/handsfree-audio.c
> +++ b/src/handsfree-audio.c
> @@ -242,16 +242,19 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
> {
> struct ofono_handsfree_card *card = user_data;
> DBusMessage *reply;
> - int sk;
> + int sk, err;
>
> if (agent == NULL) {
> /* There's no agent, so there's no one to reply to */
> - reply = NULL;
> + if (card->msg)
> + dbus_message_unref(card->msg);
> +
> + card->msg = NULL;
> goto done;
> }
>
> if (cond& (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
> - reply = __ofono_error_failed(card->msg);
> + err = -EIO;
> goto done;
> }
>
> @@ -261,14 +264,19 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
>
> close(sk);
>
> - reply = dbus_message_new_method_return(card->msg);
> + err = 0;
>
> done:
> - if (reply)
> - g_dbus_send_message(ofono_dbus_get_connection(), reply);
> + /* Or the msg was already replied to, or the agent exited */
> + if (card->msg == NULL)
> + return FALSE;
>
> - dbus_message_unref(card->msg);
> - card->msg = NULL;
> + if (err< 0)
> + reply = __ofono_error_failed(card->msg);
> + else
> + reply = dbus_message_new_method_return(card->msg);
> +
> + __ofono_dbus_pending_reply(&card->msg, reply);
>
> return FALSE;
> }
Regards,
-Denis
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 5/5] handsfree-audio: Handle when .Connect() was already replied to
2013-03-28 14:41 ` Denis Kenzior
@ 2013-04-02 21:11 ` Vinicius Costa Gomes
0 siblings, 0 replies; 11+ messages in thread
From: Vinicius Costa Gomes @ 2013-04-02 21:11 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1000 bytes --]
Hi Denis,
Sorry for the delay.
On 09:41 Thu 28 Mar, Denis Kenzior wrote:
> Hi Vinicius,
>
> On 03/27/2013 07:13 PM, Vinicius Costa Gomes wrote:
> >In some cases, it is possible that when sco_connect_cb() is called
> >the .Connect() message (stored in card->msg) is not valid anymore.
>
> Can you tell me what cases these are?
>
> My thinking is that we will treat the connect callback specially.
>
> If the driver calls the callback function, then it is assumed that
> no further action is necessary. If the driver calls connect_sco(),
> then we assume that the callback function will never be called.
This is indeed the case (when the HFP 1.6 driver fallbacks to direct SCO
connection). The way I was writing it I was calling connect_sco() and the
callback inside the driver.
If we consider that when you call connect_sco() you hand the connection
responsability to the core, it even makes more sense.
So, this patch can be ignored.
Cheers,
--
Vinicius
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/5] hfp_hf_bluez5: Add a card driver for HFP 1.6
2013-03-28 0:12 [PATCH 1/5] hfp_hf_bluez5: Add a card driver for HFP 1.6 Vinicius Costa Gomes
` (3 preceding siblings ...)
2013-03-28 0:13 ` [PATCH 5/5] handsfree-audio: Handle when .Connect() was already replied to Vinicius Costa Gomes
@ 2013-03-28 14:37 ` Denis Kenzior
4 siblings, 0 replies; 11+ messages in thread
From: Denis Kenzior @ 2013-03-28 14:37 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
Hi Vinicius,
On 03/27/2013 07:12 PM, Vinicius Costa Gomes wrote:
> This is just the skeleton of a Handsfree Audio Card for the HF side of
> HFP 1.6.
> ---
> plugins/hfp_hf_bluez5.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
Patch has been applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 11+ messages in thread