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/01/06 00:14:45 UTC
[3/4] incubator-mynewt-larva git commit: Notification tests.
Notification 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/b296dd4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/b296dd4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/b296dd4c
Branch: refs/heads/master
Commit: b296dd4cb10602a08600aa6d9d57ee210a6ebffb
Parents: 8764e91
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Jan 5 14:52:16 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Jan 5 15:13:50 2016 -0800
----------------------------------------------------------------------
net/nimble/host/src/ble_att.c | 7 ++
net/nimble/host/src/ble_att_cmd.c | 4 +-
net/nimble/host/src/ble_att_priv.h | 3 +
net/nimble/host/src/ble_att_svr.c | 4 +
net/nimble/host/src/test/ble_att_svr_test.c | 104 +++++++++++++++++++++++
5 files changed, 120 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b296dd4c/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 8437389..05da354 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -103,6 +103,13 @@ ble_att_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
}
void
+ble_att_set_notify_cb(ble_att_svr_notify_fn *cb, void *cb_arg)
+{
+ ble_att_svr_notify_cb = cb;
+ ble_att_svr_notify_cb_arg = cb_arg;
+}
+
+void
ble_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu)
{
if (peer_mtu < BLE_ATT_MTU_DFLT) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b296dd4c/net/nimble/host/src/ble_att_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd.c b/net/nimble/host/src/ble_att_cmd.c
index cae2189..918e452 100644
--- a/net/nimble/host/src/ble_att_cmd.c
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -694,7 +694,7 @@ ble_att_notify_req_write(void *payload, int len,
}
u8ptr = payload;
- u8ptr[0] = BLE_ATT_OP_EXEC_WRITE_RSP;
+ u8ptr[0] = BLE_ATT_OP_NOTIFY_REQ;
htole16(u8ptr + 1, req->banq_handle);
return 0;
@@ -733,7 +733,7 @@ ble_att_indicate_req_write(void *payload, int len,
}
u8ptr = payload;
- u8ptr[0] = BLE_ATT_OP_EXEC_WRITE_RSP;
+ u8ptr[0] = BLE_ATT_OP_INDICATE_REQ;
htole16(u8ptr + 1, req->baiq_handle);
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b296dd4c/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index d9f2eed..3b8d2ff 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -95,6 +95,9 @@ void ble_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu);
struct os_mbuf *ble_att_get_pkthdr(void);
/*** @svr */
+extern ble_att_svr_notify_fn *ble_att_svr_notify_cb;
+extern void *ble_att_svr_notify_cb_arg;
+
int ble_att_svr_find_by_uuid(uint8_t *uuid, struct ble_att_svr_entry **ha_ptr);
uint16_t ble_att_svr_prev_handle(void);
int ble_att_svr_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b296dd4c/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 8c7e985..419191b 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2200,6 +2200,10 @@ ble_att_svr_rx_notify(struct ble_hs_conn *conn,
rc = ble_att_notify_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
assert(rc == 0);
+ if (req.banq_handle == 0) {
+ return BLE_HS_EBADDATA;
+ }
+
os_mbuf_adj(*rxom, BLE_ATT_NOTIFY_REQ_BASE_SZ);
attr_data = ble_att_svr_flat_buf;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b296dd4c/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index c39837e..3d0d8a9 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -38,6 +38,11 @@ static int ble_att_svr_test_attr_w_1_len;
static uint8_t ble_att_svr_test_attr_w_2[1024];
static int ble_att_svr_test_attr_w_2_len;
+static uint16_t ble_att_svr_test_n_conn_handle;
+static uint16_t ble_att_svr_test_n_attr_handle;
+static uint8_t ble_att_svr_test_attr_n[1024];
+static int ble_att_svr_test_attr_n_len;
+
static void
ble_att_svr_test_misc_init(struct ble_hs_conn **conn,
struct ble_l2cap_chan **att_chan)
@@ -720,6 +725,81 @@ ble_att_svr_test_misc_exec_write(struct ble_hs_conn *conn,
}
}
+static void
+ble_att_svr_test_misc_rx_notify(struct ble_hs_conn *conn,
+ struct ble_l2cap_chan *chan,
+ uint16_t attr_handle,
+ void *attr_val, int attr_len, int good)
+{
+ struct ble_att_notify_req req;
+ uint8_t buf[1024];
+ int off;
+ int rc;
+
+ req.banq_handle = attr_handle;
+ rc = ble_att_notify_req_write(buf, sizeof buf, &req);
+ TEST_ASSERT_FATAL(rc == 0);
+ off = BLE_ATT_NOTIFY_REQ_BASE_SZ;
+
+ memcpy(buf + off, attr_val, attr_len);
+ off += attr_len;
+
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off);
+ if (good) {
+ TEST_ASSERT(rc == 0);
+ } else {
+ TEST_ASSERT(rc == BLE_HS_EBADDATA);
+ }
+}
+
+static int
+ble_att_svr_test_misc_notify_cb(uint16_t conn_handle, uint16_t attr_handle,
+ uint8_t *attr_val, uint16_t attr_len,
+ void *arg)
+{
+ int *iarg;
+
+ iarg = arg;
+
+ ble_att_svr_test_n_conn_handle = conn_handle;
+ ble_att_svr_test_n_attr_handle = attr_handle;
+ TEST_ASSERT_FATAL(attr_len <= sizeof ble_att_svr_test_attr_n);
+ ble_att_svr_test_attr_n_len = attr_len;
+ memcpy(ble_att_svr_test_attr_n, attr_val, attr_len);
+
+ return *iarg;
+}
+
+static void
+ble_att_svr_test_misc_verify_notify(struct ble_hs_conn *conn,
+ struct ble_l2cap_chan *chan,
+ uint16_t attr_handle,
+ void *attr_val, int attr_len, int good)
+{
+ int cbrc;
+
+ cbrc = 0;
+ ble_att_set_notify_cb(ble_att_svr_test_misc_notify_cb, &cbrc);
+
+ ble_att_svr_test_n_conn_handle = 0xffff;
+ ble_att_svr_test_n_attr_handle = 0;
+ ble_att_svr_test_attr_n_len = 0;
+
+ ble_att_svr_test_misc_rx_notify(conn, chan, attr_handle, attr_val,
+ attr_len, good);
+
+ if (good) {
+ TEST_ASSERT(ble_att_svr_test_n_conn_handle == conn->bhc_handle);
+ TEST_ASSERT(ble_att_svr_test_n_attr_handle == attr_handle);
+ TEST_ASSERT(ble_att_svr_test_attr_n_len == attr_len);
+ TEST_ASSERT(memcmp(ble_att_svr_test_attr_n, attr_val, attr_len) == 0);
+ } else {
+ TEST_ASSERT(ble_att_svr_test_n_conn_handle == 0xffff);
+ TEST_ASSERT(ble_att_svr_test_n_attr_handle == 0);
+ TEST_ASSERT(ble_att_svr_test_attr_n_len == 0);
+ }
+}
+
TEST_CASE(ble_att_svr_test_mtu)
{
/*** MTU too low; should pretend peer sent default value instead. */
@@ -1664,6 +1744,29 @@ TEST_CASE(ble_att_svr_test_prep_write)
ble_att_svr_test_misc_verify_w_2(data, 61);
}
+TEST_CASE(ble_att_svr_test_notify)
+{
+ struct ble_l2cap_chan *chan;
+ struct ble_hs_conn *conn;
+
+ ble_att_svr_test_misc_init(&conn, &chan);
+
+ /*** Successful notifies; verify callback is executed. */
+ /* 3-length attribute. */
+ ble_att_svr_test_misc_verify_notify(conn, chan, 10,
+ (uint8_t[]) { 1, 2, 3 }, 3, 1);
+ /* 1-length attribute. */
+ ble_att_svr_test_misc_verify_notify(conn, chan, 1,
+ (uint8_t[]) { 0xff }, 1, 1);
+ /* 0-length attribute. */
+ ble_att_svr_test_misc_verify_notify(conn, chan, 43, NULL, 0, 1);
+
+ /*** Bad notifies; verify callback is not executed. */
+ /* Attribute handle of 0. */
+ ble_att_svr_test_misc_verify_notify(conn, chan, 0,
+ (uint8_t[]) { 1, 2, 3 }, 3, 0);
+}
+
TEST_SUITE(ble_att_svr_suite)
{
ble_att_svr_test_mtu();
@@ -1674,6 +1777,7 @@ TEST_SUITE(ble_att_svr_suite)
ble_att_svr_test_read_type();
ble_att_svr_test_read_group_type();
ble_att_svr_test_prep_write();
+ ble_att_svr_test_notify();
}
int