linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] transport: add getsockname to transport driver
@ 2013-05-28 17:45 Gustavo Padovan
  2013-05-28 17:45 ` [PATCH 2/6] bluetooth: add getsockname() entry in the bluetooth driver Gustavo Padovan
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Gustavo Padovan @ 2013-05-28 17:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: emilio.pozuelo, Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Enable other pieces of obex to get the source Bluetooth address.
---
 obexd/src/transport.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/obexd/src/transport.h b/obexd/src/transport.h
index b81615b..97e10d0 100644
--- a/obexd/src/transport.h
+++ b/obexd/src/transport.h
@@ -26,6 +26,7 @@ struct obex_transport_driver {
 	uint16_t service;
 	void *(*start) (struct obex_server *server, int *err);
 	int (*getpeername) (GIOChannel *io, char **name);
+	int (*getsockname) (GIOChannel *io, char **name);
 	void (*stop) (void *data);
 };
 
-- 
1.8.1.4


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

* [PATCH 2/6] bluetooth: add getsockname() entry in the bluetooth driver
  2013-05-28 17:45 [PATCH 1/6] transport: add getsockname to transport driver Gustavo Padovan
@ 2013-05-28 17:45 ` Gustavo Padovan
  2013-05-28 17:45 ` [PATCH 3/6] obex: add obex_getsockname() Gustavo Padovan
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Gustavo Padovan @ 2013-05-28 17:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: emilio.pozuelo, Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

---
 obexd/plugins/bluetooth.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/obexd/plugins/bluetooth.c b/obexd/plugins/bluetooth.c
index b9e9c91..07baf90 100644
--- a/obexd/plugins/bluetooth.c
+++ b/obexd/plugins/bluetooth.c
@@ -431,10 +431,29 @@ static int bluetooth_getpeername(GIOChannel *io, char **name)
 	return 0;
 }
 
+static int bluetooth_getsockname(GIOChannel *io, char **name)
+{
+	GError *gerr = NULL;
+	char address[18];
+
+	bt_io_get(io, &gerr, BT_IO_OPT_SOURCE, address, BT_IO_OPT_INVALID);
+
+	if (gerr) {
+		error("%s", gerr->message);
+		g_error_free(gerr);
+		return -EINVAL;
+	}
+
+	*name = g_strdup(address);
+
+	return 0;
+}
+
 static struct obex_transport_driver driver = {
 	.name = "bluetooth",
 	.start = bluetooth_start,
 	.getpeername = bluetooth_getpeername,
+	.getsockname = bluetooth_getsockname,
 	.stop = bluetooth_stop
 };
 
-- 
1.8.1.4


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

* [PATCH 3/6] obex: add obex_getsockname()
  2013-05-28 17:45 [PATCH 1/6] transport: add getsockname to transport driver Gustavo Padovan
  2013-05-28 17:45 ` [PATCH 2/6] bluetooth: add getsockname() entry in the bluetooth driver Gustavo Padovan
@ 2013-05-28 17:45 ` Gustavo Padovan
  2013-05-28 17:45 ` [PATCH 4/6] obex: get src and dst address and store it Gustavo Padovan
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Gustavo Padovan @ 2013-05-28 17:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: emilio.pozuelo, Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Allow obex users to get the source device address.
---
 obexd/src/obex.c | 10 ++++++++++
 obexd/src/obex.h |  1 +
 2 files changed, 11 insertions(+)

diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index a3e7b0e..7a1d612 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
@@ -1226,6 +1226,16 @@ int obex_getpeername(struct obex_session *os, char **name)
 	return transport->getpeername(os->io, name);
 }
 
