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/17 03:45:28 UTC
incubator-mynewt-larva git commit: Additional ATT find-info tests.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 845b5fa50 -> 55082ce6c
Additional ATT find-info tests.
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/55082ce6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/55082ce6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/55082ce6
Branch: refs/heads/master
Commit: 55082ce6cd6597ce96f0c8c5d9134465a9bccf6e
Parents: 845b5fa
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Nov 16 18:45:12 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Nov 16 18:45:12 2015 -0800
----------------------------------------------------------------------
net/nimble/host/src/ble_hs_att.c | 9 +-
net/nimble/host/src/ble_hs_uuid.c | 3 +
net/nimble/host/src/test/ble_hs_att_test.c | 177 ++++++++++++++++++++++-
net/nimble/host/src/test/ble_hs_uuid_test.c | 22 ++-
4 files changed, 203 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/55082ce6/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 2becbb8..fa92da5 100644
--- a/net/nimble/host/src/ble_hs_att.c
+++ b/net/nimble/host/src/ble_hs_att.c
@@ -421,7 +421,7 @@ ble_hs_att_fill_info(struct ble_hs_att_find_info_req *req, uint8_t *buf,
goto done;
}
- new_rsp_sz = *rsp_sz + 16;
+ new_rsp_sz = *rsp_sz + 18;
if (new_rsp_sz > buf_sz) {
goto done;
}
@@ -482,8 +482,11 @@ ble_hs_att_rx_find_info_req(struct ble_hs_conn *conn,
* response base at the start of the buffer.
*/
rc = ble_hs_att_fill_info(
- &req, ble_hs_att_tx_buf + BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ,
- conn->bhc_att_mtu, &rsp_sz, &rsp.bhafp_format);
+ &req,
+ ble_hs_att_tx_buf + BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ,
+ conn->bhc_att_mtu - BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ,
+ &rsp_sz,
+ &rsp.bhafp_format);
if (rc != 0) {
ble_hs_att_tx_error_rsp(chan, BLE_HS_ATT_OP_FIND_INFO_REQ,
req.bhafq_start_handle,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/55082ce6/net/nimble/host/src/ble_hs_uuid.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_uuid.c b/net/nimble/host/src/ble_hs_uuid.c
index 2c9e1aa..f905159 100644
--- a/net/nimble/host/src/ble_hs_uuid.c
+++ b/net/nimble/host/src/ble_hs_uuid.c
@@ -52,6 +52,9 @@ ble_hs_uuid_16bit(uint8_t *uuid128)
}
uuid16 = (uuid128[2] << 8) + uuid128[3];
+ if (uuid16 == 0) {
+ return -1;
+ }
return uuid16;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/55082ce6/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 85084cc..d267a6d 100644
--- a/net/nimble/host/src/test/ble_hs_att_test.c
+++ b/net/nimble/host/src/test/ble_hs_att_test.c
@@ -136,6 +136,68 @@ ble_hs_att_test_misc_verify_tx_write_rsp(struct ble_l2cap_chan *chan)
BLE_HS_ATT_WRITE_RSP_SZ);
}
+struct ble_hs_att_test_info_entry {
+ uint16_t handle; /* 0 on last entry */
+ uint16_t uuid16; /* 0 if not present. */
+ uint8_t uuid128[16];
+};
+
+static void
+ble_hs_att_test_misc_verify_tx_find_info_rsp(
+ struct ble_l2cap_chan *chan, struct ble_hs_att_test_info_entry *entries)
+{
+ struct ble_hs_att_test_info_entry *entry;
+ struct ble_hs_att_find_info_rsp rsp;
+ uint16_t handle;
+ uint16_t uuid16;
+ uint8_t buf[BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ];
+ uint8_t uuid128[16];
+ int off;
+ int rc;
+
+ off = 0;
+
+ rc = os_mbuf_copydata(chan->blc_tx_buf, off, sizeof buf, buf);
+ TEST_ASSERT(rc == 0);
+ off += sizeof buf;
+
+ rc = ble_hs_att_find_info_rsp_parse(buf, sizeof buf, &rsp);
+ TEST_ASSERT(rc == 0);
+
+ TEST_ASSERT(rsp.bhafp_op == BLE_HS_ATT_OP_FIND_INFO_RSP);
+
+ for (entry = entries; entry->handle != 0; entry++) {
+ rc = os_mbuf_copydata(chan->blc_tx_buf, off, 2, &handle);
+ TEST_ASSERT(rc == 0);
+ off += 2;
+
+ handle = le16toh((void *)&handle);
+ TEST_ASSERT(handle == entry->handle);
+
+ if (entry->uuid16 != 0) {
+ TEST_ASSERT(rsp.bhafp_format ==
+ BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT);
+ rc = os_mbuf_copydata(chan->blc_tx_buf, off, 2, &uuid16);
+ TEST_ASSERT(rc == 0);
+ off += 2;
+
+ uuid16 = le16toh((void *)&uuid16);
+ TEST_ASSERT(uuid16 == entry->uuid16);
+ } else {
+ TEST_ASSERT(rsp.bhafp_format ==
+ BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT);
+ rc = os_mbuf_copydata(chan->blc_tx_buf, off, 16, uuid128);
+ TEST_ASSERT(rc == 0);
+ off += 16;
+
+ TEST_ASSERT(memcmp(uuid128, entry->uuid128, 16) == 0);
+ }
+ }
+
+ /* Remove the error response from the buffer. */
+ os_mbuf_adj(&ble_l2cap_mbuf_pool, chan->blc_tx_buf, off);
+}
+
TEST_CASE(ble_hs_att_test_read)
{
struct ble_hs_att_read_req req;
@@ -251,7 +313,16 @@ TEST_CASE(ble_hs_att_test_find_info)
struct ble_hs_att_find_info_req req;
struct ble_l2cap_chan *chan;
struct ble_hs_conn *conn;
+ uint16_t handle1;
+ uint16_t handle2;
+ uint16_t handle3;
uint8_t buf[BLE_HS_ATT_FIND_INFO_REQ_SZ];
+ uint8_t uuid1[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+ uint8_t uuid2[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
+ uint8_t uuid3[16] = {
+ 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb
+ };
int rc;
rc = ble_hs_init(10);
@@ -264,6 +335,9 @@ TEST_CASE(ble_hs_att_test_find_info)
chan = ble_l2cap_chan_find(conn, BLE_L2CAP_CID_ATT);
TEST_ASSERT_FATAL(chan != NULL);
+ /* Increase the MTU to 128 bytes to allow testing of long responses. */
+ conn->bhc_att_mtu = 128;
+
/*** Start handle of 0. */
req.bhafq_op = BLE_HS_ATT_OP_FIND_INFO_REQ;
req.bhafq_start_handle = 0;
@@ -304,7 +378,108 @@ TEST_CASE(ble_hs_att_test_find_info)
ble_hs_att_test_misc_verify_tx_err_rsp(chan, BLE_HS_ATT_OP_FIND_INFO_REQ,
200, BLE_HS_ATT_ERR_ATTR_NOT_FOUND);
- /* XXX: Test successful responses. */
+ /*** Range too late. */
+ rc = ble_hs_att_register(uuid1, 0, &handle1,
+ ble_hs_att_test_misc_attr_fn_1);
+ TEST_ASSERT(rc == 0);
+
+ req.bhafq_start_handle = 200;
+ req.bhafq_end_handle = 300;
+
+ rc = ble_hs_att_find_info_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_err_rsp(chan, BLE_HS_ATT_OP_FIND_INFO_REQ,
+ 200, BLE_HS_ATT_ERR_ATTR_NOT_FOUND);
+
+ /*** One 128-bit entry. */
+ req.bhafq_start_handle = handle1;
+ req.bhafq_end_handle = handle1;
+
+ rc = ble_hs_att_find_info_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_find_info_rsp(chan,
+ ((struct ble_hs_att_test_info_entry[]) { {
+ .handle = handle1,
+ .uuid128 = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
+ }, {
+ .handle = 0,
+ } }));
+
+ /*** Two 128-bit entries. */
+ rc = ble_hs_att_register(uuid2, 0,
+ &handle2, ble_hs_att_test_misc_attr_fn_1);
+ TEST_ASSERT(rc == 0);
+
+ req.bhafq_start_handle = handle1;
+ req.bhafq_end_handle = handle2;
+
+ rc = ble_hs_att_find_info_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_find_info_rsp(chan,
+ ((struct ble_hs_att_test_info_entry[]) { {
+ .handle = handle1,
+ .uuid128 = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
+ }, {
+ .handle = handle2,
+ .uuid128 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
+ }, {
+ .handle = 0,
+ } }));
+
+ /*** Two 128-bit entries; 16-bit entry doesn't get sent. */
+ rc = ble_hs_att_register(uuid3, 0,
+ &handle3, ble_hs_att_test_misc_attr_fn_1);
+ TEST_ASSERT(rc == 0);
+
+ req.bhafq_start_handle = handle1;
+ req.bhafq_end_handle = handle3;
+
+ rc = ble_hs_att_find_info_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_find_info_rsp(chan,
+ ((struct ble_hs_att_test_info_entry[]) { {
+ .handle = handle1,
+ .uuid128 = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
+ }, {
+ .handle = handle2,
+ .uuid128 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
+ }, {
+ .handle = 0,
+ } }));
+
+ /*** Remaining 16-bit entry requested. */
+ req.bhafq_start_handle = handle3;
+ req.bhafq_end_handle = handle3;
+
+ rc = ble_hs_att_find_info_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_find_info_rsp(chan,
+ ((struct ble_hs_att_test_info_entry[]) { {
+ .handle = handle3,
+ .uuid16 = 0x000f,
+ }, {
+ .handle = 0,
+ } }));
}
TEST_SUITE(att_suite)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/55082ce6/net/nimble/host/src/test/ble_hs_uuid_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_uuid_test.c b/net/nimble/host/src/test/ble_hs_uuid_test.c
index 449418f..fa1dfcd 100644
--- a/net/nimble/host/src/test/ble_hs_uuid_test.c
+++ b/net/nimble/host/src/test/ble_hs_uuid_test.c
@@ -28,29 +28,43 @@ TEST_CASE(ble_hs_uuid_test_128_to_16)
uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
-
TEST_ASSERT(uuid16 == 0x0003);
/*** BNEP */
uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
-
TEST_ASSERT(uuid16 == 0x000f);
/*** L2CAP */
uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
-
TEST_ASSERT(uuid16 == 0x0100);
/*** ObEXObjectPush */
uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
-
TEST_ASSERT(uuid16 == 0x1105);
+
+ /*** Invalid base. */
+ uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
+ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9c, 0x34, 0xfb}));
+ TEST_ASSERT(uuid16 == -1);
+
+ /*** Invalid prefix. */
+ uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
+ 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
+ TEST_ASSERT(uuid16 == -1);
+
+ /*** 16-bit UUID of 0. */
+ uuid16 = ble_hs_uuid_16bit(((uint8_t[]) {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}));
+ TEST_ASSERT(uuid16 == -1);
}
TEST_SUITE(ble_hs_uuid_test_suite)