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 2015/11/06 21:32:12 UTC

incubator-mynewt-larva git commit: Don't send more than ATT_MTU-1 bytes of attr data.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master dfd27cb24 -> 3f2a8b0f0


Don't send more than ATT_MTU-1 bytes of attr data.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/3f2a8b0f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/3f2a8b0f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/3f2a8b0f

Branch: refs/heads/master
Commit: 3f2a8b0f0878230dec0b4ab96cb0f4bd59ad863d
Parents: dfd27cb
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Nov 6 12:31:41 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Nov 6 12:31:41 2015 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs.c               |  2 --
 net/nimble/host/src/ble_hs_att.c           | 15 ++++++++---
 net/nimble/host/src/ble_hs_att.h           |  2 +-
 net/nimble/host/src/ble_hs_conn.c          |  2 ++
 net/nimble/host/src/ble_hs_conn.h          |  1 +
 net/nimble/host/src/test/ble_hs_att_test.c | 34 ++++++++++++++++++++-----
 6 files changed, 42 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3f2a8b0f/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index ba13da6..af02ae7 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -81,8 +81,6 @@ ble_host_task_handler(void *arg)
                 /* Reset callout, wakeup every 50ms */
                 os_callout_reset(&ble_host_task_timer, 50);
                 break;
-            case BLE_HOST_EVENT_NEW_ATTR_CONN: 
-                break;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3f2a8b0f/net/nimble/host/src/ble_hs_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att.c b/net/nimble/host/src/ble_hs_att.c
index f30b3e3..2be795d 100644
--- a/net/nimble/host/src/ble_hs_att.c
+++ b/net/nimble/host/src/ble_hs_att.c
@@ -348,8 +348,10 @@ ble_hs_att_tx_error_rsp(struct ble_l2cap_chan *chan, uint8_t req_op,
 }
 
 static int
-ble_hs_att_tx_read_rsp(struct ble_l2cap_chan *chan, void *data, int data_len)
+ble_hs_att_tx_read_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                       void *attr_data, int attr_len)
 {
+    uint16_t data_len;
     uint8_t op;
     int rc;
 
@@ -359,9 +361,14 @@ ble_hs_att_tx_read_rsp(struct ble_l2cap_chan *chan, void *data, int data_len)
         return rc;
     }
 
-    /* XXX: Check attribute length against MTU. */
+    /* Vol. 3, part F, 3.2.9; don't send more than ATT_MTU-1 bytes of data. */
+    if (attr_len > conn->bhc_att_mtu - 1) {
+        data_len = conn->bhc_att_mtu - 1;
+    } else {
+        data_len = attr_len;
+    }
 
-    rc = ble_l2cap_tx(chan, data, data_len);
+    rc = ble_l2cap_tx(chan, attr_data, data_len);
     if (rc != 0) {
         return rc;
     }
@@ -407,7 +414,7 @@ ble_hs_att_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
         goto send_err;
     }
 
-    rc = ble_hs_att_tx_read_rsp(chan, attr_data, attr_len);
+    rc = ble_hs_att_tx_read_rsp(conn, chan, attr_data, attr_len);
     if (rc != 0) {
         goto send_err;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3f2a8b0f/net/nimble/host/src/ble_hs_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att.h b/net/nimble/host/src/ble_hs_att.h
index 7ab8c8c..573b260 100644
--- a/net/nimble/host/src/ble_hs_att.h
+++ b/net/nimble/host/src/ble_hs_att.h
@@ -19,7 +19,7 @@
 
 #include "host/uuid.h"
 
-#define BLE_HOST_EVENT_NEW_ATTR_CONN (OS_EVENT_T_PERUSER)
+#define BLE_HS_ATT_MTU_DFLT         23
 
 struct ble_hs_att_entry;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3f2a8b0f/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index a745f73..ad4f7c8 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -39,6 +39,8 @@ ble_hs_conn_alloc(void)
         goto err;
     }
 
+    conn->bhc_att_mtu = BLE_HS_ATT_MTU_DFLT;
+
     SLIST_INIT(&conn->bhc_channels);
 
     chan = ble_hs_att_create_chan();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3f2a8b0f/net/nimble/host/src/ble_hs_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.h b/net/nimble/host/src/ble_hs_conn.h
