You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/17 20:33:57 UTC

[3/4] incubator-mynewt-core git commit: BLE Host - Don't send overly-large ACL data pkts.

BLE Host - Don't send overly-large ACL data pkts.

The host was misinterpreting the buffer size that the controller
indicates in its response to the LE Read Buffer Size HCI command.
Specifically, the host interpreted the value as the number of bytes it
can put in an ACL payload.  This is wrong; the value is the total size
of an ACL data packet, including the ACL data header.

The fix is to reduce the maximum number of data bytes the host includes
in an ACL data packet by four (size of an ACL data header).


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/b4c9f850
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b4c9f850
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b4c9f850

Branch: refs/heads/develop
Commit: b4c9f850d8562f9f1201728476546540243ba7c1
Parents: f31fbdd
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Nov 17 12:25:16 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Nov 17 12:25:16 2016 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_hci.c            | 18 +++++++++++++++---
 net/nimble/host/test/src/ble_hs_test_util.c |  4 ++--
 2 files changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4c9f850/net/nimble/host/src/ble_hs_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci.c b/net/nimble/host/src/ble_hs_hci.c
index ebb75d9..ba86e2f 100644
--- a/net/nimble/host/src/ble_hs_hci.c
+++ b/net/nimble/host/src/ble_hs_hci.c
@@ -352,6 +352,15 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg)
     return 0;
 }
 
+/**
+ * Calculates the largest ACL payload that the controller can accept.  This is
+ * everything in an ACL data packet except for the ACL header.
+ */
+static uint16_t
+ble_hs_hci_max_acl_payload_sz(void)
+{
+    return ble_hs_hci_buf_sz - BLE_HCI_DATA_HDR_SZ;
+}
 
 /**
  * Splits an appropriately-sized fragment from the front of an outgoing ACL
@@ -374,12 +383,15 @@ static int
 ble_hs_hci_split_frag(struct os_mbuf **om, struct os_mbuf **out_frag)
 {
     struct os_mbuf *frag;
+    uint16_t max_sz;
     int rc;
 
     /* Assume failure. */
     *out_frag = NULL;
 
-    if (OS_MBUF_PKTLEN(*om) <= ble_hs_hci_buf_sz) {
+    max_sz = ble_hs_hci_max_acl_payload_sz();
+
+    if (OS_MBUF_PKTLEN(*om) <= max_sz) {
         /* Final fragment. */
         *out_frag = *om;
         *om = NULL;
@@ -393,12 +405,12 @@ ble_hs_hci_split_frag(struct os_mbuf **om, struct os_mbuf **out_frag)
     }
 
     /* Move data from the front of the packet into the fragment mbuf. */
-    rc = os_mbuf_appendfrom(frag, *om, 0, ble_hs_hci_buf_sz);
+    rc = os_mbuf_appendfrom(frag, *om, 0, max_sz);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
         goto err;
     }
-    os_mbuf_adj(*om, ble_hs_hci_buf_sz);
+    os_mbuf_adj(*om, max_sz);
 
     /* More fragments to follow. */
     *out_frag = frag;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4c9f850/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index 0e9ef43..083afc4 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -982,8 +982,8 @@ ble_hs_test_util_set_startup_acks(void)
         {
             .opcode = ble_hs_hci_util_opcode_join(
                 BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_BUF_SIZE),
-            /* Use a very low buffer size (16) to test fragmentation. */
-            .evt_params = { 0x10, 0x00, 0x20 },
+            /* Use a very low buffer size (20) to test fragmentation. */
+            .evt_params = { 0x14, 0x00, 0x20 },
             .evt_params_len = 3,
         },
         {