Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: patrick.ohly@intel.com
Subject: [PATCH BlueZ 7/8] gobex: Handle suspending/resuming for GET when SRM is active
Date: Fri, 14 Feb 2014 17:53:03 +0200	[thread overview]
Message-ID: <1392393184-15266-7-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1392393184-15266-1-git-send-email-luiz.dentz@gmail.com>

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

This adds support for suspending/resuming GET requests GET when SRM is
active, in this case suspending the TX queue wont stop the remote
to continue sending packets, to do that SRMP header should be set to wait
so the remote should wait.
---
 gobex/gobex-transfer.c |  2 +-
 gobex/gobex.c          | 56 ++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index b815d60..09f56ba 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -390,7 +390,7 @@ static void transfer_put_req(GObex *obex, GObexPacket *req, gpointer user_data)
 
 	rspcode = put_get_bytes(transfer, req);
 
-	/* Don't send continue while in SRM */
+	/* Don't send continue while SRM is active */
 	if (g_obex_srm_active(transfer->obex) &&
 				rspcode == G_OBEX_RSP_CONTINUE)
 		goto done;
diff --git a/gobex/gobex.c b/gobex/gobex.c
index 291ed72..0d9b449 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -105,6 +105,7 @@ struct pending_pkt {
 	GObexResponseFunc rsp_func;
 	gpointer rsp_data;
 	gboolean cancelled;
+	gboolean suspended;
 };
 
 struct req_handler {
@@ -407,7 +408,9 @@ static void setup_srm(GObex *obex, GObexPacket *pkt, gboolean outgoing)
 		g_obex_header_get_uint8(hdr, &srmp);
 		g_obex_debug(G_OBEX_DEBUG_COMMAND, "srmp 0x%02x", srmp);
 		set_srmp(obex, srmp, outgoing);
-	} else
+	} else if (obex->pending_req && obex->pending_req->suspended)
+		g_obex_packet_add_uint8(pkt, G_OBEX_HDR_SRMP, G_OBEX_SRMP_WAIT);
+	else
 		set_srmp(obex, -1, outgoing);
 
 	if (final)
@@ -845,24 +848,73 @@ gboolean g_obex_remove_request_function(GObex *obex, guint id)
 	return TRUE;
 }
 
+static void g_obex_srm_suspend(GObex *obex)
+{
+	struct pending_pkt *p = obex->pending_req;
+	GObexPacket *req;
+
+	g_source_remove(p->timeout_id);
+	p->suspended = TRUE;
+
+	req = g_obex_packet_new(G_OBEX_OP_GET, TRUE,
+					G_OBEX_HDR_SRMP, G_OBEX_SRMP_WAIT,
+					G_OBEX_HDR_INVALID);
+
+	g_obex_send(obex, req, NULL);
+}
+
 void g_obex_suspend(GObex *obex)
 {
+	struct pending_pkt *req = obex->pending_req;
+
 	g_obex_debug(G_OBEX_DEBUG_COMMAND, "conn %u", obex->conn_id);
 
+	if (!g_obex_srm_active(obex) || !req)
+		goto done;
+
+	/* Send SRMP wait in case of GET */
+	if (g_obex_packet_get_operation(req->pkt, NULL) == G_OBEX_OP_GET) {
+		g_obex_srm_suspend(obex);
+		return;
+	}
+
+done:
+	obex->suspended = TRUE;
+
 	if (obex->write_source > 0) {
 		g_source_remove(obex->write_source);
 		obex->write_source = 0;
 	}
+}
 
-	obex->suspended = TRUE;
+static void g_obex_srm_resume(GObex *obex)
+{
+	struct pending_pkt *p = obex->pending_req;
+	GObexPacket *req;
+
+	p->timeout_id = g_timeout_add_seconds(p->timeout, req_timeout, obex);
+	p->suspended = FALSE;
+
+	req = g_obex_packet_new(G_OBEX_OP_GET, TRUE, G_OBEX_HDR_INVALID);
+
+	g_obex_send(obex, req, NULL);
 }
 
 void g_obex_resume(GObex *obex)
 {
+	struct pending_pkt *req = obex->pending_req;
+
 	g_obex_debug(G_OBEX_DEBUG_COMMAND, "conn %u", obex->conn_id);
 
 	obex->suspended = FALSE;
 
+	if (g_obex_srm_active(obex) || !req)
+		goto done;
+
+	if (g_obex_packet_get_operation(req->pkt, NULL) == G_OBEX_OP_GET)
+		g_obex_srm_resume(obex);
+
+done:
 	if (g_queue_get_length(obex->tx_queue) > 0 || obex->tx_data > 0)
 		enable_tx(obex);
 }
-- 
1.8.5.3


  parent reply	other threads:[~2014-02-14 15:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14 15:52 [PATCH BlueZ 1/8] obexd/transfer: Add Transfer.Suspend method Luiz Augusto von Dentz
2014-02-14 15:52 ` [PATCH BlueZ 2/8] obexd/transfer: Add Transfer.Resume method Luiz Augusto von Dentz
2014-02-14 15:52 ` [PATCH BlueZ 3/8] tools/obexctl: Add suspend command Luiz Augusto von Dentz
2014-02-14 15:53 ` [PATCH BlueZ 4/8] tools/obexctl: Add resume command Luiz Augusto von Dentz
2014-02-14 15:53 ` [PATCH BlueZ 5/8] unit/test-gobex-transfer: Add /gobex/test_packet_get_req_suspend_resume Luiz Augusto von Dentz
2014-02-14 15:53 ` [PATCH BlueZ 6/8] gobex: Fix not handling SRM properly Luiz Augusto von Dentz
2014-02-14 15:53 ` Luiz Augusto von Dentz [this message]
2014-02-14 15:53 ` [PATCH BlueZ 8/8] doc/obex-api: Update documentation Luiz Augusto von Dentz
2014-02-17  7:24   ` Andrei Emeltchenko
2014-02-18  9:09   ` Patrick Ohly
2014-02-18  9:30     ` Luiz Augusto von Dentz
2014-02-18 16:54       ` Patrick Ohly
2014-02-19 17:11         ` Luiz Augusto von Dentz
2014-02-20 10:52           ` Patrick Ohly
2014-02-20 12:09             ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392393184-15266-7-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=patrick.ohly@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox