You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ry...@apache.org on 2019/03/13 08:28:20 UTC
[mynewt-nimble] branch master updated: nimble/host: Fix credits
setting for L2CAP CoC
This is an automated email from the ASF dual-hosted git repository.
rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
The following commit(s) were added to refs/heads/master by this push:
new f8f0274 nimble/host: Fix credits setting for L2CAP CoC
f8f0274 is described below
commit f8f02740acdf4d302d5c2f91ee2e34444d405671
Author: Ćukasz Rymanowski <lu...@codecoup.pl>
AuthorDate: Tue Mar 12 13:13:12 2019 +0100
nimble/host: Fix credits setting for L2CAP CoC
With current implementation we could end up having credits 0 when
requested L2CAP CoC MTU is much lower than MTU on L2CAP channel.
This patch fixes it.
---
nimble/host/src/ble_l2cap_coc.c | 5 ++++-
nimble/host/test/src/ble_l2cap_test.c | 22 ++++++++++++++++++----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/nimble/host/src/ble_l2cap_coc.c b/nimble/host/src/ble_l2cap_coc.c
index 4dd2a93..61345f5 100644
--- a/nimble/host/src/ble_l2cap_coc.c
+++ b/nimble/host/src/ble_l2cap_coc.c
@@ -255,7 +255,10 @@ ble_l2cap_coc_chan_alloc(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
/* Number of credits should allow to send full SDU with on given
* L2CAP MTU
*/
- chan->coc_rx.credits = (mtu + (chan->my_mtu - 1) / 2) / chan->my_mtu;
+ chan->coc_rx.credits = mtu / chan->my_mtu;
+ if (mtu % chan->my_mtu) {
+ chan->coc_rx.credits++;
+ }
chan->initial_credits = chan->coc_rx.credits;
return chan;
diff --git a/nimble/host/test/src/ble_l2cap_test.c b/nimble/host/test/src/ble_l2cap_test.c
index e0c537f..106b9f6 100644
--- a/nimble/host/test/src/ble_l2cap_test.c
+++ b/nimble/host/test/src/ble_l2cap_test.c
@@ -719,6 +719,18 @@ ble_l2cap_test_event(struct ble_l2cap_event *event, void *arg)
}
}
+static uint16_t ble_l2cap_calculate_credits(uint16_t mtu, uint16_t mps)
+{
+ int credits;
+
+ credits = mtu / mps;
+ if (mtu % mps) {
+ credits++;
+ }
+
+ return credits;
+}
+
static void
ble_l2cap_test_coc_connect(struct test_data *t)
{
@@ -747,8 +759,9 @@ ble_l2cap_test_coc_connect(struct test_data *t)
return;
}
- req.credits = htole16((t->mtu + (MYNEWT_VAL(BLE_L2CAP_COC_MTU) - 1) / 2) /
- MYNEWT_VAL(BLE_L2CAP_COC_MTU));
+ req.credits = htole16(
+ ble_l2cap_calculate_credits(t->mtu,
+ MYNEWT_VAL(BLE_L2CAP_COC_MTU)));
req.mps = htole16(MYNEWT_VAL(BLE_L2CAP_COC_MTU));
req.mtu = htole16(t->mtu);
req.psm = htole16(t->psm);
@@ -812,8 +825,9 @@ ble_l2cap_test_coc_connect_by_peer(struct test_data *t)
rsp.result = htole16(ev->l2cap_status);
} else {
/* Receive response from peer.*/
- rsp.credits = htole16((t->mtu + (MYNEWT_VAL(BLE_L2CAP_COC_MTU) - 1) / 2) /
- MYNEWT_VAL(BLE_L2CAP_COC_MTU));
+ rsp.credits = htole16(
+ ble_l2cap_calculate_credits(t->mtu,
+ MYNEWT_VAL(BLE_L2CAP_COC_MTU)));
rsp.dcid = current_cid++;
rsp.mps = htole16(MYNEWT_VAL(BLE_L2CAP_COC_MTU));
rsp.mtu = htole16(t->mtu);