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 2022/08/05 08:33:15 UTC

[mynewt-nimble] branch master updated (a77acc42 -> 3bb185da)

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

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


    from a77acc42 porting/npl/nuttx: fix callout_handler implement
     new 65716bde nimble/ll: Fix spurious MIC failure
     new 3bb185da nimble/phy/nrf: Wait for CCM to finish decryption

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nimble/controller/src/ble_ll_conn.c  |  4 ++--
 nimble/drivers/nrf52/src/ble_phy.c   | 14 ++++----------
 nimble/drivers/nrf5340/src/ble_phy.c | 14 ++++----------
 3 files changed, 10 insertions(+), 22 deletions(-)


[mynewt-nimble] 02/02: nimble/phy/nrf: Wait for CCM to finish decryption

Posted by an...@apache.org.
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 3bb185daad2296c02d4efd13760b4b884d70d7e4
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Aug 4 11:47:32 2022 +0200

    nimble/phy/nrf: Wait for CCM to finish decryption
    
    In extremely rare cases seems like ENDCRYPT flag is not set before we
    check for MISTATUS, so just spin a bit in that case and wait for CCM to
    finish.
---
 nimble/drivers/nrf52/src/ble_phy.c   | 14 ++++----------
 nimble/drivers/nrf5340/src/ble_phy.c | 14 ++++----------
 2 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/nimble/drivers/nrf52/src/ble_phy.c b/nimble/drivers/nrf52/src/ble_phy.c
index 9b441238..c06536a9 100644
--- a/nimble/drivers/nrf52/src/ble_phy.c
+++ b/nimble/drivers/nrf52/src/ble_phy.c
@@ -1100,6 +1100,10 @@ ble_phy_rx_end_isr(void)
         ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_CRC_OK;
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
         if (g_ble_phy_data.phy_encrypted) {
+            while (NRF_CCM->EVENTS_ENDCRYPT == 0) {
+                /* Make sure CCM finished */
+            };
+
             /* Only set MIC failure flag if frame is not zero length */
             if ((dptr[1] != 0) && (NRF_CCM->MICSTATUS == 0)) {
                 ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_MIC_FAILURE;
@@ -1115,16 +1119,6 @@ ble_phy_rx_end_isr(void)
                 STATS_INC(ble_phy_stats, rx_hw_err);
                 ble_hdr->rxinfo.flags &= ~BLE_MBUF_HDR_F_CRC_OK;
             }
-
-            /*
-             * XXX: This is a total hack work-around for now but I dont
-             * know what else to do. If ENDCRYPT is not set and we are
-             * encrypted we need to not trust this frame and drop it.
-             */
-            if (NRF_CCM->EVENTS_ENDCRYPT == 0) {
-                STATS_INC(ble_phy_stats, rx_hw_err);
-                ble_hdr->rxinfo.flags &= ~BLE_MBUF_HDR_F_CRC_OK;
-            }
         }
 #endif
     }
diff --git a/nimble/drivers/nrf5340/src/ble_phy.c b/nimble/drivers/nrf5340/src/ble_phy.c
index 060e32ee..51b80a56 100644
--- a/nimble/drivers/nrf5340/src/ble_phy.c
+++ b/nimble/drivers/nrf5340/src/ble_phy.c
@@ -958,6 +958,10 @@ ble_phy_rx_end_isr(void)
         ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_CRC_OK;
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
         if (g_ble_phy_data.phy_encrypted) {
+            while (NRF_CCM_NS->EVENTS_ENDCRYPT == 0) {
+                /* Make sure CCM finished */
+            };
+
             /* Only set MIC failure flag if frame is not zero length */
             if ((dptr[1] != 0) && (NRF_CCM_NS->MICSTATUS == 0)) {
                 ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_MIC_FAILURE;
@@ -973,16 +977,6 @@ ble_phy_rx_end_isr(void)
                 STATS_INC(ble_phy_stats, rx_hw_err);
                 ble_hdr->rxinfo.flags &= ~BLE_MBUF_HDR_F_CRC_OK;
             }
-
-            /*
-             * XXX: This is a total hack work-around for now but I dont
-             * know what else to do. If ENDCRYPT is not set and we are
-             * encrypted we need to not trust this frame and drop it.
-             */
-            if (NRF_CCM_NS->EVENTS_ENDCRYPT == 0) {
-                STATS_INC(ble_phy_stats, rx_hw_err);
-                ble_hdr->rxinfo.flags &= ~BLE_MBUF_HDR_F_CRC_OK;
-            }
         }
 #endif
     }


[mynewt-nimble] 01/02: nimble/ll: Fix spurious MIC failure

Posted by an...@apache.org.
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 65716bde509975501782cbe2c74556cd4e5d7eca
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Aug 4 11:28:14 2022 +0200

    nimble/ll: Fix spurious MIC failure
    
    We should only check MIC failures on new PDUs.
    
    If we acked encrypted packet, but peer did not receive that ack, the
    encryption counter will be different on both sides for next packet. This
    is ok since we should drop retransmission anyway. However, MIC failure
    is always set by phy and failure is checked in LL before checking for
    retransmissions, so it does not quite work as expected.
---
 nimble/controller/src/ble_ll_conn.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 4d1bf85e..ec758bff 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -3365,9 +3365,10 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
     hdr_byte = rxbuf[0];
     acl_len = rxbuf[1];
     llid = hdr_byte & BLE_LL_DATA_HDR_LLID_MASK;
+    rxd_sn = hdr_byte & BLE_LL_DATA_HDR_SN_MASK;
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
-    if (BLE_MBUF_HDR_MIC_FAILURE(hdr)) {
+    if (BLE_MBUF_HDR_MIC_FAILURE(hdr) && (rxd_sn != connsm->last_rxd_sn)) {
         STATS_INC(ble_ll_conn_stats, mic_failures);
         ble_ll_conn_timeout(connsm, BLE_ERR_CONN_TERM_MIC);
         goto conn_rx_data_pdu_end;
@@ -3431,7 +3432,6 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
      * Discard the received PDU if the sequence number is the same
      * as the last received sequence number
      */
-    rxd_sn = hdr_byte & BLE_LL_DATA_HDR_SN_MASK;
     if (rxd_sn == connsm->last_rxd_sn) {
        STATS_INC(ble_ll_conn_stats, data_pdu_rx_dup);
        goto conn_rx_data_pdu_end;