From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau <frederic.dalleau@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH v2 1/9] bluetooth: add functions for sco connection
Date: Thu, 17 Mar 2011 19:55:40 +0100 [thread overview]
Message-ID: <1300388148-925-2-git-send-email-frederic.dalleau@linux.intel.com> (raw)
In-Reply-To: <1300388148-925-1-git-send-email-frederic.dalleau@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 4307 bytes --]
---
plugins/bluetooth.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++
plugins/bluetooth.h | 7 +++
2 files changed, 129 insertions(+), 0 deletions(-)
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 7c2d5b0..89cc72d 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -64,6 +64,14 @@ struct cb_data {
GIOChannel *io;
};
+struct sco {
+ char laddress[18];
+ char raddress[18];
+ guint active_watch;
+ GIOChannel *active;
+ GIOChannel *listening;
+};
+
void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
char *buf, int size)
{
@@ -932,5 +940,119 @@ void bluetooth_unregister_server(struct server *server)
bluetooth_unref();
}
+static gboolean sco_disconnect_cb(GIOChannel *io, GIOCondition cond,
+ gpointer data)
+{
+ struct sco *sco = data;
+
+ if(cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
+ DBG("");
+ sco->active = NULL;
+ sco->active_watch = 0;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void sco_connect_cb(GIOChannel *channel, GError *err, gpointer data)
+{
+ struct sco *sco = data;
+
+ if(err != NULL) {
+ DBG("Failed to connect SCO channel: %s", err->message);
+ return;
+ }
+
+ DBG("sco->active_watch %d sco->active %p sco->listening %p",
+ sco->active_watch, sco->active, sco->listening);
+
+ if(sco->active_watch)
+ return;
+
+ sco->active_watch = g_io_add_watch(channel,
+ G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ sco_disconnect_cb, data);
+
+ if(sco->active)
+ g_io_channel_unref(sco->active);
+
+ sco->active = channel;
+ g_io_channel_set_close_on_unref(sco->active, TRUE);
+}
+
+void sco_connect(struct sco *sco)
+{
+ GError *err = NULL;
+
+ if(sco->active != NULL)
+ return;
+
+ sco->active = bt_io_connect(BT_IO_SCO, sco_connect_cb, sco,
+ NULL, &err, BT_IO_OPT_SOURCE, sco->laddress,
+ BT_IO_OPT_DEST, sco->raddress, BT_IO_OPT_INVALID);
+
+ if(sco->active)
+ g_io_channel_set_close_on_unref(sco->active, TRUE);
+
+ if(err != NULL) {
+ DBG("Failed to get device address: %s", err->message);
+ g_error_free(err);
+ }
+}
+
+void sco_disconnect(struct sco *sco)
+{
+ if(sco->active == NULL)
+ return;
+
+ g_source_remove(sco->active_watch);
+ sco->active_watch = 0;
+ sco->active = NULL;
+}
+
+struct sco *sco_register_server(GIOChannel *channel)
+{
+ struct sco *sco;
+ GError *err = NULL;
+
+ sco = g_try_malloc0(sizeof(struct sco));
+ if(sco == NULL)
+ return NULL;
+
+ sco->listening = bt_io_listen(BT_IO_SCO, sco_connect_cb, NULL, sco,
+ NULL, &err, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
+ BT_IO_OPT_INVALID);
+
+ if(err != NULL) {
+ DBG("Failed to listen incoming SCO: %s", err->message);
+ g_error_free(err);
+ err = NULL;
+ }
+
+ if(sco->listening)
+ g_io_channel_set_close_on_unref(sco->listening, TRUE);
+
+ bt_io_get(channel, BT_IO_RFCOMM, &err, BT_IO_OPT_SOURCE, sco->laddress,
+ BT_IO_OPT_DEST, sco->raddress, BT_IO_OPT_INVALID);
+
+ if(err != NULL) {
+ DBG("Failed to get device address: %s", err->message);
+ g_error_free(err);
+ }
+
+ return sco;
+}
+
+void sco_unregister_server(struct sco *sco)
+{
+ sco_disconnect(sco);
+
+ if(sco->listening != NULL)
+ g_io_channel_unref(sco->listening);
+
+ g_free(sco);
+}
+
OFONO_PLUGIN_DEFINE(bluetooth, "Bluetooth Utils Plugins", VERSION,
OFONO_PLUGIN_PRIORITY_DEFAULT, NULL, NULL)
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 505d908..ba88e96 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -42,6 +42,8 @@ struct bluetooth_profile {
struct server;
+struct sco;
+
typedef void (*ConnectFunc)(GIOChannel *io, GError *err, gpointer user_data);
int bluetooth_register_uuid(const char *uuid,
@@ -52,6 +54,11 @@ struct server *bluetooth_register_server(guint8 channel, const char *sdp_record,
ConnectFunc cb, gpointer user_data);
void bluetooth_unregister_server(struct server *server);
+void sco_connect(struct sco *sco);
+void sco_disconnect(struct sco *sco);
+struct sco *sco_register_server(GIOChannel *channel);
+void sco_unregister_server(struct sco *sco);
+
void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
char *buf, int size);
--
1.7.1
next prev parent reply other threads:[~2011-03-17 18:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-17 18:55 [PATCH v2 0/9] HSP profile implementation =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau [this message]
2011-03-18 20:27 ` [PATCH v2 1/9] bluetooth: add functions for sco connection Denis Kenzior
2011-03-19 11:06 ` Johan Hedberg
2011-03-21 17:08 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 2/9] emulator: add hsp emulator type =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 3/9] hsp_ag: add hsp atom type =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 4/9] hsp_ag: Initial plugin commit =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 5/9] hsp_ag: add modem watch =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 6/9] emulator: add CKPD support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-18 20:25 ` Denis Kenzior
2011-03-21 18:15 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-21 18:28 ` Denis Kenzior
2011-03-17 18:55 ` [PATCH v2 7/9] emulator: add audio connection API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 8/9] emulator: implement " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-17 18:55 ` [PATCH v2 9/9] hsp_ag: add audio connection support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
2011-03-21 12:53 ` [PATCH v2 0/9] HSP profile implementation Luiz Augusto von Dentz
2011-03-21 18:10 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Dalleau
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=1300388148-925-2-git-send-email-frederic.dalleau@linux.intel.com \
--to=frederic.dalleau@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 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.