+int obex_getsockname(struct obex_session *os, char **name)
+{
+	struct obex_transport_driver *transport = os->server->transport;
+
+	if (transport == NULL || transport->getsockname == NULL)
+		return -ENOTSUP;
+
+	return transport->getsockname(os->io, name);
+}
+
 int memncmp0(const void *a, size_t na, const void *b, size_t nb)
 {
 	if (na != nb)
diff --git a/obexd/src/obex.h b/obexd/src/obex.h
index 443a748..fc16747 100644
--- a/obexd/src/obex.h
+++ b/obexd/src/obex.h
@@ -46,6 +46,7 @@ ssize_t obex_get_apparam(struct obex_session *os, const uint8_t **buffer);
 ssize_t obex_get_non_header_data(struct obex_session *os,
 							const uint8_t **data);
 int obex_getpeername(struct obex_session *os, char **name);
+int obex_getsockname(struct obex_session *os, char **name);
 
 /* Just a thin wrapper around memcmp to deal with NULL values */
 int memncmp0(const void *a, size_t na, const void *b, size_t nb);
-- 
1.8.1.4


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

* [PATCH 4/6] obex: get src and dst address and store it
  2013-05-28 17:45 [PATCH 1/6] transport: add getsockname to transport driver Gustavo Padovan
  2013-05-28 17:45 ` [PATCH 2/6] bluetooth: add getsockname() entry in the bluetooth driver Gustavo Padovan
  2013-05-28 17:45 ` [PATCH 3/6] obex: add obex_getsockname() Gustavo Padovan
@ 2013-05-28 17:45 ` Gustavo Padovan
  2013-05-28 17:45 ` [PATCH 5/6] session: add Source and Destination properties Gustavo Padovan
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Gustavo Padovan @ 2013-05-28 17:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: emilio.pozuelo, Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

This commit creates src and dst members in obex_session to later use them
to export via Session D-Bus API.
---
 obexd/src/obex-priv.h | 2 ++
 obexd/src/obex.c      | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/obexd/src/obex-priv.h b/obexd/src/obex-priv.h
index 41854bc..355a7f8 100644
--- a/obexd/src/obex-priv.h
+++ b/obexd/src/obex-priv.h
@@ -27,6 +27,8 @@ struct obex_session {
 	uint32_t id;
 	uint8_t cmd;
 	uint8_t action_id;
+	char *src;
+	char *dst;
 	char *name;
 	char *destname;
 	char *type;
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 7a1d612..8a7a8a3 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
@@ -252,6 +252,9 @@ static void obex_session_free(struct obex_session *os)
 	if (os->obex)
 		g_obex_unref(os->obex);
 
+	g_free(os->src);
+	g_free(os->dst);
+
 	g_free(os);
 }
 
@@ -1134,6 +1137,9 @@ int obex_session_start(GIOChannel *io, uint16_t tx_mtu, uint16_t rx_mtu,
 	os->obex = obex;
 	os->io = g_io_channel_ref(io);
 
+	obex_getsockname(os, &os->src);
+	obex_getpeername(os, &os->dst);
+
 	sessions = g_slist_prepend(sessions, os);
 
 	return 0;
-- 
1.8.1.4


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

* [PATCH 5/6] session: add Source and Destination properties
  2013-05-28 17:45 [PATCH 1/6] transport: add getsockname to transport driver Gustavo Padovan
                   ` (2 preceding siblings ...)
  2013-05-28 17:45 ` [PATCH 4/6] obex: get src and dst address and store it Gustavo Padovan
@ 2013-05-28 17:45 ` Gustavo Padovan
  2013-05-28 17:45 ` [PATCH 6/6] manager: remove unused call to obex_getpeername() Gustavo Padovan
  2013-05-29 11:41 ` [PATCH 1/6] transport: add getsockname to transport driver Luiz Augusto von Dentz
  5 siblings, 0 replies; 7+ messages in thread
From: Gustavo Padovan @ 2013-05-28 17:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: emilio.pozuelo, Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

This is useful when we want to know where a incoming OPP transfer, for
example, is from.
---
 obexd/src/manager.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/obexd/src/manager.c b/obexd/src/manager.c
index b86565c..a116a3e 100644
--- a/obexd/src/manager.c
+++ b/obexd/src/manager.c
@@ -265,6 +265,30 @@ static DBusMessage *unregister_agent(DBusConnection *conn,
 	return dbus_message_new_method_return(msg);
 }
 
+static gboolean get_source(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct obex_session *os = data;
+	char *s;
+
+	s = os->src;
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &s);
+
+	return TRUE;
+}
+
+static gboolean get_destination(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct obex_session *os = data;
+	char *s;
+
+	s = os->dst;
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &s);
+
+	return TRUE;
+}
+
 static gboolean session_target_exists(const GDBusPropertyTable *property,
 								void *data)
 {
@@ -529,6 +553,8 @@ static const GDBusPropertyTable transfer_properties[] = {
 };
 
 static const GDBusPropertyTable session_properties[] = {
+	{ "Source", "s", get_source },
+	{ "Destination", "s", get_destination },
 	{ "Target", "s", get_target, NULL, session_target_exists },
 	{ "Root", "s", get_root },
 	{ }
-- 
1.8.1.4


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

* [PATCH 6/6] manager: remove unused call to obex_getpeername()
  2013-05-28 17:45 [PATCH 1/6] transport: add getsockname to transport driver Gustavo Padovan
                   ` (3 preceding siblings ...)
  2013-05-28 17:45 ` [PATCH 5/6] session: add Source and Destination properties Gustavo Padovan
@ 2013-05-28 17:45 ` Gustavo Padovan
  2013-05-29 11:41 ` [PATCH 1/6] transport: add getsockname to transport driver Luiz Augusto von Dentz
  5 siblings, 0 replies; 7+ messages in thread
From: Gustavo Padovan @ 2013-05-28 17:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: emilio.pozuelo, Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

---
 obexd/src/manager.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/obexd/src/manager.c b/obexd/src/manager.c
index a116a3e..d0991e9 100644
--- a/obexd/src/manager.c
+++ b/obexd/src/manager.c
@@ -751,10 +751,8 @@ int manager_request_authorization(struct obex_transfer *transfer, int32_t time,
 	DBusPendingCall *call;
 	const char *filename = os->name ? os->name : "";
 	const char *type = os->type ? os->type : "";
-	char *address;
 	unsigned int watch;
 	gboolean got_reply;
-	int err;
 
 	if (!agent)
 		return -1;
@@ -765,10 +763,6 @@ int manager_request_authorization(struct obex_transfer *transfer, int32_t time,
 	if (!new_folder || !new_name)
 		return -EINVAL;
 
-	err = obex_getpeername(os, &address);
-	if (err < 0)
-		return err;
-
 	msg = dbus_message_new_method_call(agent->bus_name, agent->path,
 							AGENT_INTERFACE,
 							"AuthorizePush");
@@ -776,8 +770,6 @@ int manager_request_authorization(struct obex_transfer *transfer, int32_t time,
 	dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &transfer->path,
 							DBUS_TYPE_INVALID);
 
-	g_free(address);
-
 	if (!dbus_connection_send_with_reply(connection,
 					msg, &call, TIMEOUT)) {
 		dbus_message_unref(msg);
-- 
1.8.1.4


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

* Re: [PATCH 1/6] transport: add getsockname to transport driver
  2013-05-28 17:45 [PATCH 1/6] transport: add getsockname to transport driver Gustavo Padovan
                   ` (4 preceding siblings ...)
  2013-05-28 17:45 ` [PATCH 6/6] manager: remove unused call to obex_getpeername() Gustavo Padovan
@ 2013-05-29 11:41 ` Luiz Augusto von Dentz
  5 siblings, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2013-05-29 11:41 UTC (permalink / raw)
  To: Gustavo Padovan
  Cc: linux-bluetooth@vger.kernel.org, emilio.pozuelo, Gustavo Padovan

Hi Gustavo,

On Tue, May 28, 2013 at 10:45 AM, Gustavo Padovan <gustavo@padovan.org> wrote:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>
> Enable other pieces of obex to get the source Bluetooth address.
> ---
>  obexd/src/transport.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/obexd/src/transport.h b/obexd/src/transport.h
> index b81615b..97e10d0 100644
> --- a/obexd/src/transport.h
> +++ b/obexd/src/transport.h
> @@ -26,6 +26,7 @@ struct obex_transport_driver {
>         uint16_t service;
>         void *(*start) (struct obex_server *server, int *err);
>         int (*getpeername) (GIOChannel *io, char **name);
> +       int (*getsockname) (GIOChannel *io, char **name);
>         void (*stop) (void *data);
>  };
>
> --
> 1.8.1.4

Pushed, thanks.


--
Luiz Augusto von Dentz

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

end of thread, other threads:[~2013-05-29 11:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-28 17:45 [PATCH 1/6] transport: add getsockname to transport driver Gustavo Padovan
2013-05-28 17:45 ` [PATCH 2/6] bluetooth: add getsockname() entry in the bluetooth driver Gustavo Padovan
2013-05-28 17:45 ` [PATCH 3/6] obex: add obex_getsockname() Gustavo Padovan
2013-05-28 17:45 ` [PATCH 4/6] obex: get src and dst address and store it Gustavo Padovan
2013-05-28 17:45 ` [PATCH 5/6] session: add Source and Destination properties Gustavo Padovan
2013-05-28 17:45 ` [PATCH 6/6] manager: remove unused call to obex_getpeername() Gustavo Padovan
2013-05-29 11:41 ` [PATCH 1/6] transport: add getsockname to transport driver Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).