All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] bluetooth: add server support
@ 2011-01-31 20:51 Gustavo F. Padovan
  2011-01-31 20:51 ` [PATCH 2/8] bluetooth: add support to register Bluetooth Service Gustavo F. Padovan
  2011-02-01 14:17 ` [PATCH 1/8] bluetooth: add server support Frederic Danis
  0 siblings, 2 replies; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-01-31 20:51 UTC (permalink / raw)
  To: ofono

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

Initial code to have support to listen over a RFCOMM socket for incoming
connections.
---
 Makefile.am         |    1 +
 plugins/bluetooth.c |  165 +++++++++++++++++++++++++++++++++++++++++++++++++++
 plugins/bluetooth.h |   11 ++++
 3 files changed, 177 insertions(+), 0 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index a38fcb9..77b1453 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -321,6 +321,7 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
 builtin_modules += hfp
 builtin_sources += plugins/hfp.c plugins/bluetooth.h
 
+builtin_sources += $(btio_sources)
 builtin_cflags += @BLUEZ_CFLAGS@
 builtin_libadd += @BLUEZ_LIBS@
 endif
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 93dd7a1..dcf75e6 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -35,13 +35,58 @@
 
 #include <ofono/dbus.h>
 
+#include <btio.h>
 #include "bluetooth.h"
 
 static DBusConnection *connection;
 static GHashTable *uuid_hash = NULL;
 static GHashTable *adapter_address_hash = NULL;
+static GSList *server_list = NULL;
 static gint bluetooth_refcount;
 
+struct server {
+	guint16		service;
+	gchar		*name;
+	guint8		channel;
+	GIOChannel	*io;
+	char		*adapter;
+	guint		handle;
+	ConnectFunc	connect_cb;
+	gpointer	user_data;
+};
+
+typedef struct {
+	guint8 b[6];
+} __attribute__((packed)) bdaddr_t;
+
+static void baswap(bdaddr_t *dst, const bdaddr_t *src)
+{
+	register unsigned char *d = (unsigned char *) dst;
+	register const unsigned char *s = (const unsigned char *) src;
+	register int i;
+
+	for (i = 0; i < 6; i++)
+		d[i] = s[5-i];
+}
+
+static int str2ba(const char *str, bdaddr_t *ba)
+{
+	guint8 b[6];
+	const char *ptr = str;
+	int i;
+
+	for (i = 0; i < 6; i++) {
+		b[i] = (guint8) strtol(ptr, NULL, 16);
+		if (i != 5 && !(ptr = strchr(ptr, ':')))
+			ptr = ":00:00:00:00:00";
+		ptr++;
+	}
+
+	baswap(ba, (bdaddr_t *) b);
+
+	return 0;
+}
+
 void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
 				char *buf, int size)
 {
@@ -371,6 +416,70 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
 	return TRUE;
 }
 
+static void server_stop(gpointer data)
+{
+	struct server *server = data;
+
+	if (server->handle > 0) {
+		DBusMessage *msg;
+
+		msg = dbus_message_new_method_call(BLUEZ_SERVICE,
+						server->adapter,
+						BLUEZ_SERVICE_INTERFACE,
+						"RemoveRecord");
+		dbus_message_append_args(msg, DBUS_TYPE_UINT32, &server->handle,
+						DBUS_TYPE_INVALID);
+		g_dbus_send_message(connection, msg);
+
+		server->handle = 0;
+	}
+
+	if (server->io != NULL) {
+		g_io_channel_shutdown(server->io, TRUE, NULL);
+		g_io_channel_unref(server->io);
+		server->io = NULL;
+	}
+
+	g_free(server->adapter);
+	server->adapter = NULL;
+}
+
+static void new_connection(GIOChannel *io, gpointer user_data)
+{
+	struct server *server = user_data;
+
+	DBG("%p", server);
+}
+
+static void server_start(gpointer data, gpointer user_data)
+{
+	struct server *server = data;
+	char *addr, *path = user_data;
+	bdaddr_t baddr;
+	GError *err = NULL;
+
+	if (server->handle != 0)
+		return;
+
+	addr = g_hash_table_lookup(adapter_address_hash, path);
+	str2ba(addr, &baddr);
+	server->io = bt_io_listen(BT_IO_RFCOMM, NULL, new_connection,
+					server, NULL, &err,
+					BT_IO_OPT_SOURCE_BDADDR, &baddr,
+					BT_IO_OPT_CHANNEL, server->channel,
+					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
+					BT_IO_OPT_INVALID);
+	if (server->io == NULL) {
+		ofono_error("Bluetooth %s register failed: %s",
+					server->name, err->message);
+		g_error_free(err);
+		server_stop(server);
+		return;
+	}
+
+	server->adapter = g_strdup(path);
+}
+
 static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data)
 {
 	const char *path = user_data;
@@ -395,6 +504,9 @@ static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data)
 	g_hash_table_insert(adapter_address_hash,
 				g_strdup(path), g_strdup(addr));
 
+	if (server_list)
+		g_slist_foreach(server_list, server_start, (gpointer)path);
+
 	for (l = device_list; l; l = l->next) {
 		const char *device = l->data;
 
@@ -429,11 +541,26 @@ static gboolean adapter_removed(DBusConnection *connection,
 				DBusMessage *message, void *user_data)
 {
 	const char *path;
+	GSList *l;
 
 	if (dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
 				DBUS_TYPE_INVALID) == TRUE)
 		g_hash_table_remove(adapter_address_hash, path);
 
+	for (l = server_list; l; l = l->next) {
+		struct server *server = l->data;
+
+		if (!server->adapter)
+			continue;
+
+		if (!g_str_equal(path, server->adapter))
+			continue;
+
+		/* Don't remove handle if the adapter has been removed */
+		server->handle = 0;
+		server_stop(server);
+	}
+
 	return TRUE;
 }
 
@@ -590,5 +717,43 @@ void bluetooth_unregister_uuid(const char *uuid)
 	bluetooth_unref();
 }
 
+struct server *bluetooth_register_server(guint16 service, char *name,
+						guint8 channel, ConnectFunc cb,
+						gpointer user_data)
+{
+	struct server *server;
+
+	server = g_try_new0(struct server, 1);
+	if (!server)
+		return NULL;
+
+	bluetooth_ref();
+
+	server->service = service;
+	server->name = g_strdup(name);
+	server->channel = channel;
+	server->connect_cb = cb;
+	server->user_data = user_data;
+
+	server_list = g_slist_prepend(server_list, server);
+
+	bluetooth_send_with_reply("/", BLUEZ_MANAGER_INTERFACE, "GetProperties",
+					manager_properties_cb, NULL, NULL, -1,
+					DBUS_TYPE_INVALID);
+
+	return server;
+}
+
+void bluetooth_unregister_server(struct server *server)
+{
+	server_list = g_slist_remove(server_list, server);
+
+	server_stop(server);
+	g_free(server->name);
+	g_free(server);
+
+	bluetooth_unref();
+}
+
 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 42b0d13..f6fc6a6 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -23,6 +23,7 @@
 #define	BLUEZ_MANAGER_INTERFACE		BLUEZ_SERVICE ".Manager"
 #define	BLUEZ_ADAPTER_INTERFACE		BLUEZ_SERVICE ".Adapter"
 #define	BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device"
+#define	BLUEZ_SERVICE_INTERFACE		BLUEZ_SERVICE ".Service"
 
 #define DBUS_TIMEOUT 15
 
@@ -39,10 +40,20 @@ struct bluetooth_profile {
 	void (*set_alias)(const char *device, const char *);
 };
 
+
+typedef void (*ConnectFunc)(GIOChannel *io, GError *err, gpointer user_data);
+
+struct server;
+
 int bluetooth_register_uuid(const char *uuid,
 				struct bluetooth_profile *profile);
 void bluetooth_unregister_uuid(const char *uuid);
 
+struct server *bluetooth_register_server(guint16 service, char *name,
+						guint8 channel, ConnectFunc cb,
+						gpointer user_data);
+void bluetooth_unregister_server(struct server *server);
+
 void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
 							char *buf, int size);
 
-- 
1.7.4.rc3


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

* [PATCH 2/8] bluetooth: add support to register Bluetooth Service
  2011-01-31 20:51 [PATCH 1/8] bluetooth: add server support Gustavo F. Padovan
@ 2011-01-31 20:51 ` Gustavo F. Padovan
  2011-01-31 20:51   ` [PATCH 3/8] bluetooth: add Request auth code for new connections Gustavo F. Padovan
  2011-02-01 14:25   ` [PATCH 2/8] bluetooth: add support to register Bluetooth Service Frederic Danis
  2011-02-01 14:17 ` [PATCH 1/8] bluetooth: add server support Frederic Danis
  1 sibling, 2 replies; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-01-31 20:51 UTC (permalink / raw)
  To: ofono

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

---
 plugins/bluetooth.c |   75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index dcf75e6..0b5a021 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -44,6 +44,43 @@ static GHashTable *adapter_address_hash = NULL;
 static GSList *server_list = NULL;
 static gint bluetooth_refcount;
 
+static const gchar *dun_record = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>	\
+<record>									\
+  <attribute id=\"0x0001\">							\
+    <sequence>									\
+      <uuid value=\"0x1103\"/>							\
+    </sequence>									\
+  </attribute>									\
+										\
+  <attribute id=\"0x0004\">							\
+    <sequence>									\
+      <sequence>								\
+        <uuid value=\"0x0100\"/>						\
+      </sequence>								\
+      <sequence>								\
+        <uuid value=\"0x0003\"/>						\
+        <uint8 value=\"%u\" name=\"channel\"/>					\
+      </sequence>								\
+      <sequence>								\
+        <uuid value=\"0x0008\"/>						\
+      </sequence>								\
+    </sequence>									\
+  </attribute>									\
+										\
+  <attribute id=\"0x0009\">							\
+    <sequence>									\
+      <sequence>								\
+        <uuid value=\"0x1103\"/>						\
+        <uint16 value=\"0x0100\" name=\"version\"/>				\
+      </sequence>								\
+    </sequence>									\
+  </attribute>									\
+										\
+  <attribute id=\"0x0100\">							\
+    <text value=\"%s\" name=\"name\"/>						\
+  </attribute>									\
+</record>";
+
 struct server {
 	guint16		service;
 	gchar		*name;
@@ -451,12 +488,40 @@ static void new_connection(GIOChannel *io, gpointer user_data)
 	DBG("%p", server);
 }
 
+static void add_record_cb(DBusPendingCall *call, gpointer user_data)
+{
+	struct server *server = user_data;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	DBusError derr;
+	guint32 handle;
+
+	dbus_error_init(&derr);
+
+	if (dbus_set_error_from_message(&derr, reply)) {
+		ofono_error("Replied with an error: %s, %s",
+					derr.name, derr.message);
+		dbus_error_free(&derr);
+		server_stop(server);
+		goto done;
+	}
+
+	dbus_message_get_args(reply, NULL, DBUS_TYPE_UINT32, &handle,
+					DBUS_TYPE_INVALID);
+	server->handle = handle;
+
+	ofono_info("Registered: %s, handle: 0x%x", server->name, handle);
+
+done:
+	dbus_message_unref(reply);
+}
+
 static void server_start(gpointer data, gpointer user_data)
 {
 	struct server *server = data;
 	char *addr, *path = user_data;
 	bdaddr_t baddr;
 	GError *err = NULL;
+	gchar *xml;
 
 	if (server->handle != 0)
 		return;
@@ -478,6 +543,16 @@ static void server_start(gpointer data, gpointer user_data)
 	}
 
 	server->adapter = g_strdup(path);
+
+	xml = g_markup_printf_escaped(dun_record, server->channel,
+					server->name);
+
+	bluetooth_send_with_reply(path, BLUEZ_SERVICE_INTERFACE, "AddRecord",
+					add_record_cb, server, NULL, -1,
+					DBUS_TYPE_STRING, &xml,
+					DBUS_TYPE_INVALID);
+
+	g_free(xml);
 }
 
 static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data)
-- 
1.7.4.rc3


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

* [PATCH 3/8] bluetooth: add Request auth code for new connections
  2011-01-31 20:51 ` [PATCH 2/8] bluetooth: add support to register Bluetooth Service Gustavo F. Padovan
@ 2011-01-31 20:51   ` Gustavo F. Padovan
  2011-01-31 20:51     ` [PATCH 4/8] include: add public headed to emulator atom Gustavo F. Padovan
  2011-02-01 14:25   ` [PATCH 2/8] bluetooth: add support to register Bluetooth Service Frederic Danis
  1 sibling, 1 reply; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-01-31 20:51 UTC (permalink / raw)
  To: ofono

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

Now a RFCOMM incoming connection can be made, all the pieces are here.
---
 plugins/bluetooth.c |  123 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 122 insertions(+), 1 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 0b5a021..f3b9140 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -90,6 +90,9 @@ struct server {
 	guint		handle;
 	ConnectFunc	connect_cb;
 	gpointer	user_data;
+	gboolean	pending_auth;
+	GIOChannel	*client_io;
+	guint		client_watch;
 };
 
 typedef struct {
@@ -453,10 +456,25 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
 	return TRUE;
 }
 
