* [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections
@ 2013-03-20 23:03 Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 2/4] handsfree-audio: Add support for sending the SCO socket Vinicius Costa Gomes
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-20 23:03 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3202 bytes --]
When calling the card's .Connect() method, we should be able to
establish a SCO connection.
Right now, we only have support for establishing the SCO connection
directly, this is what is expected from HFP 1.5 HF/AG devices.
---
src/handsfree-audio.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 96 insertions(+), 1 deletion(-)
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index c7fa2fb..1da2224 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -53,6 +53,8 @@ struct ofono_handsfree_card {
char *remote;
char *local;
char *path;
+ DBusMessage *msg;
+ guint sco_watch;
const struct ofono_handsfree_card_driver *driver;
void *driver_data;
};
@@ -235,10 +237,103 @@ 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)
+
+{
+ struct ofono_handsfree_card *card = user_data;
+ DBusMessage *reply;
+ int sk;
+
+ if (agent == NULL)
+ return FALSE;
+
+ if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+ reply = __ofono_error_failed(card->msg);
+ goto done;
+ }
+
+ sk = g_io_channel_unix_get_fd(io);
+
+ close(sk);
+
+ reply = dbus_message_new_method_return(card->msg);
+
+done:
+ g_dbus_send_message(ofono_dbus_get_connection(), reply);
+
+ return FALSE;
+}
+
+static void sco_watch_destroy(gpointer user_data)
+{
+ struct ofono_handsfree_card *card = user_data;
+
+ card->sco_watch = 0;
+ dbus_message_unref(card->msg);
+}
+
static DBusMessage *card_connect(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- return __ofono_error_not_implemented(msg);
+ struct ofono_handsfree_card *card = data;
+ GIOChannel *io;
+ int sk;
+
+ if (agent == NULL)
+ return __ofono_error_not_available(msg);
+
+ if (card->sco_watch)
+ return __ofono_error_busy(msg);
+
+ sk = card_connect_sco(card);
+ if (sk < 0)
+ return __ofono_error_failed(msg);
+
+ io = g_io_channel_unix_new(sk);
+ card->sco_watch = g_io_add_watch_full(io, G_PRIORITY_DEFAULT,
+ G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+ sco_connect_cb, card, sco_watch_destroy);
+
+ g_io_channel_unref(io);
+
+ card->msg = dbus_message_ref(msg);
+
+ return NULL;
}
static const GDBusMethodTable card_methods[] = {
--
1.8.1.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] handsfree-audio: Add support for sending the SCO socket
2013-03-20 23:03 [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections Vinicius Costa Gomes
@ 2013-03-20 23:03 ` Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 3/4] handsfree-audio: Reject .Connect() from other senders Vinicius Costa Gomes
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-20 23:03 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 567 bytes --]
Send the SCO socket to the agent associated with the card that
just got connected.
---
src/handsfree-audio.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 1da2224..3600255 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -289,6 +289,8 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
sk = g_io_channel_unix_get_fd(io);
+ send_new_connection(card->path, sk);
+
close(sk);
reply = dbus_message_new_method_return(card->msg);
--
1.8.1.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] handsfree-audio: Reject .Connect() from other senders
2013-03-20 23:03 [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 2/4] handsfree-audio: Add support for sending the SCO socket Vinicius Costa Gomes
@ 2013-03-20 23:03 ` Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 4/4] doc: Add Handsfree Audio Card "Connect" errors Vinicius Costa Gomes
2013-03-21 15:05 ` [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections Denis Kenzior
3 siblings, 0 replies; 6+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-20 23:03 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 754 bytes --]
Only the agent should be able to call .Connect() on the card.
---
src/handsfree-audio.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 3600255..c2bdc7f 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -314,11 +314,17 @@ static DBusMessage *card_connect(DBusConnection *conn,
{
struct ofono_handsfree_card *card = data;
GIOChannel *io;
+ const char *sender;
int sk;
if (agent == NULL)
return __ofono_error_not_available(msg);
+ sender = dbus_message_get_sender(msg);
+
+ if (!g_str_equal(sender, agent->owner))
+ return __ofono_error_not_allowed(msg);
+
if (card->sco_watch)
return __ofono_error_busy(msg);
--
1.8.1.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] doc: Add Handsfree Audio Card "Connect" errors
2013-03-20 23:03 [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 2/4] handsfree-audio: Add support for sending the SCO socket Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 3/4] handsfree-audio: Reject .Connect() from other senders Vinicius Costa Gomes
@ 2013-03-20 23:03 ` Vinicius Costa Gomes
2013-03-21 15:07 ` Denis Kenzior
2013-03-21 15:05 ` [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections Denis Kenzior
3 siblings, 1 reply; 6+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-20 23:03 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 782 bytes --]
From: Claudio Takahasi <claudio.takahasi@openbossa.org>
---
doc/handsfree-audio-api.txt | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/doc/handsfree-audio-api.txt b/doc/handsfree-audio-api.txt
index 6c3c8b5..89b5aab 100644
--- a/doc/handsfree-audio-api.txt
+++ b/doc/handsfree-audio-api.txt
@@ -70,6 +70,12 @@ Methods dict GetProperties()
the audio connection could not be established, this
method will return an error.
+ Possible Errors: [service].Error.InProgress
+ [service].Error.Failed
+ [service].Error.NotAvailable
+ [service].Error.NotImplemented
+ [service].Error.NotAllowed
+
Signals PropertyChanged(string name, variant value)
This signal indicates a changed value of the given
--
1.8.1.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections
2013-03-20 23:03 [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections Vinicius Costa Gomes
` (2 preceding siblings ...)
2013-03-20 23:03 ` [PATCH 4/4] doc: Add Handsfree Audio Card "Connect" errors Vinicius Costa Gomes
@ 2013-03-21 15:05 ` Denis Kenzior
3 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2013-03-21 15:05 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3700 bytes --]
Hi Vinicius,
On 03/20/2013 06:03 PM, Vinicius Costa Gomes wrote:
> When calling the card's .Connect() method, we should be able to
> establish a SCO connection.
>
> Right now, we only have support for establishing the SCO connection
> directly, this is what is expected from HFP 1.5 HF/AG devices.
> ---
> src/handsfree-audio.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 96 insertions(+), 1 deletion(-)
>
> diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
> index c7fa2fb..1da2224 100644
> --- a/src/handsfree-audio.c
> +++ b/src/handsfree-audio.c
> @@ -53,6 +53,8 @@ struct ofono_handsfree_card {
> char *remote;
> char *local;
> char *path;
> + DBusMessage *msg;
> + guint sco_watch;
> const struct ofono_handsfree_card_driver *driver;
> void *driver_data;
> };
> @@ -235,10 +237,103 @@ 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)
> +
> +{
> + struct ofono_handsfree_card *card = user_data;
> + DBusMessage *reply;
> + int sk;
> +
> + if (agent == NULL)
> + return FALSE;
> +
This seems wrong. We can't just return here.
> + if (cond& (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
> + reply = __ofono_error_failed(card->msg);
> + goto done;
> + }
> +
> + sk = g_io_channel_unix_get_fd(io);
> +
> + close(sk);
> +
> + reply = dbus_message_new_method_return(card->msg);
> +
> +done:
> + g_dbus_send_message(ofono_dbus_get_connection(), reply);
> +
> + return FALSE;
> +}
> +
> +static void sco_watch_destroy(gpointer user_data)
> +{
> + struct ofono_handsfree_card *card = user_data;
> +
> + card->sco_watch = 0;
> + dbus_message_unref(card->msg);
> +}
> +
I would get rid of sco_watch_destroy. Once we go to AT+BCC, the
sco_watch and card->msg will be unrelated.
> static DBusMessage *card_connect(DBusConnection *conn,
> DBusMessage *msg, void *data)
> {
> - return __ofono_error_not_implemented(msg);
> + struct ofono_handsfree_card *card = data;
> + GIOChannel *io;
> + int sk;
> +
> + if (agent == NULL)
> + return __ofono_error_not_available(msg);
> +
> + if (card->sco_watch)
> + return __ofono_error_busy(msg);
> +
> + sk = card_connect_sco(card);
> + if (sk< 0)
> + return __ofono_error_failed(msg);
> +
> + io = g_io_channel_unix_new(sk);
> + card->sco_watch = g_io_add_watch_full(io, G_PRIORITY_DEFAULT,
> + G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
> + sco_connect_cb, card, sco_watch_destroy);
> +
> + g_io_channel_unref(io);
> +
> + card->msg = dbus_message_ref(msg);
> +
> + return NULL;
> }
>
> static const GDBusMethodTable card_methods[] = {
Regards,
-Denis
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 4/4] doc: Add Handsfree Audio Card "Connect" errors
2013-03-20 23:03 ` [PATCH 4/4] doc: Add Handsfree Audio Card "Connect" errors Vinicius Costa Gomes
@ 2013-03-21 15:07 ` Denis Kenzior
0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2013-03-21 15:07 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 278 bytes --]
Hi Vinicius,
On 03/20/2013 06:03 PM, Vinicius Costa Gomes wrote:
> From: Claudio Takahasi<claudio.takahasi@openbossa.org>
>
> ---
> doc/handsfree-audio-api.txt | 6 ++++++
> 1 file changed, 6 insertions(+)
>
Patch has been applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-03-21 15:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-20 23:03 [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 2/4] handsfree-audio: Add support for sending the SCO socket Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 3/4] handsfree-audio: Reject .Connect() from other senders Vinicius Costa Gomes
2013-03-20 23:03 ` [PATCH 4/4] doc: Add Handsfree Audio Card "Connect" errors Vinicius Costa Gomes
2013-03-21 15:07 ` Denis Kenzior
2013-03-21 15:05 ` [PATCH 1/4] handsfree-audio: Add support for initiating SCO connections Denis Kenzior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox