linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH obexd 3/4] gobex: automatically use SRM when transport type is SOCK_SEQPACKET
Date: Tue,  3 Jan 2012 15:52:23 +0200	[thread overview]
Message-ID: <1325598744-18855-3-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1325598744-18855-1-git-send-email-luiz.dentz@gmail.com>

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

This simplifies the applications so SRM setup phase became transparent
while using SOCK_SEQPACKET which is useful for GOEP 2.0 since in that
case we can only use SRM if the transport is L2CAP.

This also follows GOEP 2.0 Page 14 - 4.6 Using Single Response Mode:

  "The Server cannot issue an enable request, but can only issue a
  response to an enable request from the Client. SRM will remain in
  effect for the duration of the operation that enabled it (PUT or GET)
  ...
  SRM headers shall not be sent in CONNECT request or response packets."

and Page 22 - 5.4 Establishment of OBEX Connection:

  "SRM headers shall not be sent in the Connect request or response
  packets (note, this is to preserve backwards compatibility). SRM shall
  be enabled through Put and Get operations only."

So only in case of PUT or GET requests SRM is automatically configured,
applications can still enable it manually for other operations by adding
the headers like before but it is not recommended.

Note that it would be a good practice to indicate SRM support by using
value 0x02, but since that should happens during CONNECT command it is
not done automatically for requests when acting as a client, server
responding to indicate requests will automatically add SRM headers though.
---
 gobex/gobex.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/gobex/gobex.c b/gobex/gobex.c
index ed051ee..0db4567 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -72,6 +72,7 @@ struct _GObex {
 	size_t tx_sent;
 
 	gboolean suspended;
+	gboolean use_srm;
 
 	struct srm_config *srm;
 
@@ -505,6 +506,9 @@ static void setup_srm(GObex *obex, GObexPacket *pkt, gboolean outgoing)
 	guint8 op;
 	gboolean final;
 
+	if (!obex->use_srm)
+		return;
+
 	op = g_obex_packet_get_operation(pkt, &final);
 
 	hdr = g_obex_packet_get_header(pkt, G_OBEX_HDR_SRM);
@@ -538,6 +542,24 @@ static void setup_srm(GObex *obex, GObexPacket *pkt, gboolean outgoing)
 	set_srm(obex, op, G_OBEX_SRM_DISABLE);
 }
 
+static void prepare_srm_rsp(GObex *obex, GObexPacket *pkt)
+{
+	GObexHeader *hdr;
+
+	if (!obex->use_srm || obex->srm == NULL)
+		return;
+
+	if (obex->srm->enabled)
+		return;
+
+	hdr = g_obex_packet_get_header(pkt, G_OBEX_HDR_SRM);
+	if (hdr != NULL)
+		return;
+
+	hdr = g_obex_header_new_uint8(G_OBEX_HDR_SRM, G_OBEX_SRM_ENABLE);
+	g_obex_packet_prepend_header(pkt, hdr);
+}
+
 gboolean g_obex_send(GObex *obex, GObexPacket *pkt, GError **err)
 {
 	struct pending_pkt *p;
@@ -552,8 +574,14 @@ gboolean g_obex_send(GObex *obex, GObexPacket *pkt, GError **err)
 		return FALSE;
 	}
 
-	if (obex->rx_last_op == G_OBEX_OP_CONNECT)
+	switch (obex->rx_last_op) {
+	case G_OBEX_OP_CONNECT:
 		prepare_connect_rsp(obex, pkt);
+	case G_OBEX_OP_GET:
+	case G_OBEX_OP_PUT:
+		prepare_srm_rsp(obex, pkt);
+		break;
+	}
 
 	setup_srm(obex, pkt, TRUE);
 
@@ -567,6 +595,24 @@ gboolean g_obex_send(GObex *obex, GObexPacket *pkt, GError **err)
 	return ret;
 }
 
+static void prepare_srm_req(GObex *obex, GObexPacket *pkt)
+{
+	GObexHeader *hdr;
+
+	if (!obex->use_srm)
+		return;
+
+	if (obex->srm != NULL && obex->srm->enabled)
+		return;
+
+	hdr = g_obex_packet_get_header(pkt, G_OBEX_HDR_SRM);
+	if (hdr != NULL)
+		return;
+
+	hdr = g_obex_header_new_uint8(G_OBEX_HDR_SRM, G_OBEX_SRM_ENABLE);
+	g_obex_packet_prepend_header(pkt, hdr);
+}
+
 guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout,
 			GObexResponseFunc func, gpointer user_data,
 			GError **err)
@@ -574,9 +620,16 @@ guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout,
 	GObexHeader *hdr;
 	struct pending_pkt *p;
 	static guint id = 1;
+	guint8 op;
 
 	g_obex_debug(G_OBEX_DEBUG_COMMAND, "conn %u", obex->conn_id);
 
+	op = g_obex_packet_get_operation(req, NULL);
+	if (op == G_OBEX_OP_PUT || op == G_OBEX_OP_GET) {
+		/* Only enable SRM automatically for GET and PUT */
+		prepare_srm_req(obex, req);
+	}
+
 	setup_srm(obex, req, TRUE);
 
 	if (obex->conn_id == CONNID_INVALID)
@@ -1226,6 +1279,7 @@ GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type,
 		obex->write = write_stream;
 		break;
 	case G_OBEX_TRANSPORT_PACKET:
+		obex->use_srm = TRUE;
 		obex->read = read_packet;
 		obex->write = write_packet;
 		break;
-- 
1.7.7.4


  parent reply	other threads:[~2012-01-03 13:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-03 13:52 [PATCH obexd 1/4] gobex: handle Single Response Mode (SRM) headers Luiz Augusto von Dentz
2012-01-03 13:52 ` [PATCH obexd 2/4] gobex: handle Single Response Mode Parameters (SRMP) headers Luiz Augusto von Dentz
2012-01-03 13:52 ` Luiz Augusto von Dentz [this message]
2012-01-03 15:58   ` [PATCH obexd 3/4] gobex: automatically use SRM when transport type is SOCK_SEQPACKET Hendrik Sattler
2012-01-03 22:31     ` Luiz Augusto von Dentz
2012-01-04 18:48       ` Hendrik Sattler
2012-01-05 12:11         ` Luiz Augusto von Dentz
2012-01-05 22:40           ` Hendrik Sattler
2012-01-09 11:10             ` Luiz Augusto von Dentz
2012-01-03 13:52 ` [PATCH obexd 4/4] gobex: fix unit test when using SOCK_SEQPACKET Luiz Augusto von Dentz
2012-01-11 13:58 ` [PATCH obexd 1/4] gobex: handle Single Response Mode (SRM) headers Johan Hedberg

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=1325598744-18855-3-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).