+static void disconnect(struct server *server)
+{
+	if (server->client_io == NULL)
+		return;
+
+	server->client_io = NULL;
+
+	if (server->client_watch > 0) {
+		g_source_remove(server->client_watch);
+		server->client_watch = 0;
+	}
+}
+
 static void server_stop(gpointer data)
 {
 	struct server *server = data;
 
+	disconnect(server);
+
 	if (server->handle > 0) {
 		DBusMessage *msg;
 
@@ -481,11 +499,114 @@ static void server_stop(gpointer data)
 	server->adapter = NULL;
 }
 
+static void cancel_authorization(struct server *server)
+{
+	DBusMessage *msg;
+
+	msg = dbus_message_new_method_call(BLUEZ_SERVICE, server->adapter,
+			BLUEZ_SERVICE_INTERFACE, "CancelAuthorization");
+	if (!msg)
+		return;
+
+	g_dbus_send_message(connection, msg);
+}
+
+static void auth_cb(DBusPendingCall *call, gpointer user_data)
+{
+	struct server *server = user_data;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	DBusError derr;
+	GError *err = NULL;
+
+	dbus_error_init(&derr);
+
+	server->pending_auth = FALSE;
+
+	if (dbus_set_error_from_message(&derr, reply)) {
+		ofono_error("RequestAuthorization error: %s, %s",
+				derr.name, derr.message);
+
+		if (dbus_error_has_name(&derr, DBUS_ERROR_NO_REPLY))
+			cancel_authorization(server);
+
+		dbus_error_free(&derr);
+		goto failed;
+	}
+
+	ofono_info("RequestAuthorization() succeeded");
+
+	if (!bt_io_accept(server->client_io, server->connect_cb,
+					server->user_data, NULL, &err)) {
+		ofono_error("%s", err->message);
+		g_error_free(err);
+		goto failed;
+	}
+	return;
+
+failed:
+	dbus_message_unref(reply);
+	disconnect(server);
+}
+
+static gboolean client_event(GIOChannel *io, GIOCondition cond,
+						gpointer user_data)
+{
+	struct server *server = user_data;
+
+	if (server->pending_auth == TRUE)
+		cancel_authorization(server);
+
+	server->pending_auth = FALSE;
+
+	disconnect(server);
+
+	return FALSE;
+}
+
 static void new_connection(GIOChannel *io, gpointer user_data)
 {
 	struct server *server = user_data;
+	GError *err = NULL;
+	char address[18];
+	const char *addr;
+	guint8 channel;
+	int ret;
+
+	if (server->client_watch != 0) {
+		ofono_info("Client already connected");
+		return;
+	}
+
+	bt_io_get(io, BT_IO_RFCOMM, &err, BT_IO_OPT_DEST, address,
+					BT_IO_OPT_CHANNEL, &channel,
+					BT_IO_OPT_INVALID);
+	if (err) {
+		ofono_error("%s", err->message);
+		g_error_free(err);
+		return;
+	}
+
+	ofono_info("New connection from: %s, channel %u", address, channel);
+
+	addr = address;
+	ret = bluetooth_send_with_reply(server->adapter,
+					BLUEZ_SERVICE_INTERFACE,
+					"RequestAuthorization",
+					auth_cb, server, NULL, DBUS_TIMEOUT,
+					DBUS_TYPE_STRING, &addr,
+					DBUS_TYPE_UINT32, &server->handle,
+					DBUS_TYPE_INVALID);
+	if (ret < 0) {
+		ofono_error("RequestAuthorization() failed");
+		return;
+	}
+
+	server->client_io = io;
+	server->client_watch = g_io_add_watch(server->client_io,
+					G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+					client_event, server);
 
-	DBG("%p", server);
+	server->pending_auth = TRUE;
 }
 
 static void add_record_cb(DBusPendingCall *call, gpointer user_data)
-- 
1.7.4.rc3


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

* [PATCH 4/8] include: add public headed to emulator atom
  2011-01-31 20:51   ` [PATCH 3/8] bluetooth: add Request auth code for new connections Gustavo F. Padovan
@ 2011-01-31 20:51     ` Gustavo F. Padovan
  2011-01-31 20:51       ` [PATCH 5/8] emulator: Add emulator atom in oFono Gustavo F. Padovan
  0 siblings, 1 reply; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-01-31 20:51 UTC (permalink / raw)
  To: ofono

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

---
 include/emulator.h |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)
 create mode 100644 include/emulator.h

diff --git a/include/emulator.h b/include/emulator.h
new file mode 100644
index 0000000..1287b47
--- /dev/null
+++ b/include/emulator.h
@@ -0,0 +1,55 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __OFONO_EMULATOR_H
+#define __OFONO_EMULATOR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ofono/types.h>
+
+struct ofono_emulator;
+
+struct ofono_emulator_driver {
+	const char *name;
+	enum ofono_atom_type type;
+	int (*probe)(struct ofono_emulator *emulator,
+			struct ofono_modem *modem);
+	void (*remove)();
+};
+
+int ofono_emulator_enable(struct ofono_emulator *emulator, int fd);
+void ofono_emulator_disable(struct ofono_emulator *emulator);
+void ofono_emulator_remove(struct ofono_emulator *emulator);
+struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
+					struct ofono_emulator_driver *driver);
+
+int ofono_emulator_driver_register(const struct ofono_emulator_driver *driver);
+void ofono_emulator_driver_unregister(
+				const struct ofono_emulator_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_EMULATOR_H */
-- 
1.7.4.rc3


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

* [PATCH 5/8] emulator: Add emulator atom in oFono
  2011-01-31 20:51     ` [PATCH 4/8] include: add public headed to emulator atom Gustavo F. Padovan
@ 2011-01-31 20:51       ` Gustavo F. Padovan
  2011-01-31 20:52         ` [PATCH 6/8] dun_gw: Add DUN server plugin for oFono Gustavo F. Padovan
  0 siblings, 1 reply; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-01-31 20:51 UTC (permalink / raw)
  To: ofono

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

Create emulator atom when modem state changes to online. The emulator
driver probes each driver to create specific emulator like DUN, HFP AG,
etc. Once get client connection request, create GAtServer to talk AT
commands with client side.

Based on a patch from Zhenhua Zhang <zhenhua.zhang@intel.com>
---
 Makefile.am        |    5 +-
 include/emulator.h |    5 +-
 src/emulator.c     |  281 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ofono.h        |    5 +
 4 files changed, 291 insertions(+), 5 deletions(-)
 create mode 100644 src/emulator.c

diff --git a/Makefile.am b/Makefile.am
index 77b1453..1ca08e9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,7 +14,7 @@ pkginclude_HEADERS = include/log.h include/plugin.h include/history.h \
 			include/audio-settings.h include/nettime.h \
 			include/ctm.h include/cdma-voicecall.h \
 			include/cdma-sms.h include/sim-auth.h \
-			include/gprs-provision.h
+			include/gprs-provision.h include/emulator.h
 
 nodist_pkginclude_HEADERS = include/version.h
 
@@ -363,7 +363,8 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
 			src/simfs.c src/simfs.h src/audio-settings.c \
 			src/smsagent.c src/smsagent.h src/ctm.c \
 			src/cdma-voicecall.c src/sim-auth.c \
-			src/message.h src/message.c src/gprs-provision.c
+			src/message.h src/message.c src/gprs-provision.c \
+			src/emulator.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/include/emulator.h b/include/emulator.h
index 1287b47..bc89071 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -33,9 +33,8 @@ struct ofono_emulator;
 struct ofono_emulator_driver {
 	const char *name;
 	enum ofono_atom_type type;
-	int (*probe)(struct ofono_emulator *emulator,
-			struct ofono_modem *modem);
-	void (*remove)();
+	int (*probe)(struct ofono_emulator *emulator);
+	void (*remove)(void);
 };
 
 int ofono_emulator_enable(struct ofono_emulator *emulator, int fd);
diff --git a/src/emulator.c b/src/emulator.c
new file mode 100644
index 0000000..aa71e21
--- /dev/null
+++ b/src/emulator.c
@@ -0,0 +1,281 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <glib.h>
+#include <gdbus.h>
+
+#include "ofono.h"
+#include "common.h"
+#include "gatserver.h"
+
+struct ofono_emulator {
+	struct ofono_modem *modem;
+	struct ofono_atom *atom;
+	GAtServer *server;
+	struct ofono_emulator_driver *driver;
+};
+
+static GSList *emulator_drivers = NULL;
+
+static void ofono_emulator_debug(const char *str, void *data)
+{
+	g_print("%s: %s\n", (char *)data, str);
+}
+
+void ofono_emulator_remove(struct ofono_emulator *emulator)
+{
+	if (emulator == NULL)
+		return;
+
+	__ofono_atom_free(emulator->atom);
+}
+
+static void ppp_connect(const char *iface, const char *local,
+			const char *remote,
+			const char *dns1, const char *dns2,
+			gpointer user_data)
+{
+	DBG("Network Device: %s\n", iface);
+	DBG("IP Address: %s\n", local);
+	DBG("Remote IP Address: %s\n", remote);
+	DBG("Primary DNS Server: %s\n", dns1);
+	DBG("Secondary DNS Server: %s\n", dns2);
+}
+
+static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+
+	DBG("");
+
+	g_at_ppp_unref(e->ppp);
+	e->ppp = NULL;
+
+	if (e->server == NULL)
+		return;
+
+	g_at_server_resume(e->server);
+
+	g_at_server_send_final(e->server, G_AT_SERVER_RESULT_NO_CARRIER);
+}
+
+static gboolean setup_ppp(gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	GAtServer *server = e->server;
+	GAtIO *io;
+
+	DBG("");
+
+	io = g_at_server_get_io(server);
+
+	g_at_server_suspend(server);
+
+	e->ppp = g_at_ppp_server_new_from_io(io, DUN_SERVER_ADDRESS);
+	if (e->ppp == NULL) {
+		g_at_server_resume(server);
+		return FALSE;
+	}
+
+	g_at_ppp_set_server_info(e->ppp, DUN_PEER_ADDRESS,
+					DUN_DNS_SERVER_1, DUN_DNS_SERVER_2);
+
+	g_at_ppp_set_credentials(e->ppp, "", "");
+	g_at_ppp_set_debug(e->ppp, ofono_emulator_debug, "PPP");
+
+	g_at_ppp_set_connect_function(e->ppp, ppp_connect, e);
+	g_at_ppp_set_disconnect_function(e->ppp, ppp_disconnect, e);
+
+	return FALSE;
+}
+
+static gboolean dial_call(struct ofono_emulator *e, const char *dial_str)
+{
+	char c = *dial_str;
+
+	DBG("dial call %s", dial_str);
+
+	if (c == '*' || c == '#' || c == 'T' || c == 't') {
+
+		g_at_server_send_intermediate(e->server, "CONNECT");
+		g_idle_add(setup_ppp, e);
+	}
+
+	return TRUE;
+}
+
+static void dial_cb(GAtServerRequestType type, GAtResult *result,
+					gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+	GAtServer *server = e->server;
+	GAtResultIter iter;
+	const char *dial_str;
+
+	DBG("");
+
+	if (type != G_AT_SERVER_REQUEST_TYPE_SET)
+		goto error;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "D"))
+		goto error;
+
+	dial_str = g_at_result_iter_raw_line(&iter);
+	if (!dial_str)
+		goto error;
+
+	if (e->ppp)
+		goto error;
+
+	if (!dial_call(e, dial_str))
+		goto error;
+
+	return;
+
+error:
+	g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+}
+
+void ofono_emulator_disable(struct ofono_emulator *e)
+{
+	DBG("");
+
+	g_at_server_shutdown(e->server);
+	g_at_server_unref(e->server);
+	e->server = NULL;
+}
+
+static void emulator_disconnect_cb(gpointer user_data)
+{
+	struct ofono_emulator *e = user_data;
+
+	if (e == NULL)
+		return;
+
+	ofono_emulator_disable(e);
+}
+
+int ofono_emulator_enable(struct ofono_emulator *e, int fd)
+{
+	GIOChannel *io;
+
+	if (fd < 0)
+		return -EIO;
+
+	io = g_io_channel_unix_new(fd);
+
+	e->server = g_at_server_new(io);
+	if (!e->server) {
+		g_free(e);
+		return -ENOMEM;
+	}
+
+	g_at_server_set_debug(e->server, ofono_emulator_debug, "Server");
+	g_at_server_set_disconnect_function(e->server,
+						emulator_disconnect_cb, e);
+
+	return 0;
+}
+
+static void emulator_remove(struct ofono_atom *atom)
+{
+	struct ofono_emulator *e =  __ofono_atom_get_data(atom);
+
+	DBG("");
+
+	if (e->server)
+		ofono_emulator_disable(e);
+
+	if (e->driver->remove)
+		e->driver->remove();
+
+	g_free(e);
+}
+
+struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
+					struct ofono_emulator_driver *driver)
+{
+	struct ofono_emulator *e;
+
+	DBG("");
+
+	if (driver->probe == NULL)
+		return NULL;
+
+	e = g_try_new0(struct ofono_emulator, 1);
+	if (!e)
+		return NULL;
+
+	e->modem = modem;
+	e->driver = driver;
+
+	if (driver->probe(e) < 0) {
+		g_free(e);
+		return NULL;
+	}
+
+	return e;
+}
+
+void __ofono_emulator_probe_drivers(struct ofono_modem *modem)
+{
+	struct ofono_emulator_driver *driver;
+	GSList *l;
+
+	for (l = emulator_drivers; l; l = l->next) {
+		struct ofono_emulator *e;
+
+		driver = l->data;
+
+		e = ofono_emulator_create(modem, driver);
+		if (!e)
+			continue;
+
+		e->atom = __ofono_modem_add_atom(modem, driver->type,
+							emulator_remove, e);
+	}
+}
+
+int ofono_emulator_driver_register(const struct ofono_emulator_driver *driver)
+{
+	DBG("driver: %p name: %s", driver, driver->name);
+
+	emulator_drivers = g_slist_prepend(emulator_drivers, (void *)driver);
+
+	return 0;
+}
+
+void ofono_emulator_driver_unregister(
+				const struct ofono_emulator_driver *driver)
+{
+	DBG("driver: %p name: %s", driver, driver->name);
+
+	emulator_drivers = g_slist_remove(emulator_drivers, driver);
+}
diff --git a/src/ofono.h b/src/ofono.h
index 6ba0187..64d13e7 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -128,6 +128,7 @@ enum ofono_atom_type {
 	OFONO_ATOM_TYPE_CTM,
 	OFONO_ATOM_TYPE_CDMA_VOICECALL_MANAGER,
 	OFONO_ATOM_TYPE_SIM_AUTH,
+	OFONO_ATOM_TYPE_EMULATOR_DUN,
 };
 
 enum ofono_atom_watch_condition {
@@ -430,3 +431,7 @@ ofono_bool_t __ofono_gprs_provision_get_settings(const char *mcc,
 void __ofono_gprs_provision_free_settings(
 				struct ofono_gprs_provision_data *settings,
 				int count);
+
+#include <ofono/emulator.h>
+
+void __ofono_emulator_probe_drivers(struct ofono_modem *modem);
-- 
1.7.4.rc3


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

* [PATCH 6/8] dun_gw: Add DUN server plugin for oFono
  2011-01-31 20:51       ` [PATCH 5/8] emulator: Add emulator atom in oFono Gustavo F. Padovan
@ 2011-01-31 20:52         ` Gustavo F. Padovan
  2011-01-31 20:52           ` [PATCH 7/8] emulator: Implement dialing up for DUN Gustavo F. Padovan
  0 siblings, 1 reply; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-01-31 20:52 UTC (permalink / raw)
  To: ofono

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

DUN server is probed when modem state changes to online. It registers
DUN record to Bluetooth adapter and wait for incoming DUN connection.

Based on a patch from Zhenhua Zhang <zhenhua.zhang@intel.com>
---
 Makefile.am         |    3 +
 plugins/bluetooth.h |    3 +
 plugins/dun_gw.c    |  156 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 162 insertions(+), 0 deletions(-)
 create mode 100644 plugins/dun_gw.c

diff --git a/Makefile.am b/Makefile.am
index 1ca08e9..1794ace 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -321,6 +321,9 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
 builtin_modules += hfp
 builtin_sources += plugins/hfp.c plugins/bluetooth.h
 
+builtin_modules += dun_gw
+builtin_sources += plugins/dun_gw.c plugins/bluetooth.h
+
 builtin_sources += $(btio_sources)
 builtin_cflags += @BLUEZ_CFLAGS@
 builtin_libadd += @BLUEZ_LIBS@
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index f6fc6a6..7a6c858 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -32,6 +32,9 @@
 /* Profiles bitfield */
 #define HFP_AG 0x01
 
+/* Server bitfield */
+#define DUN_GW 0x01
+
 struct bluetooth_profile {
 	const char *name;
 	int (*create)(const char *device, const char *dev_addr,
diff --git a/plugins/dun_gw.c b/plugins/dun_gw.c
new file mode 100644
index 0000000..78b87e2
--- /dev/null
+++ b/plugins/dun_gw.c
@@ -0,0 +1,156 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <glib.h>
+#include <ofono.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <gdbus.h>
+
+#include "bluetooth.h"
+
+#define DUN_GW_CHANNEL	1
+
+static struct server *server;
+static guint modemwatch_id;
+static guint channel_watch;
+
+static gboolean dun_gw_disconnect_cb(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	struct ofono_emulator *emulator = user_data;
+
+	ofono_emulator_disable(emulator);
+
+	return FALSE;
+}
+
+static void dun_gw_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
+{
+	struct ofono_emulator *emulator = user_data;
+	int fd;
+
+	DBG("");
+
+	if (err) {
+		DBG("%s", err->message);
+		return;
+	}
+
+	fd = g_io_channel_unix_get_fd(io);
+
+	if (ofono_emulator_enable(emulator, fd) < 0)
+		goto failed;
+
+	channel_watch = g_io_add_watch(io, G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+					dun_gw_disconnect_cb, emulator);
+
+	return;
+
+failed:
+	g_io_channel_shutdown(io, TRUE, NULL);
+	server = NULL;
+}
+
+static int dun_gw_probe(struct ofono_emulator *emulator)
+{
+	if (server)
+		return -EEXIST;
+
+	DBG("");
+
+	server = bluetooth_register_server(DUN_GW, "Dial-Up Networking",
+				DUN_GW_CHANNEL, dun_gw_connect_cb, emulator);
+
+	return 0;
+}
+
+static void dun_gw_remove(void)
+{
+	if (server == NULL)
+		return;
+
+	DBG("");
+
+	bluetooth_unregister_server(server);
+	server = NULL;
+}
+
+static void gprs_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	struct ofono_modem *modem = data;
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED)
+		return;
+
+	__ofono_emulator_probe_drivers(modem);
+}
+
+static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
+{
+	DBG("modem: %p, added: %d", modem, added);
+
+	if (added == FALSE)
+		return;
+
+	__ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_GPRS,
+					gprs_watch, modem, NULL);
+}
+
+static void call_modemwatch(struct ofono_modem *modem, void *user)
+{
+	modem_watch(modem, TRUE, user);
+}
+
+static struct ofono_emulator_driver emulator_driver = {
+	.name = "Dial-Up Networking",
+	.type = OFONO_ATOM_TYPE_EMULATOR_DUN,
+	.probe = dun_gw_probe,
+	.remove = dun_gw_remove,
+};
+
+static int dun_gw_init(void)
+{
+	modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
+	__ofono_modem_foreach(call_modemwatch, NULL);
+
+	return ofono_emulator_driver_register(&emulator_driver);
+}
+
+static void dun_gw_exit(void)
+{
+	__ofono_modemwatch_remove(modemwatch_id);
+
+	ofono_emulator_driver_unregister(&emulator_driver);
+}
+
+OFONO_PLUGIN_DEFINE(dun_gw, "Dial-up Networking Profile Plugins", VERSION,
+			OFONO_PLUGIN_PRIORITY_DEFAULT, dun_gw_init, dun_gw_exit)
-- 
1.7.4.rc3


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

* [PATCH 7/8] emulator: Implement dialing up for DUN
  2011-01-31 20:52         ` [PATCH 6/8] dun_gw: Add DUN server plugin for oFono Gustavo F. Padovan
@ 2011-01-31 20:52           ` Gustavo F. Padovan
  2011-01-31 20:52             ` [PATCH 8/8] gsmdial: add option for Bluetooth DUN dialing Gustavo F. Padovan
  0 siblings, 1 reply; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-01-31 20:52 UTC (permalink / raw)
  To: ofono

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

It handles client ATD*99# request and then initiate the PPP negotiation.
IP forward through the new ppp interface is not done yet.

Initially based on patches from Zhenhua Zhang <zhenhua.zhang@intel.com>
---
 src/emulator.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index aa71e21..12e801d 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -32,11 +32,18 @@
 #include "ofono.h"
 #include "common.h"
 #include "gatserver.h"
+#include "gatppp.h"
+
+#define DUN_SERVER_ADDRESS	"192.168.1.1"
+#define DUN_PEER_ADDRESS	"192.168.1.2"
+#define DUN_DNS_SERVER_1	"10.10.10.10"
+#define DUN_DNS_SERVER_2	"10.10.10.11"
 
 struct ofono_emulator {
 	struct ofono_modem *modem;
 	struct ofono_atom *atom;
 	GAtServer *server;
+	GAtPPP *ppp;
 	struct ofono_emulator_driver *driver;
 };
 
@@ -167,6 +174,12 @@ void ofono_emulator_disable(struct ofono_emulator *e)
 {
 	DBG("");
 
+	if (e->ppp) {
+		g_at_ppp_shutdown(e->ppp);
+		g_at_ppp_unref(e->ppp);
+		e->ppp = NULL;
+	}
+
 	g_at_server_shutdown(e->server);
 	g_at_server_unref(e->server);
 	e->server = NULL;
@@ -201,6 +214,8 @@ int ofono_emulator_enable(struct ofono_emulator *e, int fd)
 	g_at_server_set_disconnect_function(e->server,
 						emulator_disconnect_cb, e);
 
+	g_at_server_register(e->server, "D", dial_cb, e, NULL);
+
 	return 0;
 }
 
-- 
1.7.4.rc3


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

* [PATCH 8/8] gsmdial: add option for Bluetooth DUN dialing
  2011-01-31 20:52           ` [PATCH 7/8] emulator: Implement dialing up for DUN Gustavo F. Padovan
@ 2011-01-31 20:52             ` Gustavo F. Padovan
  0 siblings, 0 replies; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-01-31 20:52 UTC (permalink / raw)
  To: ofono

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

---
 gatchat/gsmdial.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gatchat/gsmdial.c b/gatchat/gsmdial.c
index 1be80e3..d54a26e 100644
--- a/gatchat/gsmdial.c
+++ b/gatchat/gsmdial.c
@@ -56,6 +56,7 @@ static gboolean option_legacy = FALSE;
 static gchar *option_username = NULL;
 static gchar *option_password = NULL;
 static gchar *option_pppdump = NULL;
+static gboolean option_bluetooth = 0;
 
 static GAtPPP *ppp;
 static GAtChat *control;
@@ -266,6 +267,9 @@ static void no_carrier_notify(GAtResult *result, gpointer user_data)
 {
 	char buf[64];
 
+	if (option_bluetooth)
+		return;
+
 	sprintf(buf, "AT+CFUN=%u", option_offmode);
 	g_at_chat_send(control, buf, none_prefix, power_down, NULL, NULL);
 }
@@ -612,6 +616,8 @@ static GOptionEntry options[] = {
 				"Specify CFUN offmode" },
 	{ "legacy", 'l', 0, G_OPTION_ARG_NONE, &option_legacy,
 				"Use ATD*99***<cid>#" },
+	{ "bluetooth", 'b', 0, G_OPTION_ARG_NONE, &option_bluetooth,
+				"Use only ATD*99" },
 	{ "username", 'u', 0, G_OPTION_ARG_STRING, &option_username,
 				"Specify PPP username" },
 	{ "password", 'w', 0, G_OPTION_ARG_STRING, &option_password,
@@ -700,9 +706,14 @@ int main(int argc, char **argv)
 
 	event_loop = g_main_loop_new(NULL, FALSE);
 
-	g_at_chat_send(control, "ATE0Q0V1", NULL, NULL, NULL, NULL);
-	g_at_chat_send(control, "AT+CFUN?", cfun_prefix,
-						check_mode, NULL, NULL);
+	if (option_bluetooth) {
+		g_at_chat_send(control, "ATD*99", none_prefix, connect_cb,
+				NULL, NULL);
+	} else {
+		g_at_chat_send(control, "ATE0Q0V1", NULL, NULL, NULL, NULL);
+		g_at_chat_send(control, "AT+CFUN?", cfun_prefix,
+							check_mode, NULL, NULL);
+	}
 
 	g_main_loop_run(event_loop);
 	g_source_remove(signal_source);
-- 
1.7.4.rc3


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

* Re: [PATCH 1/8] bluetooth: add server support
  2011-01-31 20:51 [PATCH 1/8] bluetooth: add server support Gustavo F. Padovan
  2011-01-31 20:51 ` [PATCH 2/8] bluetooth: add support to register Bluetooth Service Gustavo F. Padovan
@ 2011-02-01 14:17 ` Frederic Danis
  2011-02-02 18:21   ` Gustavo F. Padovan
  1 sibling, 1 reply; 13+ messages in thread
From: Frederic Danis @ 2011-02-01 14:17 UTC (permalink / raw)
  To: ofono

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

Hello Gustavo,

Le 31/01/2011 21:51, Gustavo F. Padovan a écrit :
> Initial code to have support to listen over a RFCOMM socket for incoming
> connections.
> ---
>   Makefile.am         |    1 +
>   plugins/bluetooth.c |  165 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   plugins/bluetooth.h |   11 ++++
>   3 files changed, 177 insertions(+), 0 deletions(-)
>
> diff --git a/Makefile.am b/Makefile.am
> index a38fcb9..77b1453 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -321,6 +321,7 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
>   builtin_modules += hfp
>   builtin_sources += plugins/hfp.c plugins/bluetooth.h
>
> +builtin_sources += $(btio_sources)
>   builtin_cflags += @BLUEZ_CFLAGS@
>   builtin_libadd += @BLUEZ_LIBS@
>   endif
> diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
> index 93dd7a1..dcf75e6 100644
> --- a/plugins/bluetooth.c
> +++ b/plugins/bluetooth.c
> @@ -35,13 +35,58 @@
>
>   #include<ofono/dbus.h>
>
> +#include<btio.h>
>   #include "bluetooth.h"
>
>   static DBusConnection *connection;
>   static GHashTable *uuid_hash = NULL;
>   static GHashTable *adapter_address_hash = NULL;
> +static GSList *server_list = NULL;
>   static gint bluetooth_refcount;
>
> +struct server {
> +	guint16		service;
> +	gchar		*name;
> +	guint8		channel;
> +	GIOChannel	*io;
> +	char		*adapter;
> +	guint		handle;
> +	ConnectFunc	connect_cb;
> +	gpointer	user_data;
> +};
> +
> +typedef struct {
> +	guint8 b[6];
> +} __attribute__((packed)) bdaddr_t;
> +
> +static void baswap(bdaddr_t *dst, const bdaddr_t *src)
> +{
> +	register unsigned char *d = (unsigned char *) dst;
> +	register const unsigned char *s = (const unsigned char *) src;
> +	register int i;
> +
> +	for (i = 0; i<  6; i++)
> +		d[i] = s[5-i];
> +}
> +
> +static int str2ba(const char *str, bdaddr_t *ba)
> +{
> +	guint8 b[6];
> +	const char *ptr = str;
> +	int i;
> +
> +	for (i = 0; i<  6; i++) {
> +		b[i] = (guint8) strtol(ptr, NULL, 16);
> +		if (i != 5&&  !(ptr = strchr(ptr, ':')))
> +			ptr = ":00:00:00:00:00";
> +		ptr++;
> +	}
> +
> +	baswap(ba, (bdaddr_t *) b);
> +
> +	return 0;
> +}
> +
>   void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
>   				char *buf, int size)
>   {
> @@ -371,6 +416,70 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
>   	return TRUE;
>   }
>
> +static void server_stop(gpointer data)
> +{
> +	struct server *server = data;
> +
> +	if (server->handle>  0) {
> +		DBusMessage *msg;
> +
> +		msg = dbus_message_new_method_call(BLUEZ_SERVICE,
> +						server->adapter,
> +						BLUEZ_SERVICE_INTERFACE,
> +						"RemoveRecord");
> +		dbus_message_append_args(msg, DBUS_TYPE_UINT32,&server->handle,
> +						DBUS_TYPE_INVALID);
> +		g_dbus_send_message(connection, msg);
> +
> +		server->handle = 0;
> +	}
> +
> +	if (server->io != NULL) {
> +		g_io_channel_shutdown(server->io, TRUE, NULL);
> +		g_io_channel_unref(server->io);
> +		server->io = NULL;
> +	}
> +
> +	g_free(server->adapter);
> +	server->adapter = NULL;
> +}
> +
> +static void new_connection(GIOChannel *io, gpointer user_data)
> +{
> +	struct server *server = user_data;
> +
> +	DBG("%p", server);
> +}
> +
> +static void server_start(gpointer data, gpointer user_data)
> +{
> +	struct server *server = data;
> +	char *addr, *path = user_data;
> +	bdaddr_t baddr;
> +	GError *err = NULL;
> +
> +	if (server->handle != 0)
> +		return;
> +
> +	addr = g_hash_table_lookup(adapter_address_hash, path);
> +	str2ba(addr,&baddr);
> +	server->io = bt_io_listen(BT_IO_RFCOMM, NULL, new_connection,
> +					server, NULL,&err,
> +					BT_IO_OPT_SOURCE_BDADDR,&baddr,
> +					BT_IO_OPT_CHANNEL, server->channel,
> +					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
> +					BT_IO_OPT_INVALID);
> +	if (server->io == NULL) {
> +		ofono_error("Bluetooth %s register failed: %s",
> +					server->name, err->message);
> +		g_error_free(err);
> +		server_stop(server);
> +		return;
> +	}
> +
> +	server->adapter = g_strdup(path);
> +}
> +
This will not allows to start server on multiple adapters, as the test 
of the SDP Record handle will prevent to bt_io_listen on other adapters.

I do not understand why you pass the adapter address, if it is omitted 
the bt_io_listen will be done for all adapters.

>   static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data)
>   {
>   	const char *path = user_data;
> @@ -395,6 +504,9 @@ static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data)
>   	g_hash_table_insert(adapter_address_hash,
>   				g_strdup(path), g_strdup(addr));
>
> +	if (server_list)
> +		g_slist_foreach(server_list, server_start, (gpointer)path);
> +
>   	for (l = device_list; l; l = l->next) {
>   		const char *device = l->data;
>
> @@ -429,11 +541,26 @@ static gboolean adapter_removed(DBusConnection *connection,
>   				DBusMessage *message, void *user_data)
>   {
>   	const char *path;
> +	GSList *l;
>
>   	if (dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH,&path,
>   				DBUS_TYPE_INVALID) == TRUE)
>   		g_hash_table_remove(adapter_address_hash, path);
>
> +	for (l = server_list; l; l = l->next) {
> +		struct server *server = l->data;
> +
> +		if (!server->adapter)
> +			continue;
> +
> +		if (!g_str_equal(path, server->adapter))
> +			continue;
> +
> +		/* Don't remove handle if the adapter has been removed */
> +		server->handle = 0;
> +		server_stop(server);
> +	}
> +
>   	return TRUE;
>   }
>
> @@ -590,5 +717,43 @@ void bluetooth_unregister_uuid(const char *uuid)
>   	bluetooth_unref();
>   }
>
> +struct server *bluetooth_register_server(guint16 service, char *name,
> +						guint8 channel, ConnectFunc cb,
> +						gpointer user_data)
> +{
> +	struct server *server;
> +
> +	server = g_try_new0(struct server, 1);
> +	if (!server)
> +		return NULL;
> +
> +	bluetooth_ref();
> +
> +	server->service = service;
> +	server->name = g_strdup(name);
> +	server->channel = channel;
> +	server->connect_cb = cb;
> +	server->user_data = user_data;
> +
> +	server_list = g_slist_prepend(server_list, server);
> +
> +	bluetooth_send_with_reply("/", BLUEZ_MANAGER_INTERFACE, "GetProperties",
> +					manager_properties_cb, NULL, NULL, -1,
> +					DBUS_TYPE_INVALID);
> +
> +	return server;
> +}
> +
> +void bluetooth_unregister_server(struct server *server)
> +{
> +	server_list = g_slist_remove(server_list, server);
> +
> +	server_stop(server);
> +	g_free(server->name);
> +	g_free(server);
> +
> +	bluetooth_unref();
> +}
> +
>   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 42b0d13..f6fc6a6 100644
> --- a/plugins/bluetooth.h
> +++ b/plugins/bluetooth.h
> @@ -23,6 +23,7 @@
>   #define	BLUEZ_MANAGER_INTERFACE		BLUEZ_SERVICE ".Manager"
>   #define	BLUEZ_ADAPTER_INTERFACE		BLUEZ_SERVICE ".Adapter"
>   #define	BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device"
> +#define	BLUEZ_SERVICE_INTERFACE		BLUEZ_SERVICE ".Service"
>
>   #define DBUS_TIMEOUT 15
>
> @@ -39,10 +40,20 @@ struct bluetooth_profile {
>   	void (*set_alias)(const char *device, const char *);
>   };
>
> +
> +typedef void (*ConnectFunc)(GIOChannel *io, GError *err, gpointer user_data);
> +
> +struct server;
> +
>   int bluetooth_register_uuid(const char *uuid,
>   				struct bluetooth_profile *profile);
>   void bluetooth_unregister_uuid(const char *uuid);
>
> +struct server *bluetooth_register_server(guint16 service, char *name,
> +						guint8 channel, ConnectFunc cb,
> +						gpointer user_data);
> +void bluetooth_unregister_server(struct server *server);
> +
>   void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
>   							char *buf, int size);
>


-- 
Frederic Danis                            Open Source Technology Centre
frederic.danis(a)intel.com                              Intel Corporation


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

* Re: [PATCH 2/8] bluetooth: add support to register Bluetooth Service
  2011-01-31 20:51 ` [PATCH 2/8] bluetooth: add support to register Bluetooth Service Gustavo F. Padovan
  2011-01-31 20:51   ` [PATCH 3/8] bluetooth: add Request auth code for new connections Gustavo F. Padovan
@ 2011-02-01 14:25   ` Frederic Danis
  1 sibling, 0 replies; 13+ messages in thread
From: Frederic Danis @ 2011-02-01 14:25 UTC (permalink / raw)
  To: ofono

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

Hello Gustavo,

Le 31/01/2011 21:51, Gustavo F. Padovan a écrit :
> ---
>   plugins/bluetooth.c |   75 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 files changed, 75 insertions(+), 0 deletions(-)
>
> diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
> index dcf75e6..0b5a021 100644
> --- a/plugins/bluetooth.c
> +++ b/plugins/bluetooth.c
> @@ -44,6 +44,43 @@ static GHashTable *adapter_address_hash = NULL;
>   static GSList *server_list = NULL;
>   static gint bluetooth_refcount;
>
> +static const gchar *dun_record = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>	\
> +<record>									\
> +<attribute id=\"0x0001\">							\
> +<sequence>									\
> +<uuid value=\"0x1103\"/>							\
> +</sequence>									\
> +</attribute>									\
> +										\
> +<attribute id=\"0x0004\">							\
> +<sequence>									\
> +<sequence>								\
> +<uuid value=\"0x0100\"/>						\
> +</sequence>								\
> +<sequence>								\
> +<uuid value=\"0x0003\"/>						\
> +<uint8 value=\"%u\" name=\"channel\"/>					\
> +</sequence>								\
> +<sequence>								\
> +<uuid value=\"0x0008\"/>						\
> +</sequence>								\
> +</sequence>									\
> +</attribute>									\
> +										\
> +<attribute id=\"0x0009\">							\
> +<sequence>									\
> +<sequence>								\
> +<uuid value=\"0x1103\"/>						\
> +<uint16 value=\"0x0100\" name=\"version\"/>				\
> +</sequence>								\
> +</sequence>									\
> +</attribute>									\
> +										\
> +<attribute id=\"0x0100\">							\
> +<text value=\"%s\" name=\"name\"/>						\
> +</attribute>									\
> +</record>";
> +
Why do you set the SDP record in the generic bluetooth code ?
I think this should be moved to dun_gw code.

>   struct server {
>   	guint16		service;
>   	gchar		*name;
> @@ -451,12 +488,40 @@ static void new_connection(GIOChannel *io, gpointer user_data)
>   	DBG("%p", server);
>   }
>
> +static void add_record_cb(DBusPendingCall *call, gpointer user_data)
> +{
> +	struct server *server = user_data;
> +	DBusMessage *reply = dbus_pending_call_steal_reply(call);
> +	DBusError derr;
> +	guint32 handle;
> +
> +	dbus_error_init(&derr);
> +
> +	if (dbus_set_error_from_message(&derr, reply)) {
> +		ofono_error("Replied with an error: %s, %s",
> +					derr.name, derr.message);
> +		dbus_error_free(&derr);
> +		server_stop(server);
> +		goto done;
> +	}
> +
> +	dbus_message_get_args(reply, NULL, DBUS_TYPE_UINT32,&handle,
> +					DBUS_TYPE_INVALID);
> +	server->handle = handle;
> +
> +	ofono_info("Registered: %s, handle: 0x%x", server->name, handle);
> +
> +done:
> +	dbus_message_unref(reply);
> +}
> +
>   static void server_start(gpointer data, gpointer user_data)
>   {
>   	struct server *server = data;
>   	char *addr, *path = user_data;
>   	bdaddr_t baddr;
>   	GError *err = NULL;
> +	gchar *xml;
>
>   	if (server->handle != 0)
>   		return;
> @@ -478,6 +543,16 @@ static void server_start(gpointer data, gpointer user_data)
>   	}
>
>   	server->adapter = g_strdup(path);
> +
> +	xml = g_markup_printf_escaped(dun_record, server->channel,
> +					server->name);
> +
> +	bluetooth_send_with_reply(path, BLUEZ_SERVICE_INTERFACE, "AddRecord",
> +					add_record_cb, server, NULL, -1,
> +					DBUS_TYPE_STRING,&xml,
> +					DBUS_TYPE_INVALID);
> +
> +	g_free(xml);
>   }
>
>   static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data)


-- 
Frederic Danis                            Open Source Technology Centre
frederic.danis(a)intel.com                              Intel Corporation


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

* Re: [PATCH 1/8] bluetooth: add server support
  2011-02-01 14:17 ` [PATCH 1/8] bluetooth: add server support Frederic Danis
@ 2011-02-02 18:21   ` Gustavo F. Padovan
  2011-02-03 15:56     ` Frederic Danis
  0 siblings, 1 reply; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-02-02 18:21 UTC (permalink / raw)
  To: ofono

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

Hi Frederic,

* Frederic Danis <frederic.danis@linux.intel.com> [2011-02-01 15:17:56 +0100]:

> Hello Gustavo,
> 
> Le 31/01/2011 21:51, Gustavo F. Padovan a écrit :
> > Initial code to have support to listen over a RFCOMM socket for incoming
> > connections.
> > ---
> >   Makefile.am         |    1 +
> >   plugins/bluetooth.c |  165 +++++++++++++++++++++++++++++++++++++++++++++++++++
> >   plugins/bluetooth.h |   11 ++++
> >   3 files changed, 177 insertions(+), 0 deletions(-)
> >
> > diff --git a/Makefile.am b/Makefile.am
> > index a38fcb9..77b1453 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -321,6 +321,7 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
> >   builtin_modules += hfp
> >   builtin_sources += plugins/hfp.c plugins/bluetooth.h
> >
> > +builtin_sources += $(btio_sources)
> >   builtin_cflags += @BLUEZ_CFLAGS@
> >   builtin_libadd += @BLUEZ_LIBS@
> >   endif
> > diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
> > index 93dd7a1..dcf75e6 100644
> > --- a/plugins/bluetooth.c
> > +++ b/plugins/bluetooth.c
> > @@ -35,13 +35,58 @@
> >
> >   #include<ofono/dbus.h>
> >
> > +#include<btio.h>
> >   #include "bluetooth.h"
> >
> >   static DBusConnection *connection;
> >   static GHashTable *uuid_hash = NULL;
> >   static GHashTable *adapter_address_hash = NULL;
> > +static GSList *server_list = NULL;
> >   static gint bluetooth_refcount;
> >
> > +struct server {
> > +	guint16		service;
> > +	gchar		*name;
> > +	guint8		channel;
> > +	GIOChannel	*io;
> > +	char		*adapter;
> > +	guint		handle;
> > +	ConnectFunc	connect_cb;
> > +	gpointer	user_data;
> > +};
> > +
> > +typedef struct {
> > +	guint8 b[6];
> > +} __attribute__((packed)) bdaddr_t;
> > +
> > +static void baswap(bdaddr_t *dst, const bdaddr_t *src)
> > +{
> > +	register unsigned char *d = (unsigned char *) dst;
> > +	register const unsigned char *s = (const unsigned char *) src;
> > +	register int i;
> > +
> > +	for (i = 0; i<  6; i++)
> > +		d[i] = s[5-i];
> > +}
> > +
> > +static int str2ba(const char *str, bdaddr_t *ba)
> > +{
> > +	guint8 b[6];
> > +	const char *ptr = str;
> > +	int i;
> > +
> > +	for (i = 0; i<  6; i++) {
> > +		b[i] = (guint8) strtol(ptr, NULL, 16);
> > +		if (i != 5&&  !(ptr = strchr(ptr, ':')))
> > +			ptr = ":00:00:00:00:00";
> > +		ptr++;
> > +	}
> > +
> > +	baswap(ba, (bdaddr_t *) b);
> > +
> > +	return 0;
> > +}
> > +
> >   void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
> >   				char *buf, int size)
> >   {
> > @@ -371,6 +416,70 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
> >   	return TRUE;
> >   }
> >
> > +static void server_stop(gpointer data)
> > +{
> > +	struct server *server = data;
> > +
> > +	if (server->handle>  0) {
> > +		DBusMessage *msg;
> > +
> > +		msg = dbus_message_new_method_call(BLUEZ_SERVICE,
> > +						server->adapter,
> > +						BLUEZ_SERVICE_INTERFACE,
> > +						"RemoveRecord");
> > +		dbus_message_append_args(msg, DBUS_TYPE_UINT32,&server->handle,
> > +						DBUS_TYPE_INVALID);
> > +		g_dbus_send_message(connection, msg);
> > +
> > +		server->handle = 0;
> > +	}
> > +
> > +	if (server->io != NULL) {
> > +		g_io_channel_shutdown(server->io, TRUE, NULL);
> > +		g_io_channel_unref(server->io);
> > +		server->io = NULL;
> > +	}
> > +
> > +	g_free(server->adapter);
> > +	server->adapter = NULL;
> > +}
> > +
> > +static void new_connection(GIOChannel *io, gpointer user_data)
> > +{
> > +	struct server *server = user_data;
> > +
> > +	DBG("%p", server);
> > +}
> > +
> > +static void server_start(gpointer data, gpointer user_data)
> > +{
> > +	struct server *server = data;
> > +	char *addr, *path = user_data;
> > +	bdaddr_t baddr;
> > +	GError *err = NULL;
> > +
> > +	if (server->handle != 0)
> > +		return;
> > +
> > +	addr = g_hash_table_lookup(adapter_address_hash, path);
> > +	str2ba(addr,&baddr);
> > +	server->io = bt_io_listen(BT_IO_RFCOMM, NULL, new_connection,
> > +					server, NULL,&err,
> > +					BT_IO_OPT_SOURCE_BDADDR,&baddr,
> > +					BT_IO_OPT_CHANNEL, server->channel,
> > +					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
> > +					BT_IO_OPT_INVALID);
> > +	if (server->io == NULL) {
> > +		ofono_error("Bluetooth %s register failed: %s",
> > +					server->name, err->message);
> > +		g_error_free(err);
> > +		server_stop(server);
> > +		return;
> > +	}
> > +
> > +	server->adapter = g_strdup(path);
> > +}
> > +
> This will not allows to start server on multiple adapters, as the test 
> of the SDP Record handle will prevent to bt_io_listen on other adapters.

Yes, it will. The SDP record is per adapter, so I call bt_io_listen on that
adapter and and add the SDP record to the adapter records. The code does that
for all adapters.

> 
> I do not understand why you pass the adapter address, if it is omitted 
> the bt_io_listen will be done for all adapters.

See above.

-- 
Gustavo F. Padovan
http://profusion.mobi

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

* Re: [PATCH 1/8] bluetooth: add server support
  2011-02-02 18:21   ` Gustavo F. Padovan
@ 2011-02-03 15:56     ` Frederic Danis
  2011-02-03 16:30       ` Gustavo F. Padovan
  0 siblings, 1 reply; 13+ messages in thread
From: Frederic Danis @ 2011-02-03 15:56 UTC (permalink / raw)
  To: ofono

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

Hello Gustavo,

Le 02/02/2011 19:21, Gustavo F. Padovan a écrit :
> Hi Frederic,
>
> * Frederic Danis<frederic.danis@linux.intel.com>  [2011-02-01 15:17:56 +0100]:
>
>> Hello Gustavo,
>>
>> Le 31/01/2011 21:51, Gustavo F. Padovan a écrit :
>>> Initial code to have support to listen over a RFCOMM socket for incoming
>>> connections.
>>> ---
>>>    Makefile.am         |    1 +
>>>    plugins/bluetooth.c |  165 +++++++++++++++++++++++++++++++++++++++++++++++++++
>>>    plugins/bluetooth.h |   11 ++++
>>>    3 files changed, 177 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/Makefile.am b/Makefile.am
>>> index a38fcb9..77b1453 100644
>>> --- a/Makefile.am
>>> +++ b/Makefile.am
>>> @@ -321,6 +321,7 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
>>>    builtin_modules += hfp
>>>    builtin_sources += plugins/hfp.c plugins/bluetooth.h
>>>
>>> +builtin_sources += $(btio_sources)
>>>    builtin_cflags += @BLUEZ_CFLAGS@
>>>    builtin_libadd += @BLUEZ_LIBS@
>>>    endif
>>> diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
>>> index 93dd7a1..dcf75e6 100644
>>> --- a/plugins/bluetooth.c
>>> +++ b/plugins/bluetooth.c
>>> @@ -35,13 +35,58 @@
>>>
>>>    #include<ofono/dbus.h>
>>>
>>> +#include<btio.h>
>>>    #include "bluetooth.h"
>>>
>>>    static DBusConnection *connection;
>>>    static GHashTable *uuid_hash = NULL;
>>>    static GHashTable *adapter_address_hash = NULL;
>>> +static GSList *server_list = NULL;
>>>    static gint bluetooth_refcount;
>>>
>>> +struct server {
>>> +	guint16		service;
>>> +	gchar		*name;
>>> +	guint8		channel;
>>> +	GIOChannel	*io;
>>> +	char		*adapter;
>>> +	guint		handle;
>>> +	ConnectFunc	connect_cb;
>>> +	gpointer	user_data;
>>> +};
>>> +
>>> +typedef struct {
>>> +	guint8 b[6];
>>> +} __attribute__((packed)) bdaddr_t;
>>> +
>>> +static void baswap(bdaddr_t *dst, const bdaddr_t *src)
>>> +{
>>> +	register unsigned char *d = (unsigned char *) dst;
>>> +	register const unsigned char *s = (const unsigned char *) src;
>>> +	register int i;
>>> +
>>> +	for (i = 0; i<   6; i++)
>>> +		d[i] = s[5-i];
>>> +}
>>> +
>>> +static int str2ba(const char *str, bdaddr_t *ba)
>>> +{
>>> +	guint8 b[6];
>>> +	const char *ptr = str;
>>> +	int i;
>>> +
>>> +	for (i = 0; i<   6; i++) {
>>> +		b[i] = (guint8) strtol(ptr, NULL, 16);
>>> +		if (i != 5&&   !(ptr = strchr(ptr, ':')))
>>> +			ptr = ":00:00:00:00:00";
>>> +		ptr++;
>>> +	}
>>> +
>>> +	baswap(ba, (bdaddr_t *) b);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>>    void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
>>>    				char *buf, int size)
>>>    {
>>> @@ -371,6 +416,70 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
>>>    	return TRUE;
>>>    }
>>>
>>> +static void server_stop(gpointer data)
>>> +{
>>> +	struct server *server = data;
>>> +
>>> +	if (server->handle>   0) {
>>> +		DBusMessage *msg;
>>> +
>>> +		msg = dbus_message_new_method_call(BLUEZ_SERVICE,
>>> +						server->adapter,
>>> +						BLUEZ_SERVICE_INTERFACE,
>>> +						"RemoveRecord");
>>> +		dbus_message_append_args(msg, DBUS_TYPE_UINT32,&server->handle,
>>> +						DBUS_TYPE_INVALID);
>>> +		g_dbus_send_message(connection, msg);
>>> +
>>> +		server->handle = 0;
>>> +	}
>>> +
>>> +	if (server->io != NULL) {
>>> +		g_io_channel_shutdown(server->io, TRUE, NULL);
>>> +		g_io_channel_unref(server->io);
>>> +		server->io = NULL;
>>> +	}
>>> +
>>> +	g_free(server->adapter);
>>> +	server->adapter = NULL;
>>> +}
>>> +
>>> +static void new_connection(GIOChannel *io, gpointer user_data)
>>> +{
>>> +	struct server *server = user_data;
>>> +
>>> +	DBG("%p", server);
>>> +}
>>> +
>>> +static void server_start(gpointer data, gpointer user_data)
>>> +{
>>> +	struct server *server = data;
>>> +	char *addr, *path = user_data;
>>> +	bdaddr_t baddr;
>>> +	GError *err = NULL;
>>> +
>>> +	if (server->handle != 0)
>>> +		return;
>>> +
>>> +	addr = g_hash_table_lookup(adapter_address_hash, path);
>>> +	str2ba(addr,&baddr);
>>> +	server->io = bt_io_listen(BT_IO_RFCOMM, NULL, new_connection,
>>> +					server, NULL,&err,
>>> +					BT_IO_OPT_SOURCE_BDADDR,&baddr,
>>> +					BT_IO_OPT_CHANNEL, server->channel,
>>> +					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
>>> +					BT_IO_OPT_INVALID);
>>> +	if (server->io == NULL) {
>>> +		ofono_error("Bluetooth %s register failed: %s",
>>> +					server->name, err->message);
>>> +		g_error_free(err);
>>> +		server_stop(server);
>>> +		return;
>>> +	}
>>> +
>>> +	server->adapter = g_strdup(path);
>>> +}
>>> +
>> This will not allows to start server on multiple adapters, as the test
>> of the SDP Record handle will prevent to bt_io_listen on other adapters.
>
> Yes, it will. The SDP record is per adapter, so I call bt_io_listen on that
> adapter and and add the SDP record to the adapter records. The code does that
> for all adapters.
>
>>
>> I do not understand why you pass the adapter address, if it is omitted
>> the bt_io_listen will be done for all adapters.
>
> See above.
>

Without the second patch (which add the SDP record), I agree with you 
that bt_io_listen will be called for each adapter path.
But, you will lost reference to the io channel and to the path adapter 
(resulting in memory leak).

With the second patch, this will only work if adapters are present 
during ofono launch. But, if the adapter is added later, after the sdp 
record has been added for the first adapters, bt_io_listen will not be 
called as server->handle is non-null.

One other thing, I do not understand why you use BT_IO_OPT_SOURCE_BDADDR 
instead of BT_IO_OPT_SOURCE (this one accept Bluetooth address as string).

Regards

Fred

-- 
Frederic Danis                            Open Source Technology Centre
frederic.danis(a)intel.com                              Intel Corporation


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

* Re: [PATCH 1/8] bluetooth: add server support
  2011-02-03 15:56     ` Frederic Danis
@ 2011-02-03 16:30       ` Gustavo F. Padovan
  0 siblings, 0 replies; 13+ messages in thread
From: Gustavo F. Padovan @ 2011-02-03 16:30 UTC (permalink / raw)
  To: ofono

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

Hi Frederic,

* Frederic Danis <frederic.danis@linux.intel.com> [2011-02-03 16:56:14 +0100]:

> Hello Gustavo,
> 
> Le 02/02/2011 19:21, Gustavo F. Padovan a écrit :
> > Hi Frederic,
> >
> > * Frederic Danis<frederic.danis@linux.intel.com>  [2011-02-01 15:17:56 +0100]:
> >
> >> Hello Gustavo,
> >>
> >> Le 31/01/2011 21:51, Gustavo F. Padovan a écrit :
> >>> Initial code to have support to listen over a RFCOMM socket for incoming
> >>> connections.
> >>> ---
> >>>    Makefile.am         |    1 +
> >>>    plugins/bluetooth.c |  165 +++++++++++++++++++++++++++++++++++++++++++++++++++
> >>>    plugins/bluetooth.h |   11 ++++
> >>>    3 files changed, 177 insertions(+), 0 deletions(-)
> >>>
> >>> diff --git a/Makefile.am b/Makefile.am
> >>> index a38fcb9..77b1453 100644
> >>> --- a/Makefile.am
> >>> +++ b/Makefile.am
> >>> @@ -321,6 +321,7 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
> >>>    builtin_modules += hfp
> >>>    builtin_sources += plugins/hfp.c plugins/bluetooth.h
> >>>
> >>> +builtin_sources += $(btio_sources)
> >>>    builtin_cflags += @BLUEZ_CFLAGS@
> >>>    builtin_libadd += @BLUEZ_LIBS@
> >>>    endif
> >>> diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
> >>> index 93dd7a1..dcf75e6 100644
> >>> --- a/plugins/bluetooth.c
> >>> +++ b/plugins/bluetooth.c
> >>> @@ -35,13 +35,58 @@
> >>>
> >>>    #include<ofono/dbus.h>
> >>>
> >>> +#include<btio.h>
> >>>    #include "bluetooth.h"
> >>>
> >>>    static DBusConnection *connection;
> >>>    static GHashTable *uuid_hash = NULL;
> >>>    static GHashTable *adapter_address_hash = NULL;
> >>> +static GSList *server_list = NULL;
> >>>    static gint bluetooth_refcount;
> >>>
> >>> +struct server {
> >>> +	guint16		service;
> >>> +	gchar		*name;
> >>> +	guint8		channel;
> >>> +	GIOChannel	*io;
> >>> +	char		*adapter;
> >>> +	guint		handle;
> >>> +	ConnectFunc	connect_cb;
> >>> +	gpointer	user_data;
> >>> +};
> >>> +
> >>> +typedef struct {
> >>> +	guint8 b[6];
> >>> +} __attribute__((packed)) bdaddr_t;
> >>> +
> >>> +static void baswap(bdaddr_t *dst, const bdaddr_t *src)
> >>> +{
> >>> +	register unsigned char *d = (unsigned char *) dst;
> >>> +	register const unsigned char *s = (const unsigned char *) src;
> >>> +	register int i;
> >>> +
> >>> +	for (i = 0; i<   6; i++)
> >>> +		d[i] = s[5-i];
> >>> +}
> >>> +
> >>> +static int str2ba(const char *str, bdaddr_t *ba)
> >>> +{
> >>> +	guint8 b[6];
> >>> +	const char *ptr = str;
> >>> +	int i;
> >>> +
> >>> +	for (i = 0; i<   6; i++) {
> >>> +		b[i] = (guint8) strtol(ptr, NULL, 16);
> >>> +		if (i != 5&&   !(ptr = strchr(ptr, ':')))
> >>> +			ptr = ":00:00:00:00:00";
> >>> +		ptr++;
> >>> +	}
> >>> +
> >>> +	baswap(ba, (bdaddr_t *) b);
> >>> +
> >>> +	return 0;
> >>> +}
> >>> +
> >>>    void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
> >>>    				char *buf, int size)
> >>>    {
> >>> @@ -371,6 +416,70 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
> >>>    	return TRUE;
> >>>    }
> >>>
> >>> +static void server_stop(gpointer data)
> >>> +{
> >>> +	struct server *server = data;
> >>> +
> >>> +	if (server->handle>   0) {
> >>> +		DBusMessage *msg;
> >>> +
> >>> +		msg = dbus_message_new_method_call(BLUEZ_SERVICE,
> >>> +						server->adapter,
> >>> +						BLUEZ_SERVICE_INTERFACE,
> >>> +						"RemoveRecord");
> >>> +		dbus_message_append_args(msg, DBUS_TYPE_UINT32,&server->handle,
> >>> +						DBUS_TYPE_INVALID);
> >>> +		g_dbus_send_message(connection, msg);
> >>> +
> >>> +		server->handle = 0;
> >>> +	}
> >>> +
> >>> +	if (server->io != NULL) {
> >>> +		g_io_channel_shutdown(server->io, TRUE, NULL);
> >>> +		g_io_channel_unref(server->io);
> >>> +		server->io = NULL;
> >>> +	}
> >>> +
> >>> +	g_free(server->adapter);
> >>> +	server->adapter = NULL;
> >>> +}
> >>> +
> >>> +static void new_connection(GIOChannel *io, gpointer user_data)
> >>> +{
> >>> +	struct server *server = user_data;
> >>> +
> >>> +	DBG("%p", server);
> >>> +}
> >>> +
> >>> +static void server_start(gpointer data, gpointer user_data)
> >>> +{
> >>> +	struct server *server = data;
> >>> +	char *addr, *path = user_data;
> >>> +	bdaddr_t baddr;
> >>> +	GError *err = NULL;
> >>> +
> >>> +	if (server->handle != 0)
> >>> +		return;
> >>> +
> >>> +	addr = g_hash_table_lookup(adapter_address_hash, path);
> >>> +	str2ba(addr,&baddr);
> >>> +	server->io = bt_io_listen(BT_IO_RFCOMM, NULL, new_connection,
> >>> +					server, NULL,&err,
> >>> +					BT_IO_OPT_SOURCE_BDADDR,&baddr,
> >>> +					BT_IO_OPT_CHANNEL, server->channel,
> >>> +					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
> >>> +					BT_IO_OPT_INVALID);
> >>> +	if (server->io == NULL) {
> >>> +		ofono_error("Bluetooth %s register failed: %s",
> >>> +					server->name, err->message);
> >>> +		g_error_free(err);
> >>> +		server_stop(server);
> >>> +		return;
> >>> +	}
> >>> +
> >>> +	server->adapter = g_strdup(path);
> >>> +}
> >>> +
> >> This will not allows to start server on multiple adapters, as the test
> >> of the SDP Record handle will prevent to bt_io_listen on other adapters.
> >
> > Yes, it will. The SDP record is per adapter, so I call bt_io_listen on that
> > adapter and and add the SDP record to the adapter records. The code does that
> > for all adapters.
> >
> >>
> >> I do not understand why you pass the adapter address, if it is omitted
> >> the bt_io_listen will be done for all adapters.
> >
> > See above.
> >
> 
> Without the second patch (which add the SDP record), I agree with you 
> that bt_io_listen will be called for each adapter path.
> But, you will lost reference to the io channel and to the path adapter 
> (resulting in memory leak).

