Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect
@ 2014-03-21 11:58 Luiz Augusto von Dentz
  2014-03-21 11:58 ` [PATCH BlueZ 2/3] unit/test-gobex: Add test for g_obex_disconnect Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2014-03-21 11:58 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds g_obex_disconnect function which can be used to send OBEX
Disconnect command.
---
 gobex/gobex.c | 12 ++++++++++++
 gobex/gobex.h |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/gobex/gobex.c b/gobex/gobex.c
index d7d325b..ca15941 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -1445,6 +1445,18 @@ guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data,
 	return g_obex_send_req(obex, req, -1, func, user_data, err);
 }
 
+guint g_obex_disconnect(GObex *obex, GObexResponseFunc func, gpointer user_data,
+								GError **err)
+{
+	GObexPacket *req;
+
+	g_obex_debug(G_OBEX_DEBUG_COMMAND, "");
+
+	req = g_obex_packet_new(G_OBEX_OP_DISCONNECT, TRUE, G_OBEX_HDR_INVALID);
+
+	return g_obex_send_req(obex, req, -1, func, user_data, err);
+}
+
 guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
 					gpointer user_data, GError **err)
 {
diff --git a/gobex/gobex.h b/gobex/gobex.h
index 76a224e..7c47590 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -75,6 +75,9 @@ void g_obex_unref(GObex *obex);
 guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data,
 				GError **err, guint8 first_hdr_id, ...);
 
+guint g_obex_disconnect(GObex *obex, GObexResponseFunc func, gpointer user_data,
+								GError **err);
+
 guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
 					gpointer user_data, GError **err);
 
-- 
1.8.5.3


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

* [PATCH BlueZ 2/3] unit/test-gobex: Add test for g_obex_disconnect
  2014-03-21 11:58 [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect Luiz Augusto von Dentz
@ 2014-03-21 11:58 ` Luiz Augusto von Dentz
  2014-03-21 11:58 ` [PATCH BlueZ 3/3] obexd/client: Fix not sending OBEX Disconnect when disconnecting Luiz Augusto von Dentz
  2014-03-21 14:15 ` [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2014-03-21 11:58 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 unit/test-gobex.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/unit/test-gobex.c b/unit/test-gobex.c
index ded83dd..2834c77 100644
--- a/unit/test-gobex.c
+++ b/unit/test-gobex.c
@@ -45,6 +45,10 @@ static uint8_t pkt_connect_req[] = { G_OBEX_OP_CONNECT | FINAL_BIT,
 static uint8_t pkt_connect_rsp[] = { 0x20 | FINAL_BIT, 0x00, 0x07,
 					0x10, 0x00, 0x10, 0x00 };
 
+static uint8_t pkt_disconnect_req[] = { G_OBEX_OP_DISCONNECT | FINAL_BIT,
+					0x00, 0x03 };
+static uint8_t pkt_disconnect_rsp[] = { 0x20 | FINAL_BIT, 0x00, 0x03 };
+
 static uint8_t pkt_setpath_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, 0x00, 0x10,
 					0x02, 0x00,
 					G_OBEX_HDR_NAME, 0x00, 0x0b,
@@ -883,6 +887,42 @@ static void test_connect(void)
 	g_assert_no_error(d.err);
 }
 
+static void test_obex_disconnect(void)
+{
+	GIOChannel *io;
+	GIOCondition cond;
+	guint io_id, timer_id;
+	GObex *obex;
+	struct test_data d = { 0, NULL, {
+			{ pkt_disconnect_req, sizeof(pkt_disconnect_req) } }, {
+			{ pkt_disconnect_rsp, sizeof(pkt_disconnect_rsp) } } };
+
+	create_endpoints(&obex, &io, SOCK_STREAM);
+
+	cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
+	io_id = g_io_add_watch(io, cond, test_io_cb, &d);
+
+	d.mainloop = g_main_loop_new(NULL, FALSE);
+
+	timer_id = g_timeout_add_seconds(1, test_timeout, &d);
+
+	g_obex_disconnect(obex, req_complete, &d, &d.err);
+	g_assert_no_error(d.err);
+
+	g_main_loop_run(d.mainloop);
+
+	g_assert_cmpuint(d.count, ==, 1);
+
+	g_main_loop_unref(d.mainloop);
+
+	g_source_remove(timer_id);
+	g_io_channel_unref(io);
+	g_source_remove(io_id);
+	g_obex_unref(obex);
+
+	g_assert_no_error(d.err);
+}
+
 static void test_setpath(void)
 {
 	GIOChannel *io;
@@ -1188,6 +1228,7 @@ int main(int argc, char *argv[])
 					test_cancel_req_delay_pkt);
 
 	g_test_add_func("/gobex/test_connect", test_connect);
+	g_test_add_func("/gobex/test_obex_disconnect", test_obex_disconnect);
 
 	g_test_add_func("/gobex/test_setpath", test_setpath);
 	g_test_add_func("/gobex/test_setpath_up", test_setpath_up);
-- 
1.8.5.3


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

* [PATCH BlueZ 3/3] obexd/client: Fix not sending OBEX Disconnect when disconnecting
  2014-03-21 11:58 [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect Luiz Augusto von Dentz
  2014-03-21 11:58 ` [PATCH BlueZ 2/3] unit/test-gobex: Add test for g_obex_disconnect Luiz Augusto von Dentz
@ 2014-03-21 11:58 ` Luiz Augusto von Dentz
  2014-03-21 14:15 ` [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2014-03-21 11:58 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Sending OBEX Disconnect command before disconnecting the transport is
mandatory.
---
 obexd/client/session.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/obexd/client/session.c b/obexd/client/session.c
index 8138b1e..cb176e4 100644
--- a/obexd/client/session.c
+++ b/obexd/client/session.c
@@ -240,8 +240,6 @@ static void session_free(struct obc_session *session)
 	if (session->p)
 		pending_request_free(session->p);
 
-	sessions = g_slist_remove(sessions, session);
-
 	g_free(session->path);
 	g_free(session->owner);
 	g_free(session->source);
@@ -250,6 +248,25 @@ static void session_free(struct obc_session *session)
 	g_free(session);
 }
 
+static void disconnect_complete(GObex *obex, GError *err, GObexPacket *rsp,
+							void *user_data)
+{
+	struct obc_session *session = user_data;
+
+	DBG("");
+
+	if (err)
+		error("%s", err->message);
+
+	/* Disconnect transport */
+	if (session->id > 0 && session->transport != NULL) {
+		session->transport->disconnect(session->id);
+		session->id = 0;
+	}
+
+	session_free(session);
+}
+
 void obc_session_unref(struct obc_session *session)
 {
 	int refs;
@@ -261,6 +278,19 @@ void obc_session_unref(struct obc_session *session)
 	if (refs > 0)
 		return;
 
+	sessions = g_slist_remove(sessions, session);
+
+	if (!session->obex)
+		goto disconnect;
+
+	/* Wait OBEX Disconnect to complete if command succeed otherwise
+	 * proceed with transport disconnection since there is nothing else to
+	 * be done */
+	if (g_obex_disconnect(session->obex, disconnect_complete, session,
+									NULL))
+		return;
+
+disconnect:
 	/* Disconnect transport */
 	if (session->id > 0 && session->transport != NULL) {
 		session->transport->disconnect(session->id);
-- 
1.8.5.3


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

* Re: [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect
  2014-03-21 11:58 [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect Luiz Augusto von Dentz
  2014-03-21 11:58 ` [PATCH BlueZ 2/3] unit/test-gobex: Add test for g_obex_disconnect Luiz Augusto von Dentz
  2014-03-21 11:58 ` [PATCH BlueZ 3/3] obexd/client: Fix not sending OBEX Disconnect when disconnecting Luiz Augusto von Dentz
@ 2014-03-21 14:15 ` Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2014-03-21 14:15 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

Hi,

On Fri, Mar 21, 2014 at 1:58 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> This adds g_obex_disconnect function which can be used to send OBEX
> Disconnect command.
> ---
>  gobex/gobex.c | 12 ++++++++++++
>  gobex/gobex.h |  3 +++
>  2 files changed, 15 insertions(+)
>
> diff --git a/gobex/gobex.c b/gobex/gobex.c
> index d7d325b..ca15941 100644
> --- a/gobex/gobex.c
> +++ b/gobex/gobex.c
> @@ -1445,6 +1445,18 @@ guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data,
>         return g_obex_send_req(obex, req, -1, func, user_data, err);
>  }
>
> +guint g_obex_disconnect(GObex *obex, GObexResponseFunc func, gpointer user_data,
> +                                                               GError **err)
> +{
> +       GObexPacket *req;
> +
> +       g_obex_debug(G_OBEX_DEBUG_COMMAND, "");
> +
> +       req = g_obex_packet_new(G_OBEX_OP_DISCONNECT, TRUE, G_OBEX_HDR_INVALID);
> +
> +       return g_obex_send_req(obex, req, -1, func, user_data, err);
> +}
> +
>  guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
>                                         gpointer user_data, GError **err)
>  {
> diff --git a/gobex/gobex.h b/gobex/gobex.h
> index 76a224e..7c47590 100644
> --- a/gobex/gobex.h
> +++ b/gobex/gobex.h
> @@ -75,6 +75,9 @@ void g_obex_unref(GObex *obex);
>  guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data,
>                                 GError **err, guint8 first_hdr_id, ...);
>
> +guint g_obex_disconnect(GObex *obex, GObexResponseFunc func, gpointer user_data,
> +                                                               GError **err);
> +
>  guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
>                                         gpointer user_data, GError **err);
>
> --
> 1.8.5.3

Pushed.


-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2014-03-21 14:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-21 11:58 [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect Luiz Augusto von Dentz
2014-03-21 11:58 ` [PATCH BlueZ 2/3] unit/test-gobex: Add test for g_obex_disconnect Luiz Augusto von Dentz
2014-03-21 11:58 ` [PATCH BlueZ 3/3] obexd/client: Fix not sending OBEX Disconnect when disconnecting Luiz Augusto von Dentz
2014-03-21 14:15 ` [PATCH BlueZ 1/3] gobex: Add g_obex_disconnect 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