All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v0 1/3] bluez5: Add SCO socket declarations
@ 2013-01-23 23:46 Claudio Takahasi
  2013-01-23 23:46 ` [PATCH v0 2/3] bluez5: Add bt_bacpy Claudio Takahasi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Claudio Takahasi @ 2013-01-23 23:46 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1863 bytes --]

Adds local copy of SCO Bluetooth sockets declarations, since the
objective to avoid including BlueZ library headers.
---
 plugins/bluez5.c        |  3 +++
 plugins/bluez5.h        | 28 ++++++++++++++++++++++++++++
 plugins/hfp_hf_bluez5.c |  2 ++
 3 files changed, 33 insertions(+)

diff --git a/plugins/bluez5.c b/plugins/bluez5.c
index 8d8b565..d471454 100644
--- a/plugins/bluez5.c
+++ b/plugins/bluez5.c
@@ -24,6 +24,9 @@
 #endif
 
 #include <errno.h>
+#include <stdint.h>
+#include <sys/socket.h>
+
 #include <glib.h>
 
 #define OFONO_API_SUBJECT_TO_CHANGE
diff --git a/plugins/bluez5.h b/plugins/bluez5.h
index 3aa8ffe..fd0704e 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -28,6 +28,34 @@
 #define HFP_HS_UUID	"0000111e-0000-1000-8000-00805f9b34fb"
 #define HFP_AG_UUID	"0000111f-0000-1000-8000-00805f9b34fb"
 
+#ifndef AF_BLUETOOTH
+#define AF_BLUETOOTH		31
+#define PF_BLUETOOTH		AF_BLUETOOTH
+#endif
+
+#define BTPROTO_SCO		2
+
+#define SOL_SCO			17
+
+#ifndef SOL_BLUETOOTH
+#define SOL_BLUETOOTH		274
+#endif
+
+#define BT_DEFER_SETUP		7
+
+/* BD Address */
+typedef struct {
+	uint8_t b[6];
+} __attribute__((packed)) bdaddr_t;
+
+#define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
+
+/* SCO socket address */
+struct sockaddr_sco {
+	sa_family_t	sco_family;
+	bdaddr_t	sco_bdaddr;
+};
+
 int bluetooth_register_profile(DBusConnection *conn, const char *uuid,
 					const char *name, const char *object);
 
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index f6ceb76..0e496ee 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -24,9 +24,11 @@
 #endif
 
 #include <errno.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <sys/socket.h>
 
 #include <glib.h>
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v0 2/3] bluez5: Add bt_bacpy
  2013-01-23 23:46 [PATCH v0 1/3] bluez5: Add SCO socket declarations Claudio Takahasi
@ 2013-01-23 23:46 ` Claudio Takahasi
  2013-01-23 23:46 ` [PATCH v0 3/3] hfp_hf_bluez5: Add SCO listen socket Claudio Takahasi
  2013-01-28 14:19 ` [PATCH v0 1/3] bluez5: Add SCO socket declarations Claudio Takahasi
  2 siblings, 0 replies; 4+ messages in thread
From: Claudio Takahasi @ 2013-01-23 23:46 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]

Adds a copy of BlueZ bacpy function.
---
 plugins/bluez5.c | 8 +++++++-
 plugins/bluez5.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/plugins/bluez5.c b/plugins/bluez5.c
index d471454..ea74fac 100644
--- a/plugins/bluez5.c
+++ b/plugins/bluez5.c
@@ -23,9 +23,10 @@
 #include <config.h>
 #endif
 
-#include <errno.h>
 #include <stdint.h>
+#include <errno.h>
 #include <sys/socket.h>
+#include <string.h>
 
 #include <glib.h>
 
@@ -39,6 +40,11 @@
 
 #define BLUEZ_PROFILE_MGMT_INTERFACE   BLUEZ_SERVICE ".ProfileManager1"
 