Then we need a per adapter structure here.

> 
> With the second patch, this will only work if adapters are present 
> during ofono launch. But, if the adapter is added later, after the sdp 
> record has been added for the first adapters, bt_io_listen will not be 
> called as server->handle is non-null.

Another reason for the per adapter structure.

> 
> One other thing, I do not understand why you use BT_IO_OPT_SOURCE_BDADDR 
> instead of BT_IO_OPT_SOURCE (this one accept Bluetooth address as string).

Hum, we need to fix this.

-- 
Gustavo F. Padovan
http://profusion.mobi

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

end of thread, other threads:[~2011-02-03 16:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-31 20:51 [PATCH 1/8] bluetooth: add server support Gustavo F. Padovan
2011-01-31 20:51 ` [PATCH 2/8] bluetooth: add support to register Bluetooth Service Gustavo F. Padovan
2011-01-31 20:51   ` [PATCH 3/8] bluetooth: add Request auth code for new connections Gustavo F. Padovan
2011-01-31 20:51     ` [PATCH 4/8] include: add public headed to emulator atom Gustavo F. Padovan
2011-01-31 20:51       ` [PATCH 5/8] emulator: Add emulator atom in oFono Gustavo F. Padovan
2011-01-31 20:52         ` [PATCH 6/8] dun_gw: Add DUN server plugin for oFono Gustavo F. Padovan
2011-01-31 20:52           ` [PATCH 7/8] emulator: Implement dialing up for DUN Gustavo F. Padovan
2011-01-31 20:52             ` [PATCH 8/8] gsmdial: add option for Bluetooth DUN dialing Gustavo F. Padovan
2011-02-01 14:25   ` [PATCH 2/8] bluetooth: add support to register Bluetooth Service Frederic Danis
2011-02-01 14:17 ` [PATCH 1/8] bluetooth: add server support Frederic Danis
2011-02-02 18:21   ` Gustavo F. Padovan
2011-02-03 15:56     ` Frederic Danis
2011-02-03 16:30       ` Gustavo F. Padovan

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.