From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 5/5] hfp_ag_bluez5: Add SCO listen socket
Date: Tue, 05 Feb 2013 17:27:00 +0100 [thread overview]
Message-ID: <1360081620-19458-5-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1360081620-19458-1-git-send-email-frederic.danis@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 3379 bytes --]
This patch adds the initial SCO server socket handling.
---
plugins/hfp_ag_bluez5.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index c6b858e..ee8c8bf 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -48,6 +48,7 @@ struct hfp_ag {
struct ofono_emulator *em;
bdaddr_t local;
bdaddr_t peer;
+ guint sco_watch;
};
static guint modemwatch_id;
@@ -64,6 +65,9 @@ static void free_hfp_ag(void *data)
if (hfp_ag == NULL)
return;
+ if (hfp_ag->sco_watch)
+ g_source_remove(hfp_ag->sco_watch);
+
hfp_ags = g_slist_remove(hfp_ags, hfp_ag);
g_free(hfp_ag);
}
@@ -206,6 +210,82 @@ static const GDBusMethodTable profile_methods[] = {
{ }
};
+static gboolean sco_cb(GIOChannel *io, GIOCondition cond,
+ gpointer user_data)
+
+{
+ struct hfp_ag *hfp_ag = user_data;
+ char adapter_address[18];
+ char device_address[18];
+
+ if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+ hfp_ag->sco_watch = 0;
+
+ bt_ba2str(&hfp_ag->local, adapter_address);
+ bt_ba2str(&hfp_ag->peer, device_address);
+ DBG("SCO: %s - %s (closed)", adapter_address, device_address);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean hfp_ag_sco_accept(int fd, struct sockaddr_sco *raddr)
+{
+ struct sockaddr_sco laddr;
+ socklen_t optlen;
+ GSList *l;
+ char adapter_address[18];
+ char device_address[18];
+ struct hfp_ag *hfp_ag = NULL;
+ GIOChannel *sco_io;
+ int err;
+
+ memset(&laddr, 0, sizeof(laddr));
+ optlen = sizeof(laddr);
+ if (getsockname(fd, (struct sockaddr *) &laddr, &optlen) < 0) {
+ err = errno;
+ ofono_error("SCO getsockname(): %s (%d)", strerror(err), err);
+ return FALSE;
+ }
+
+ for (l = hfp_ags; l; l = l->next) {
+ struct hfp_ag *tmp = l->data;
+
+ if (bt_bacmp(&laddr.sco_bdaddr, &tmp->local) != 0)
+ continue;
+
+ if (bt_bacmp(&raddr->sco_bdaddr, &tmp->peer) != 0)
+ continue;
+
+ hfp_ag = tmp;
+ break;
+ }
+
+ if (!hfp_ag) {
+ ofono_error("Rejecting SCO: SLC connection missing!");
+ return FALSE;
+ }
+
+ bt_ba2str(&laddr.sco_bdaddr, adapter_address);
+ bt_ba2str(&raddr->sco_bdaddr, device_address);
+ DBG("SCO: %s < %s (incoming)", adapter_address, device_address);
+
+ sco_io = g_io_channel_unix_new(fd);
+
+ g_io_channel_set_close_on_unref(sco_io, TRUE);
+ g_io_channel_set_flags(sco_io, G_IO_FLAG_NONBLOCK, NULL);
+
+ hfp_ag->sco_watch = g_io_add_watch(sco_io,
+ G_IO_ERR | G_IO_HUP | G_IO_NVAL,
+ sco_cb, hfp_ag);
+
+ g_io_channel_unref(sco_io);
+
+ return TRUE;
+}
+
static void sim_state_watch(enum ofono_sim_state new_state, void *data)
{
struct ofono_modem *modem = data;
@@ -219,6 +299,7 @@ static void sim_state_watch(enum ofono_sim_state new_state, void *data)
if (modems != NULL)
return;
+ bt_unregister_sco_server(hfp_ag_sco_accept);
bluetooth_unregister_profile(conn, HFP_AG_EXT_PROFILE_PATH);
return;
@@ -234,6 +315,8 @@ static void sim_state_watch(enum ofono_sim_state new_state, void *data)
bluetooth_register_profile(conn, HFP_AG_UUID, "hfp_ag",
HFP_AG_EXT_PROFILE_PATH);
+
+ bt_register_sco_server(hfp_ag_sco_accept);
}
static gboolean sim_watch_remove(gpointer key, gpointer value,
--
1.7.9.5
prev parent reply other threads:[~2013-02-05 16:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-05 16:26 [PATCH 1/5] bluez5: Add SCO server register/unregister =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2013-02-05 16:26 ` [PATCH 2/5] include: Add set/get data APIs to emulator =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2013-02-05 16:26 ` [PATCH 3/5] emulator: Add set/get data APIs =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2013-02-05 16:26 ` [PATCH 4/5] hfp_ag_bluez5: Add list of HFP AG emulators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2013-02-05 16:27 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
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=1360081620-19458-5-git-send-email-frederic.danis@linux.intel.com \
--to=frederic.danis@linux.intel.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