index 35c752b..297366d 100644
--- a/net/nimble/host/src/ble_hs_conn.h
+++ b/net/nimble/host/src/ble_hs_conn.h
@@ -26,6 +26,7 @@ struct ble_hs_conn {
     SLIST_ENTRY(ble_hs_conn) bhc_next;
     uint16_t bhc_handle;
     int bhc_fd; // XXX Temporary.
+    uint16_t bhc_att_mtu;
 
     struct ble_l2cap_chan_list bhc_channels;
 };

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3f2a8b0f/net/nimble/host/src/test/ble_hs_att_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_att_test.c b/net/nimble/host/src/test/ble_hs_att_test.c
index 72bdae0..4450eeb 100644
--- a/net/nimble/host/src/test/ble_hs_att_test.c
+++ b/net/nimble/host/src/test/ble_hs_att_test.c
@@ -16,6 +16,7 @@
 
 #include <stddef.h>
 #include <errno.h>
+#include <string.h>
 #include "nimble/hci_common.h"
 #include "host/ble_hs.h"
 #include "host/ble_hs_test.h"
@@ -25,14 +26,15 @@
 #include "ble_hs_att_cmd.h"
 #include "testutil/testutil.h"
 
-static uint8_t ble_hs_att_test_attr_1[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
+static uint8_t *ble_hs_att_test_attr_1;
+static int ble_hs_att_test_attr_1_len;
 
 static int
 ble_hs_att_test_misc_attr_fn_1(struct ble_hs_att_entry *entry,
                                uint8_t op, uint8_t **data, int *len)
 {
     *data = ble_hs_att_test_attr_1;
-    *len = sizeof ble_hs_att_test_attr_1;
+    *len = ble_hs_att_test_attr_1_len;
 
     return 0;
 }
@@ -84,10 +86,10 @@ ble_hs_att_test_misc_verify_tx_read_rsp(struct ble_l2cap_chan *chan,
     TEST_ASSERT(rc != 0);
 
     /* Remove the read response from the buffer. */
-    os_mbuf_adj(&ble_l2cap_mbuf_pool, chan->blc_tx_buf, i);
+    os_mbuf_adj(&ble_l2cap_mbuf_pool, chan->blc_tx_buf, attr_len + 1);
 }
 
-TEST_CASE(ble_hs_att_test_small_read)
+TEST_CASE(ble_hs_att_test_read)
 {
     struct ble_hs_att_read_req req;
     struct ble_l2cap_chan *chan;
@@ -111,9 +113,11 @@ TEST_CASE(ble_hs_att_test_small_read)
     rc = ble_l2cap_rx_payload(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_att_test_misc_verify_tx_err_rsp(chan, BLE_HS_ATT_OP_READ_REQ, 0,
-                                        BLE_ERR_ATTR_NOT_FOUND);
+                                           BLE_ERR_ATTR_NOT_FOUND);
 
     /*** Successful read. */
+    ble_hs_att_test_attr_1 = (uint8_t[]){0,1,2,3,4,5,6,7};
+    ble_hs_att_test_attr_1_len = 8;
     rc = ble_hs_att_register(uuid, 0, &req.bharq_handle,
                              ble_hs_att_test_misc_attr_fn_1);
     TEST_ASSERT(rc == 0);
@@ -125,7 +129,23 @@ TEST_CASE(ble_hs_att_test_small_read)
     TEST_ASSERT(rc == 0);
 
     ble_hs_att_test_misc_verify_tx_read_rsp(chan, ble_hs_att_test_attr_1,
-                                            sizeof ble_hs_att_test_attr_1);
+                                            ble_hs_att_test_attr_1_len);
+
+
+    /*** Partial read. */
+    ble_hs_att_test_attr_1 =
+        (uint8_t[]){0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,
+                    22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39};
+    ble_hs_att_test_attr_1_len = 40;
+
+    rc = ble_hs_att_read_req_write(buf, sizeof buf, &req);
+    TEST_ASSERT(rc == 0);
+
+    rc = ble_l2cap_rx_payload(conn, chan, buf, sizeof buf);
+    TEST_ASSERT(rc == 0);
+
+    ble_hs_att_test_misc_verify_tx_read_rsp(chan, ble_hs_att_test_attr_1,
+                                            BLE_HS_ATT_MTU_DFLT - 1);
 
     ble_hs_conn_free(conn);
 }
@@ -137,7 +157,7 @@ TEST_SUITE(att_suite)
     rc = host_init();
     TEST_ASSERT_FATAL(rc == 0);
 
-    ble_hs_att_test_small_read();
+    ble_hs_att_test_read();
 }
 
 int