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/750707ba Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/750707ba Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/750707ba Branch: refs/heads/master Commit: 750707ba60915ea182d416c8289324d16af8fa64 Parents: 6963daf Author: Åukasz Rymanowski <[email protected]> Authored: Fri Mar 3 11:30:45 2017 +0100 Committer: Åukasz Rymanowski <[email protected]> Committed: Fri Mar 3 12:40:43 2017 +0100 ---------------------------------------------------------------------- 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/750707ba/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/750707ba/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
