From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH v0 02/10] handsfree-audio: Move SCO to handsfree-audio.c
Date: Fri, 01 Mar 2013 13:20:14 -0600 [thread overview]
Message-ID: <5130FF6E.1030807@gmail.com> (raw)
In-Reply-To: <1362077572-28049-3-git-send-email-claudio.takahasi@openbossa.org>
[-- Attachment #1: Type: text/plain, Size: 4331 bytes --]
Hi Claudio,
On 02/28/2013 12:52 PM, Claudio Takahasi wrote:
> This patch moves the SCO socket handling from hfp_hf_bluez5 plugin to
> handsfree-audio.c file.
>
> This is the initial step to be able to support sending the file
> descriptor through the Agent NewConnection method.
> ---
> plugins/hfp_hf_bluez5.c | 102 +----------------------------------------------
> src/handsfree-audio.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 103 insertions(+), 102 deletions(-)
>
<snip>
> diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
> index b2d4b97..14488ac 100644
> --- a/src/handsfree-audio.c
> +++ b/src/handsfree-audio.c
> @@ -25,12 +25,19 @@
>
> #include<errno.h>
> #include<stdio.h>
> +#include<stdint.h>
> #include<string.h>
> +#include<fcntl.h>
> +#include<unistd.h>
> +#include<sys/socket.h>
>
> #include<gdbus.h>
> +#include<gatchat.h>
Why do you need this?
>
> +#include<drivers/hfpmodem/slc.h>
Or this?
> #include<ofono/handsfree-audio.h>
>
> +#include "bluetooth.h"
> #include "ofono.h"
>
> #define HFP_AUDIO_MANAGER_INTERFACE OFONO_SERVICE ".HandsfreeAudioManager"
> @@ -60,6 +67,97 @@ struct agent {
> static struct agent *agent = NULL;
> static int ref_count = 0;
> static GSList *card_list = 0;
> +static guint sco_watch = 0;
> +static uint16_t local_hfp_version = HFP_VERSION_1_6;
Why do we need this?
> +
> +static ofono_bool_t slc_match(struct ofono_modem *modem, void *userdata)
> +{
> + const char *remote = userdata;
> + const char *value = ofono_modem_get_string(modem, "Remote");
> +
> + if (value == NULL)
> + return FALSE;
> +
> + /* Make sure SLC has been established */
> + if (ofono_modem_get_powered(modem) != TRUE)
> + return FALSE;
> +
> + return g_str_equal(remote, value);
The matching should be done on cards, not modems.
> +}
> +
> +static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
> + gpointer user_data)
> +{
> + struct sockaddr_sco saddr;
> + socklen_t alen;
> + int sk, nsk;
> + char remote[18];
> +
> + 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;
> +
> + bt_ba2str(&saddr.sco_bdaddr, remote);
> +
> + if (ofono_modem_find(slc_match, remote) == NULL) {
> + ofono_error("Rejecting SCO: No SLC connection found!");
> + close(nsk);
> + return TRUE;
> + }
> +
> + return TRUE;
> +}
> +
> +static int sco_init(void)
> +{
> + GIOChannel *sco_io;
> + struct sockaddr_sco saddr;
> + int sk, defer_setup = 1;
> +
> + 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,
> + &defer_setup, sizeof(defer_setup))< 0) {
> + ofono_warn("Can't enable deferred setup: %s (%d)",
> + strerror(errno), errno);
> + local_hfp_version = HFP_VERSION_1_5;
> + }
> +
> + 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;
> +}
>
> static void card_append_properties(struct ofono_handsfree_card *card,
> DBusMessageIter *dict)
> @@ -430,7 +528,7 @@ void ofono_handsfree_audio_unref(void)
>
> int __ofono_handsfree_audio_manager_init(void)
> {
> - return 0;
> + return sco_init();
> }
>
> void __ofono_handsfree_audio_manager_cleanup(void)
> @@ -443,4 +541,7 @@ void __ofono_handsfree_audio_manager_cleanup(void)
>
> ref_count = 1;
> ofono_handsfree_audio_unref();
> +
> + if (sco_watch> 0)
> + g_source_remove(sco_watch);
> }
Regards,
-Denis
next prev parent reply other threads:[~2013-03-01 19:20 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-28 18:52 [PATCH v0 00/10] handsfree-audio: Add Agent NewConnection() Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 01/10] bluetooth: Add new Bluetooth header Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 02/10] handsfree-audio: Move SCO to handsfree-audio.c Claudio Takahasi
2013-03-01 19:20 ` Denis Kenzior [this message]
2013-03-04 15:44 ` Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 03/10] handsfree-audio: Remove modem dependency Claudio Takahasi
2013-03-01 19:29 ` Denis Kenzior
2013-03-04 15:45 ` Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 04/10] handsfree-audio: Add NewConnection Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 05/10] handsfree-audio: Check local SCO address Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 06/10] handsfree-audio: Reject SCO if Card is not ready Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 07/10] handsfree-audio: Reject SCO if agent is unavailable Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 08/10] handsfree-audio: Check CVSD when registering agent Claudio Takahasi
2013-03-01 19:32 ` Denis Kenzior
2013-02-28 18:52 ` [PATCH v0 09/10] handsfree-audio: Add function to get hfp version Claudio Takahasi
2013-03-01 19:40 ` Denis Kenzior
2013-03-04 16:02 ` Claudio Takahasi
2013-03-04 18:04 ` Denis Kenzior
2013-03-04 19:24 ` Marcel Holtmann
2013-03-04 19:30 ` Denis Kenzior
2013-03-04 19:54 ` Claudio Takahasi
2013-02-28 18:52 ` [PATCH v0 10/10] hfp_hf_bluez5: Fix hard-coded " Claudio Takahasi
2013-03-04 20:48 ` [PATCH v1 0/6] handsfree-audio: Add Agent NewConnection() Claudio Takahasi
2013-03-04 20:48 ` [PATCH v1 1/6] bluetooth: Add new Bluetooth header Claudio Takahasi
2013-03-04 20:48 ` [PATCH v1 2/6] handsfree-audio: Move SCO to handsfree-audio.c Claudio Takahasi
2013-03-04 20:48 ` [PATCH v1 3/6] handsfree-audio: Add NewConnection Claudio Takahasi
2013-03-04 20:48 ` [PATCH v1 4/6] handsfree-audio: Check local SCO address Claudio Takahasi
2013-03-04 20:48 ` [PATCH v1 5/6] handsfree-audio: Reject SCO if Card is not ready Claudio Takahasi
2013-03-04 20:48 ` [PATCH v1 6/6] handsfree-audio: Reject SCO if agent is unavailable Claudio Takahasi
2013-03-04 22:44 ` [PATCH v1 0/6] handsfree-audio: Add Agent NewConnection() Denis Kenzior
2013-03-05 16:40 ` Claudio Takahasi
2013-03-05 20:38 ` Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5130FF6E.1030807@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox