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/12/15 21:43:48 UTC
[2/2] incubator-mynewt-larva git commit: Add basic GATT
characteristic value write tests.
Add basic GATT characteristic value write 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/73db77e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/73db77e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/73db77e6
Branch: refs/heads/master
Commit: 73db77e601c5cf205c5cf13a2cc290cf580fb0c8
Parents: 7d4a560
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Dec 15 12:17:51 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Dec 15 12:43:19 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_gatt.h | 2 +
net/nimble/host/include/host/ble_hs_test.h | 1 +
net/nimble/host/src/ble_gatt.c | 64 +++++-----
net/nimble/host/src/test/ble_gatt_write_test.c | 129 ++++++++++++++++++++
net/nimble/host/src/test/ble_hs_test.c | 1 +
5 files changed, 165 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/73db77e6/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h
index 04f72bd..9b629d4 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -70,6 +70,8 @@ int ble_gatt_read(uint16_t conn_handle, uint16_t attr_handle,
int ble_gatt_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
void *value, uint16_t value_len,
ble_gatt_write_fn *cb, void *cb_arg);
+int ble_gatt_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
+ uint16_t value_len, ble_gatt_write_fn *cb, void *cb_arg);
int ble_gatt_mtu(uint16_t conn_handle);
int ble_gatt_init(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/73db77e6/net/nimble/host/include/host/ble_hs_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_test.h b/net/nimble/host/include/host/ble_hs_test.h
index a931988..60d80d3 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -31,5 +31,6 @@ int ble_hs_uuid_test_all(void);
int ble_gatt_disc_s_test_all(void);
int ble_gatt_disc_c_test_all(void);
int ble_gatt_read_test_all(void);
+int ble_gatt_write_test_all(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/73db77e6/net/nimble/host/src/ble_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatt.c b/net/nimble/host/src/ble_gatt.c
index bd6ecb9..0c52a14 100644
--- a/net/nimble/host/src/ble_gatt.c
+++ b/net/nimble/host/src/ble_gatt.c
@@ -261,25 +261,6 @@ ble_gatt_find(uint16_t conn_handle, uint8_t att_op, int expecting_only,
return NULL;
}
-static struct ble_gatt_entry *
-ble_gatt_find_prev(struct ble_gatt_entry *entry)
-{
- struct ble_gatt_entry *prev;
- struct ble_gatt_entry *cur;
-
- prev = NULL;
- STAILQ_FOREACH(cur, &ble_gatt_list, next) {
- if (cur == entry) {
- return prev;
- }
-
- prev = cur;
- }
-
- assert(0);
- return NULL;
-}
-
static void
ble_gatt_entry_set_pending(struct ble_gatt_entry *entry)
{
@@ -1001,7 +982,6 @@ static int
ble_gatt_kick_write_no_rsp(struct ble_gatt_entry *entry)
{
struct ble_att_write_req req;
- struct ble_gatt_entry *prev;
struct ble_hs_conn *conn;
int rc;
@@ -1018,31 +998,26 @@ ble_gatt_kick_write_no_rsp(struct ble_gatt_entry *entry)
goto err;
}
- /* No response expected; call callback and free entry. */
+ /* No response expected; call callback immediately and return nonzero to
+ * indicate the entry should be freed.
+ */
ble_gatt_write_cb(entry, 0, 0, entry->write.handle);
- prev = ble_gatt_find_prev(entry);
- ble_gatt_entry_remove_free(entry, prev);
-
- return 0;
+ return 1;
err:
ble_gatt_write_cb(entry, rc, 0, entry->write.handle);
return rc;
}
-/*****************************************************************************
- * @write *
- *****************************************************************************/
-
int
-ble_gatt_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
- uint16_t value_len, ble_gatt_write_fn *cb, void *cb_arg)
+ble_gatt_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, void *value,
+ uint16_t value_len, ble_gatt_write_fn *cb, void *cb_arg)
{
struct ble_gatt_entry *entry;
int rc;
- rc = ble_gatt_new_entry(conn_handle, BLE_GATT_OP_WRITE, &entry);
+ rc = ble_gatt_new_entry(conn_handle, BLE_GATT_OP_WRITE_NO_RSP, &entry);
if (rc != 0) {
return rc;
}
@@ -1056,6 +1031,10 @@ ble_gatt_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
return 0;
}
+/*****************************************************************************
+ * @write *
+ *****************************************************************************/
+
static int
ble_gatt_kick_write(struct ble_gatt_entry *entry)
{
@@ -1108,6 +1087,27 @@ ble_gatt_rx_write_rsp(struct ble_hs_conn *conn)
ble_gatt_entry_remove_free(entry, prev);
}
+int
+ble_gatt_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
+ uint16_t value_len, ble_gatt_write_fn *cb, void *cb_arg)
+{
+ struct ble_gatt_entry *entry;
+ int rc;
+
+ rc = ble_gatt_new_entry(conn_handle, BLE_GATT_OP_WRITE, &entry);
+ if (rc != 0) {
+ return rc;
+ }
+
+ entry->write.handle = attr_handle;
+ entry->write.value = value;
+ entry->write.value_len = value_len;
+ entry->write.cb = cb;
+ entry->write.cb_arg = cb_arg;
+
+ return 0;
+}
+
/*****************************************************************************
* @misc *
*****************************************************************************/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/73db77e6/net/nimble/host/src/test/ble_gatt_write_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_write_test.c b/net/nimble/host/src/test/ble_gatt_write_test.c
new file mode 100644
index 0000000..e33b2aa
--- /dev/null
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -0,0 +1,129 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <errno.h>
+#include "testutil/testutil.h"
+#include "nimble/ble.h"
+#include "host/ble_hs_test.h"
+#include "host/ble_gatt.h"
+#include "host/ble_hs_uuid.h"
+#include "ble_hs_priv.h"
+#include "ble_att_cmd.h"
+#include "ble_gatt_priv.h"
+#include "ble_hs_conn.h"
+#include "ble_hs_test_util.h"
+
+static int ble_gatt_write_test_cb_called;
+
+static void
+ble_gatt_write_test_init(void)
+{
+ ble_hs_test_util_init();
+ ble_gatt_write_test_cb_called = 0;
+}
+
+static int
+ble_gatt_write_test_cb(uint16_t conn_handle, uint8_t ble_hs_status,
+ uint8_t att_status, uint16_t attr_handle,
+ void *arg)
+{
+ TEST_ASSERT(conn_handle == 2);
+ TEST_ASSERT(ble_hs_status == 0);
+ TEST_ASSERT(att_status == 0);
+ TEST_ASSERT(attr_handle == 100);
+ TEST_ASSERT(arg == NULL);
+
+ ble_gatt_write_test_cb_called = 1;
+
+ return 0;
+}
+
+static void
+ble_gatt_write_test_rx_rsp(struct ble_hs_conn *conn)
+{
+ struct ble_l2cap_chan *chan;
+ uint8_t op;
+ int rc;
+
+ chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+ TEST_ASSERT_FATAL(chan != NULL);
+
+ op = BLE_ATT_OP_WRITE_RSP;
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, &op, 1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(ble_gatt_write_test_no_rsp)
+{
+ int rc;
+
+ ble_gatt_write_test_init();
+
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+
+ rc = ble_gatt_write_no_rsp(2, 100, ((uint8_t[]){1,2,3,4}), 4,
+ ble_gatt_write_test_cb, NULL);
+ TEST_ASSERT(rc == 0);
+
+ /* Send the pending ATT Write Command. */
+ ble_gatt_wakeup();
+ ble_hs_process_tx_data_queue();
+
+ /* No response expected; verify callback got called. */
+ TEST_ASSERT(ble_gatt_write_test_cb_called);
+}
+
+TEST_CASE(ble_gatt_write_test_rsp)
+{
+ struct ble_hs_conn *conn;
+ int rc;
+
+ ble_gatt_write_test_init();
+
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+
+ rc = ble_gatt_write(2, 100, ((uint8_t[]){1,2,3,4}), 4,
+ ble_gatt_write_test_cb, NULL);
+ TEST_ASSERT(rc == 0);
+
+ /* Send the pending ATT Write Command. */
+ ble_gatt_wakeup();
+ ble_hs_process_tx_data_queue();
+
+ /* Response not received yet; verify callback not called. */
+ TEST_ASSERT(!ble_gatt_write_test_cb_called);
+
+ /* Receive write response. */
+ ble_gatt_write_test_rx_rsp(conn);
+
+ /* Verify callback got called. */
+ TEST_ASSERT(ble_gatt_write_test_cb_called);
+}
+
+TEST_SUITE(gle_gatt_write_test_suite)
+{
+ ble_gatt_write_test_no_rsp();
+ ble_gatt_write_test_rsp();
+}
+
+int
+ble_gatt_write_test_all(void)
+{
+ gle_gatt_write_test_suite();
+
+ return tu_any_failed;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/73db77e6/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
index 61235d8..dfcf0f8 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -50,6 +50,7 @@ main(void)
ble_gatt_disc_s_test_all();
ble_gatt_disc_c_test_all();
ble_gatt_read_test_all();
+ ble_gatt_write_test_all();
return tu_any_failed;
}