Linux bluetooth development
 help / color / mirror / Atom feed
From: johan.hedberg@gmail.com
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH] Bluetooth: Fix consistency of local vs remote PSM reporting
Date: Tue, 28 Jan 2014 14:13:37 -0800	[thread overview]
Message-ID: <1390947217-21874-1-git-send-email-johan.hedberg@gmail.com> (raw)

From: Johan Hedberg <johan.hedberg@intel.com>

When we're the initiators of a connection the PSM resides on the remote
side and when we're acceptors on the local side. Since the PSM isn't
defined for the initiating side for all practical purposes it should
have the value 0 if requested by user space.

The l2cap_chan structure contains two values for a PSM, psm and sport,
which are used to return the value for getsockname() and getpeername().
However, the values returned haven't really been consistent. When we
initiate an outgoing connection the sport value should be set to 0, and
when we receive an incoming connect request the sport of the newly
created l2cap_chan should reflect the targetted PSM.

It's important the chan->psm has always a valid value since there are
several code paths that rely on it being set regardless of acceptor or
initiator use cases.

This patch updates the relevant outgoing and incoming connection paths
to ensure that the psm and sport l2cap_chan members have the appropriate
values in all cases.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d2ef49b54aa2..a5519a8dcb65 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3774,7 +3774,8 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
 	bacpy(&chan->dst, &conn->hcon->dst);
 	chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type);
 	chan->dst_type = bdaddr_type(conn->hcon, conn->hcon->dst_type);
-	chan->psm  = psm;
+	chan->psm = psm;
+	chan->sport = psm;
 	chan->dcid = scid;
 	chan->local_amp_id = amp_id;
 
@@ -5421,7 +5422,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
 	bacpy(&chan->dst, &conn->hcon->dst);
 	chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type);
 	chan->dst_type = bdaddr_type(conn->hcon, conn->hcon->dst_type);
-	chan->psm  = psm;
+	chan->psm = psm;
+	chan->sport = psm;
 	chan->dcid = scid;
 	chan->omtu = mtu;
 	chan->remote_mps = mps;
@@ -7083,6 +7085,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 	chan->dst_type = dst_type;
 
 	chan->psm = psm;
+	chan->sport = 0;
 	chan->dcid = cid;
 
 	auth_type = l2cap_get_auth_type(chan);
-- 
1.8.5.3


                 reply	other threads:[~2014-01-28 22:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1390947217-21874-1-git-send-email-johan.hedberg@gmail.com \
    --to=johan.hedberg@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