Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 4f5dd65cf -> 408caf5c0
MYNEWT-627 BLE Host - Join rx frags into 1 mbuf 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/408caf5c Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/408caf5c Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/408caf5c Branch: refs/heads/develop Commit: 408caf5c0f7fd5e77846ede3df37954fa7a859ad Parents: 4f5dd65 Author: Christopher Collins <[email protected]> Authored: Tue Feb 14 12:30:26 2017 -0800 Committer: Christopher Collins <[email protected]> Committed: Tue Feb 14 12:30:26 2017 -0800 ---------------------------------------------------------------------- net/nimble/host/src/ble_l2cap.c | 26 +++++++++++++++++++++++++- net/nimble/host/syscfg.yml | 7 +++++++ 2 files changed, 32 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/408caf5c/net/nimble/host/src/ble_l2cap.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c index 2fb48b6..2b60a30 100644 --- a/net/nimble/host/src/ble_l2cap.c +++ b/net/nimble/host/src/ble_l2cap.c @@ -173,6 +173,28 @@ ble_l2cap_discard_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan) ble_l2cap_forget_rx(conn, chan); } +static void +ble_l2cap_append_rx(struct ble_l2cap_chan *chan, struct os_mbuf *frag) +{ + int rc; + + (void)rc; + +#if MYNEWT_VAL(BLE_L2CAP_JOIN_RX_FRAGS) + /* Copy the data from the incoming fragment into the packet in progress. */ + rc = os_mbuf_appendfrom(chan->rx_buf, frag, 0, OS_MBUF_PKTLEN(frag)); + if (rc == 0) { + os_mbuf_free_chain(frag); + return; + } +#endif + + /* Join disabled or append failed due to mbuf shortage. Just attach the + * mbuf to the end of the packet. + */ + os_mbuf_concat(chan->rx_buf, frag); +} + static int ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, struct os_mbuf *om, @@ -182,9 +204,11 @@ ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, int rc; if (chan->rx_buf == NULL) { + /* First fragment in packet. */ chan->rx_buf = om; } else { - os_mbuf_concat(chan->rx_buf, om); + /* Continuation of packet in progress. */ + ble_l2cap_append_rx(chan, om); } /* Determine if packet is fully reassembled. */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/408caf5c/net/nimble/host/syscfg.yml ---------------------------------------------------------------------- diff --git a/net/nimble/host/syscfg.yml b/net/nimble/host/syscfg.yml index dd42ed8..be9d953 100644 --- a/net/nimble/host/syscfg.yml +++ b/net/nimble/host/syscfg.yml @@ -46,6 +46,13 @@ syscfg.defs: BLE_L2CAP_SIG_MAX_PROCS: description: 'TBD' value: 1 + BLE_L2CAP_JOIN_RX_FRAGS: + description: > + Whether to collapse incoming L2CAP fragments into a minimal set of + mbufs. + 1: Slower, more memory efficient. + 0: Faster, less memory efficient. + value: 1 BLE_L2CAP_RX_FRAG_TIMEOUT: description: > Expiry time for incoming data packets (ms). If this much time
