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 2021/10/14 23:12:52 UTC

[mynewt-nimble] 02/02: nimble/hci: Fix mbuf allocation for HCI ACL fragmentation

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 eaa1e6771ed8fb8b8ce1c7bca6c46c32bb204978
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Oct 14 12:47:31 2021 +0200

    nimble/hci: Fix mbuf allocation for HCI ACL fragmentation
    
    We need to use proper user pkt header length when allocating new mbuf
    for HCI ACL data fragment, otherwise leading space won't be set properly
    and data may be overwritten.
    
    See 20c4817625fc4d33b0d9c2f23cb0fe96eba5e988 for reference.
    
    Note: technically this does not make much sense since we use max HCI ACL
    data size for combined build so fragmentation won't happen, but let's
    fix it anyway just in case someone uses other value for whatever reason.
---
 nimble/host/src/ble_gatts.c  |  2 +-
 nimble/host/src/ble_hs_hci.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c
index a635f2d..83402e7 100644
--- a/nimble/host/src/ble_gatts.c
+++ b/nimble/host/src/ble_gatts.c
@@ -364,7 +364,7 @@ ble_gatts_val_access(uint16_t conn_handle, uint16_t attr_handle,
             gatt_ctxt->om = *om;
         } else {
             new_om = 1;
-            gatt_ctxt->om = os_msys_get_pkthdr(0, 0);
+            gatt_ctxt->om = ble_hs_mbuf_att_pkt();
             if (gatt_ctxt->om == NULL) {
                 return BLE_ATT_ERR_INSUFFICIENT_RES;
             }
diff --git a/nimble/host/src/ble_hs_hci.c b/nimble/host/src/ble_hs_hci.c
index e5c3a74..53d3647 100644
--- a/nimble/host/src/ble_hs_hci.c
+++ b/nimble/host/src/ble_hs_hci.c
@@ -41,11 +41,20 @@ static uint32_t ble_hs_hci_sup_feat;
 
 static uint8_t ble_hs_hci_version;
 
+#if MYNEWT_VAL(BLE_CONTROLLER)
 #define BLE_HS_HCI_FRAG_DATABUF_SIZE    \
     (BLE_ACL_MAX_PKT_SIZE +             \
      BLE_HCI_DATA_HDR_SZ +              \
      sizeof (struct os_mbuf_pkthdr) +   \
+     sizeof (struct ble_mbuf_hdr) +      \
      sizeof (struct os_mbuf))
+#else
+#define BLE_HS_HCI_FRAG_DATABUF_SIZE    \
+    (BLE_ACL_MAX_PKT_SIZE +             \
+     BLE_HCI_DATA_HDR_SZ +              \
+     sizeof (struct os_mbuf_pkthdr) +   \
+     sizeof (struct os_mbuf))
+#endif
 
 #define BLE_HS_HCI_FRAG_MEMBLOCK_SIZE   \
     (OS_ALIGN(BLE_HS_HCI_FRAG_DATABUF_SIZE, 4))
@@ -421,7 +430,11 @@ ble_hs_hci_frag_alloc(uint16_t frag_size, void *arg)
     struct os_mbuf *om;
 
     /* Prefer the dedicated one-element fragment pool. */
+#if MYNEWT_VAL(BLE_CONTROLLER)
+    om = os_mbuf_get_pkthdr(&ble_hs_hci_frag_mbuf_pool, sizeof(struct ble_mbuf_hdr));
+#else
     om = os_mbuf_get_pkthdr(&ble_hs_hci_frag_mbuf_pool, 0);
+#endif
     if (om != NULL) {
         om->om_data += BLE_HCI_DATA_HDR_SZ;
         return om;