You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2020/05/18 09:27:20 UTC

[mynewt-nimble] 01/02: nimble/ll: Do not hand up data PDU with invalid CRC to LL

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 28809112c9ea36301e9c31fd854b009e89025b36
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu May 14 12:39:36 2020 +0200

    nimble/ll: Do not hand up data PDU with invalid CRC to LL
    
    It seems pointless to hand up data PDU with invalid CRC to LL since the
    only thing LL does with such packets is to throw them away. This saves
    us also an unnecessary rxpdu allocation.
---
 nimble/controller/src/ble_ll_conn.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 854d6c3..c5a2a41 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -3452,9 +3452,8 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
     uint16_t acl_hdr;
     struct ble_ll_conn_sm *connsm;
 
-    if (!BLE_MBUF_HDR_CRC_OK(hdr)) {
-        goto conn_rx_data_pdu_end;
-    }
+    /* Packets with invalid CRC are not sent to LL */
+    BLE_LL_ASSERT(BLE_MBUF_HDR_CRC_OK(hdr));
 
     /* XXX: there is a chance that the connection was thrown away and
        re-used before processing packets here. Fix this. */
@@ -3612,22 +3611,33 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
     uint32_t add_usecs;
     struct os_mbuf *txpdu;
     struct ble_ll_conn_sm *connsm;
-    struct os_mbuf *rxpdu;
+    struct os_mbuf *rxpdu = NULL;
     struct ble_mbuf_hdr *txhdr;
     int rx_phy_mode;
+    bool alloc_rxpdu = true;
 
     /* Retrieve the header and payload length */
     hdr_byte = rxbuf[0];
     rx_pyld_len = rxbuf[1];
 
     /*
+     * No need to alloc rxpdu for packets with invalid CRC, we would throw them
+     * away instantly from LL anyway.
+     */
+    if (!BLE_MBUF_HDR_CRC_OK(rxhdr)) {
+        alloc_rxpdu = false;
+    }
+
+    /*
      * We need to attempt to allocate a buffer here. The reason we do this
      * now is that we should not ack the packet if we have no receive
      * buffers available. We want to free up our transmit PDU if it was
      * acked, but we should not ack the received frame if we cant hand it up.
      * NOTE: we hand up empty pdu's to the LL task!
      */
-    rxpdu = ble_ll_rxpdu_alloc(rx_pyld_len + BLE_LL_PDU_HDR_LEN);
+    if (alloc_rxpdu) {
+        rxpdu = ble_ll_rxpdu_alloc(rx_pyld_len + BLE_LL_PDU_HDR_LEN);
+    }
 
     /*
      * We should have a current connection state machine. If we dont, we just