From: johan.hedberg@gmail.com
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 16/32] Bluetooth: Track LE L2CAP credits in l2cap_chan
Date: Thu, 5 Dec 2013 15:11:14 +0200 [thread overview]
Message-ID: <1386249090-10236-17-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1386249090-10236-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch adds tracking of L2CAP connection oriented channel local and
remote credits to struct l2cap_chan and ensures that connect requests
and responses contain the right values.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/l2cap.h | 3 +++
net/bluetooth/l2cap_core.c | 16 +++++++++++-----
net/bluetooth/l2cap_sock.c | 2 ++
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index c60498907180..8c59ed17ee90 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -514,6 +514,9 @@ struct l2cap_chan {
__u16 monitor_timeout;
__u16 mps;
+ __u16 tx_credits;
+ __u16 rx_credits;
+
__u8 tx_state;
__u8 rx_state;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 4ca6fbc777f0..8a1c528908fb 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -495,6 +495,8 @@ void l2cap_le_flowctl_init(struct l2cap_chan *chan)
chan->imtu = L2CAP_DEFAULT_MTU;
chan->omtu = L2CAP_LE_MIN_MTU;
chan->mode = L2CAP_MODE_LE_FLOWCTL;
+ chan->tx_credits = 0;
+ chan->rx_credits = L2CAP_LE_MAX_CREDITS;
}
void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
@@ -643,7 +645,7 @@ static void l2cap_chan_le_connect_reject(struct l2cap_chan *chan)
rsp.dcid = cpu_to_le16(chan->scid);
rsp.mtu = cpu_to_le16(chan->imtu);
rsp.mps = __constant_cpu_to_le16(L2CAP_LE_DEFAULT_MPS);
- rsp.credits = __constant_cpu_to_le16(L2CAP_LE_MAX_CREDITS);
+ rsp.credits = cpu_to_le16(chan->rx_credits);
rsp.result = cpu_to_le16(result);
l2cap_send_cmd(conn, chan->ident, L2CAP_LE_CONN_RSP, sizeof(rsp),
@@ -1212,7 +1214,7 @@ static void l2cap_le_connect(struct l2cap_chan *chan)
req.scid = cpu_to_le16(chan->scid);
req.mtu = cpu_to_le16(chan->imtu);
req.mps = __constant_cpu_to_le16(L2CAP_LE_DEFAULT_MPS);
- req.credits = __constant_cpu_to_le16(L2CAP_LE_MAX_CREDITS);
+ req.credits = cpu_to_le16(chan->rx_credits);
chan->ident = l2cap_get_ident(conn);
@@ -3690,7 +3692,7 @@ void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan)
rsp.dcid = cpu_to_le16(chan->scid);
rsp.mtu = cpu_to_le16(chan->imtu);
rsp.mps = __constant_cpu_to_le16(L2CAP_LE_DEFAULT_MPS);
- rsp.credits = __constant_cpu_to_le16(L2CAP_LE_MAX_CREDITS);
+ rsp.credits = cpu_to_le16(chan->rx_credits);
rsp.result = __constant_cpu_to_le16(L2CAP_CR_SUCCESS);
l2cap_send_cmd(conn, chan->ident, L2CAP_LE_CONN_RSP, sizeof(rsp),
@@ -5342,6 +5344,7 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn,
chan->dcid = dcid;
chan->omtu = mtu;
chan->remote_mps = mps;
+ chan->tx_credits = credits;
l2cap_chan_ready(chan);
break;
@@ -5445,7 +5448,7 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
struct l2cap_le_conn_req *req = (struct l2cap_le_conn_req *) data;
struct l2cap_le_conn_rsp rsp;
struct l2cap_chan *chan, *pchan;
- u16 dcid, scid, mtu, mps;
+ u16 dcid, scid, credits, mtu, mps;
__le16 psm;
u8 result;
@@ -5457,6 +5460,7 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
mps = __le16_to_cpu(req->mps);
psm = req->psm;
dcid = 0;
+ credits = 0;
if (mtu < 23 || mps < 23)
return -EPROTO;
@@ -5501,9 +5505,11 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
chan->dcid = scid;
chan->omtu = mtu;
chan->remote_mps = mps;
+ chan->tx_credits = __le16_to_cpu(req->credits);
__l2cap_chan_add(conn, chan);
dcid = chan->scid;
+ credits = chan->rx_credits;
__set_chan_timer(chan, chan->ops->get_sndtimeo(chan));
@@ -5535,7 +5541,7 @@ response:
}
rsp.dcid = cpu_to_le16(dcid);
- rsp.credits = __constant_cpu_to_le16(L2CAP_LE_MAX_CREDITS);
+ rsp.credits = cpu_to_le16(credits);
rsp.result = cpu_to_le16(result);
l2cap_send_cmd(conn, cmd->ident, L2CAP_LE_CONN_RSP, sizeof(rsp), &rsp);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 485ca349fed5..61e25bafdf43 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1321,6 +1321,8 @@ static void l2cap_sock_init(struct sock *sk, struct sock *parent)
chan->tx_win_max = pchan->tx_win_max;
chan->sec_level = pchan->sec_level;
chan->flags = pchan->flags;
+ chan->tx_credits = pchan->tx_credits;
+ chan->rx_credits = pchan->rx_credits;
security_sk_clone(parent, sk);
} else {
--
1.8.4.2
next prev parent reply other threads:[~2013-12-05 13:11 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-05 13:10 [PATCH v2 00/32] Bluetooth: LE CoC support johan.hedberg
2013-12-05 13:10 ` [PATCH v2 01/32] Bluetooth: Remove unnecessary braces from one-line if-statement johan.hedberg
2013-12-05 13:11 ` [PATCH v2 02/32] Bluetooth: Add module parameter to enable LE CoC support johan.hedberg
2013-12-05 13:11 ` [PATCH v2 03/32] Bluetooth: Update l2cap_global_chan_by_psm() to take a link type johan.hedberg
2013-12-05 13:11 ` [PATCH v2 04/32] Bluetooth: Allow l2cap_chan_check_security() to be used for LE links johan.hedberg
2013-12-05 13:11 ` [PATCH v2 05/32] Bluetooth: Pass command length to LE signaling channel handlers johan.hedberg
2013-12-05 13:11 ` [PATCH v2 06/32] Bluetooth: Move LE L2CAP initiator procedure to its own function johan.hedberg
2013-12-05 13:11 ` [PATCH v2 07/32] Bluetooth: Add definitions for LE connection oriented channels johan.hedberg
2013-12-05 13:11 ` [PATCH v2 08/32] Bluetooth: Add initial code for LE L2CAP Connect Request johan.hedberg
2013-12-05 13:11 ` [PATCH v2 09/32] Bluetooth: Add smp_sufficient_security helper function johan.hedberg
2013-12-05 13:11 ` [PATCH v2 10/32] Bluetooth: Refactor L2CAP connect rejection to its own function johan.hedberg
2013-12-05 13:11 ` [PATCH v2 11/32] Bluetooth: Add basic LE L2CAP connect request receiving support johan.hedberg
2013-12-05 13:11 ` [PATCH v2 12/32] Bluetooth: Fix L2CAP channel closing for LE connections johan.hedberg
2013-12-05 13:11 ` [PATCH v2 13/32] Bluetooth: Add L2CAP Disconnect suppport for LE johan.hedberg
2013-12-05 13:11 ` [PATCH v2 14/32] Bluetooth: Make l2cap_le_sig_cmd logic consistent johan.hedberg
2013-12-05 13:11 ` [PATCH v2 15/32] Bluetooth: Add LE L2CAP flow control mode johan.hedberg
2013-12-05 13:11 ` johan.hedberg [this message]
2013-12-05 13:11 ` [PATCH v2 17/32] Bluetooth: Limit L2CAP_OPTIONS socket option usage with LE johan.hedberg
2013-12-05 13:11 ` [PATCH v2 18/32] Bluetooth: Add new BT_SNDMTU and BT_RCVMTU socket options johan.hedberg
2013-12-05 13:11 ` [PATCH v2 19/32] Bluetooth: Implement returning of LE L2CAP credits johan.hedberg
2013-12-05 13:11 ` [PATCH v2 20/32] Bluetooth: Add LE flow control discipline johan.hedberg
2013-12-05 13:11 ` [PATCH v2 21/32] Bluetooth: Reject LE CoC commands when the feature is not enabled johan.hedberg
2013-12-05 13:11 ` [PATCH v2 22/32] Bluetooth: Introduce L2CAP channel callback for suspending johan.hedberg
2013-12-05 13:11 ` [PATCH v2 23/32] Bluetooth: Add LE L2CAP segmentation support for outgoing data johan.hedberg
2013-12-05 13:11 ` [PATCH v2 24/32] Bluetooth: Implement LE L2CAP reassembly johan.hedberg
2013-12-05 13:11 ` [PATCH v2 25/32] Bluetooth: Fix LE L2CAP Connect Request handling together with SMP johan.hedberg
2013-12-05 13:11 ` [PATCH v2 26/32] Bluetooth: Fix suspending the L2CAP socket if we start with 0 credits johan.hedberg
2013-12-05 13:11 ` [PATCH v2 27/32] Bluetooth: Limit LE MPS to the MTU value johan.hedberg
2013-12-05 13:11 ` [PATCH v2 28/32] Bluetooth: Fix clearing of chan->omtu for LE CoC channels johan.hedberg
2013-12-05 13:11 ` [PATCH v2 29/32] Bluetooth: Fix CID ranges for LE CoC CID allocations johan.hedberg
2013-12-05 13:11 ` [PATCH v2 30/32] Bluetooth: Fix validating LE PSM values johan.hedberg
2013-12-06 0:02 ` Anderson Lizardo
2013-12-06 5:05 ` Johan Hedberg
2013-12-05 13:11 ` [PATCH v2 31/32] Bluetooth: Add debugfs controls for LE CoC MPS and Credits johan.hedberg
2013-12-05 13:11 ` [PATCH v2 32/32] Bluetooth: Simplify l2cap_chan initialization for LE CoC johan.hedberg
2013-12-05 15:06 ` [PATCH v2 00/32] Bluetooth: LE CoC support Marcel Holtmann
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=1386249090-10236-17-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;
as well as URLs for NNTP newsgroup(s).