+void bt_bacpy(bdaddr_t *dst, const bdaddr_t *src)
+{
+	memcpy(dst, src, sizeof(bdaddr_t));
+}
+
 static void profile_register_cb(DBusPendingCall *call, gpointer user_data)
 {
 	DBusMessage *reply;
diff --git a/plugins/bluez5.h b/plugins/bluez5.h
index fd0704e..3921c7b 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -56,6 +56,8 @@ struct sockaddr_sco {
 	bdaddr_t	sco_bdaddr;
 };
 
+void bt_bacpy(bdaddr_t *dst, const bdaddr_t *src);
+
 int bluetooth_register_profile(DBusConnection *conn, const char *uuid,
 					const char *name, const char *object);
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v0 3/3] hfp_hf_bluez5: Add SCO listen socket
  2013-01-23 23:46 [PATCH v0 1/3] bluez5: Add SCO socket declarations Claudio Takahasi
  2013-01-23 23:46 ` [PATCH v0 2/3] bluez5: Add bt_bacpy Claudio Takahasi
@ 2013-01-23 23:46 ` Claudio Takahasi
  2013-01-28 14:19 ` [PATCH v0 1/3] bluez5: Add SCO socket declarations Claudio Takahasi
  2 siblings, 0 replies; 4+ messages in thread
From: Claudio Takahasi @ 2013-01-23 23:46 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3310 bytes --]

This patch adds the initial SCO server socket handling.
---
 plugins/hfp_hf_bluez5.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 0e496ee..84c4a55 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -64,6 +64,8 @@ struct hfp {
 static GHashTable *modem_hash = NULL;
 static GHashTable *devices_proxies = NULL;
 static GDBusClient *bluez = NULL;
+static GIOChannel *sco_io = NULL;
+static guint sco_watch = 0;
 
 static void hfp_debug(const char *str, void *user_data)
 {
@@ -378,6 +380,87 @@ static const GDBusMethodTable profile_methods[] = {
 	{ }
 };
 
+static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	struct sockaddr_sco saddr;
+	socklen_t optlen;
+	int sk, nsk;
+
+	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));
+	optlen = sizeof(saddr);
+
+	nsk = accept(sk, (struct sockaddr *) &saddr, &optlen);
+	if (nsk < 0)
+		return TRUE;
+
+	/* TODO: Verify if the device has a modem */
+
+	return TRUE;
+}
+
+static GIOChannel *sco_listen(int *err)
+{
+	struct sockaddr_sco addr;
+	GIOChannel *io;
+	int sk, defer_setup = 1;
+
+	sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
+	if (sk < 0) {
+		*err = -errno;
+		return NULL;
+	}
+
+	/* Bind to local address */
+	memset(&addr, 0, sizeof(addr));
+	addr.sco_family = AF_BLUETOOTH;
+	bt_bacpy(&addr.sco_bdaddr, BDADDR_ANY);
+
+	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+		close(sk);
+		*err = -errno;
+		return NULL;
+	}
+
+	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);
+		*err = -errno;
+	}
+
+	io = g_io_channel_unix_new(sk);
+	g_io_channel_set_close_on_unref(io, TRUE);
+	g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+
+	if (listen(sk, 5) < 0) {
+		g_io_channel_unref(io);
+		*err = -errno;
+		return NULL;
+	}
+
+	return io;
+}
+
+static int sco_init(void)
+{
+	GIOCondition cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
+	int err = 0;
+
+	sco_io = sco_listen(&err);
+	if (sco_io == NULL)
+		return err;
+
+	sco_watch = g_io_add_watch(sco_io, cond, sco_accept, NULL);
+
+	return 0;
+}
+
 static void connect_handler(DBusConnection *conn, void *user_data)
 {
 	DBG("Registering External Profile handler ...");
@@ -500,6 +583,12 @@ static int hfp_init(void)
 	if (DBUS_TYPE_UNIX_FD < 0)
 		return -EBADF;
 
+	err = sco_init();
+	if (err < 0) {
+		ofono_error("SCO: %s(%d)", strerror(-err), -err);
+		return err;
+	}
+
 	/* Registers External Profile handler */
 	if (!g_dbus_register_interface(conn, HFP_EXT_PROFILE_PATH,
 					BLUEZ_PROFILE_INTERFACE,
@@ -550,6 +639,12 @@ static void hfp_exit(void)
 
 	g_hash_table_destroy(modem_hash);
 	g_hash_table_destroy(devices_proxies);
+
+	if (sco_watch)
+		g_source_remove(sco_watch);
+
+	if (sco_io)
+		g_io_channel_unref(sco_io);
 }
 
 OFONO_PLUGIN_DEFINE(hfp_bluez5, "External Hands-Free Profile Plugin", VERSION,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v0 1/3] bluez5: Add SCO socket declarations
  2013-01-23 23:46 [PATCH v0 1/3] bluez5: Add SCO socket declarations Claudio Takahasi
  2013-01-23 23:46 ` [PATCH v0 2/3] bluez5: Add bt_bacpy Claudio Takahasi
  2013-01-23 23:46 ` [PATCH v0 3/3] hfp_hf_bluez5: Add SCO listen socket Claudio Takahasi
@ 2013-01-28 14:19 ` Claudio Takahasi
  2 siblings, 0 replies; 4+ messages in thread
From: Claudio Takahasi @ 2013-01-28 14:19 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

Hi Denis

On Wed, Jan 23, 2013 at 8:46 PM, Claudio Takahasi
<claudio.takahasi@openbossa.org> wrote:
> Adds local copy of SCO Bluetooth sockets declarations, since the
> objective to avoid including BlueZ library headers.
> ---
>  plugins/bluez5.c        |  3 +++
>  plugins/bluez5.h        | 28 ++++++++++++++++++++++++++++
>  plugins/hfp_hf_bluez5.c |  2 ++
>  3 files changed, 33 insertions(+)

Ignore this patch series. I will send a new series containing more SCO
related patches.

Regards,
Claudio

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-28 14:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-23 23:46 [PATCH v0 1/3] bluez5: Add SCO socket declarations Claudio Takahasi
2013-01-23 23:46 ` [PATCH v0 2/3] bluez5: Add bt_bacpy Claudio Takahasi
2013-01-23 23:46 ` [PATCH v0 3/3] hfp_hf_bluez5: Add SCO listen socket Claudio Takahasi
2013-01-28 14:19 ` [PATCH v0 1/3] bluez5: Add SCO socket declarations Claudio Takahasi

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.