nimble/l2cap: Add initial credits calculations With this patch we calculate initial credits in that way that peer device is able to send full SDU by fill up fully LE frames.
If it happens that peer is not filling up LE Frames, there is mechanism to handling it already in receiving function Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9ee8e85e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9ee8e85e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9ee8e85e Branch: refs/heads/1_0_0_dev Commit: 9ee8e85e296d9e49aaedff9998074a01364e3b69 Parents: 687403e Author: Åukasz Rymanowski <[email protected]> Authored: Fri Mar 3 11:30:45 2017 +0100 Committer: Marko Kiiskila <[email protected]> Committed: Mon Mar 6 15:53:47 2017 -0800 ---------------------------------------------------------------------- net/nimble/host/src/ble_l2cap_coc.c | 16 ++++++++++------ net/nimble/host/src/ble_l2cap_priv.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9ee8e85e/net/nimble/host/src/ble_l2cap_coc.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c index f7ecef4..fbfbf31 100644 --- a/net/nimble/host/src/ble_l2cap_coc.c +++ b/net/nimble/host/src/ble_l2cap_coc.c @@ -249,9 +249,14 @@ ble_l2cap_coc_chan_alloc(uint16_t conn_handle, uint16_t psm, uint16_t mtu, chan->my_mtu = BLE_L2CAP_COC_MTU; chan->rx_fn = ble_l2cap_coc_rx_fn; chan->coc_rx.mtu = mtu; - chan->coc_rx.credits = 10; /* FIXME Calculate it */ chan->coc_rx.sdu = sdu_rx; + /* 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->initial_credits = chan->coc_rx.credits; return chan; } @@ -459,13 +464,12 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx) return; } - /* FIXME 10 is hardcoded - make it better. - * We want to back only that much credits which remote side is missing + /* We want to back only that much credits which remote side is missing * to be able to send complete SDU. */ - if (chan->coc_rx.credits < 10) { - ble_l2cap_sig_le_credits(chan, 10 - chan->coc_rx.credits); - chan->coc_rx.credits = 10; + if (chan->coc_rx.credits < c->initial_credits) { + ble_l2cap_sig_le_credits(chan, c->initial_credits - chan->coc_rx.credits); + chan->coc_rx.credits = c->initial_credits; } ble_hs_unlock(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9ee8e85e/net/nimble/host/src/ble_l2cap_priv.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h index 5db63c3..1d035e8 100644 --- a/net/nimble/host/src/ble_l2cap_priv.h +++ b/net/nimble/host/src/ble_l2cap_priv.h @@ -82,6 +82,7 @@ struct ble_l2cap_chan { uint16_t psm; struct ble_l2cap_coc_endpoint coc_rx; struct ble_l2cap_coc_endpoint coc_tx; + uint16_t initial_credits; ble_l2cap_event_fn *cb; void *cb_arg; #endif
