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/07/19 18:13:50 UTC
[1/2] incubator-mynewt-core git commit: BLE Host - unit test for rx
GATT long read.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop ab33b2bed -> 1f79ee282
BLE Host - unit test for rx GATT long read.
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/245d516e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/245d516e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/245d516e
Branch: refs/heads/develop
Commit: 245d516e967f313dd28a580197ab1ba215db3f4d
Parents: ab33b2b
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jul 18 15:20:29 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 18 15:20:29 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/test/ble_gatts_read_test.c | 48 ++++++++++++++++++++-
net/nimble/host/src/test/ble_hs_test_util.c | 19 +++++++-
net/nimble/host/src/test/ble_hs_test_util.h | 2 +
3 files changed, 65 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/245d516e/net/nimble/host/src/test/ble_gatts_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_read_test.c b/net/nimble/host/src/test/ble_gatts_read_test.c
index 92c86f4..0f889f9 100644
--- a/net/nimble/host/src/test/ble_gatts_read_test.c
+++ b/net/nimble/host/src/test/ble_gatts_read_test.c
@@ -133,8 +133,10 @@ ble_gatts_read_test_util_access_1(uint16_t conn_handle,
TEST_ASSERT(ctxt->chr ==
&ble_gatts_read_test_svcs[0].characteristics[0]);
- ctxt->att->read.data = ble_gatts_read_test_chr_1_val;
- ctxt->att->read.len = ble_gatts_read_test_chr_1_len;
+ ctxt->att->read.data = ble_gatts_read_test_chr_1_val +
+ ctxt->att->read.offset;
+ ctxt->att->read.len = ble_gatts_read_test_chr_1_len -
+ ctxt->att->read.offset;
return 0;
}
@@ -206,7 +208,49 @@ TEST_CASE(ble_gatts_read_test_case_basic)
}
+TEST_CASE(ble_gatts_read_test_case_long)
+{
+ struct ble_att_read_blob_req read_blob_req;
+ struct ble_att_read_req read_req;
+ uint8_t buf[max(BLE_ATT_READ_REQ_SZ, BLE_ATT_READ_BLOB_REQ_SZ)];
+ uint16_t conn_handle;
+ int rc;
+ int i;
+
+ ble_gatts_read_test_misc_init(&conn_handle);
+
+ /*** Prepare characteristic value. */
+ ble_gatts_read_test_chr_1_len = 40;
+ for (i = 0; i < ble_gatts_read_test_chr_1_len; i++) {
+ ble_gatts_read_test_chr_1_val[i] = i;
+ }
+
+ /* Receive first read request. */
+ read_req.barq_handle = ble_gatts_read_test_chr_1_val_handle;
+ ble_att_read_req_write(buf, sizeof buf, &read_req);
+
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, sizeof buf);
+ TEST_ASSERT(rc == 0);
+
+ ble_hs_test_util_verify_tx_read_rsp(ble_gatts_read_test_chr_1_val, 22);
+
+ /* Receive follow-up read blob request. */
+ read_blob_req.babq_handle = ble_gatts_read_test_chr_1_val_handle;
+ read_blob_req.babq_offset = 22;
+ ble_att_read_blob_req_write(buf, sizeof buf, &read_blob_req);
+
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, sizeof buf);
+ TEST_ASSERT(rc == 0);
+
+ /* Ensure response starts at appropriate offset (22). */
+ ble_hs_test_util_verify_tx_read_blob_rsp(
+ ble_gatts_read_test_chr_1_val + 22, 18);
+}
+
TEST_SUITE(ble_gatts_read_test_suite)
{
ble_gatts_read_test_case_basic();
+ ble_gatts_read_test_case_long();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/245d516e/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index a830449..65b428a 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -927,7 +927,8 @@ ble_hs_test_util_verify_tx_exec_write(uint8_t expected_flags)
}
void
-ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len)
+ble_hs_test_util_verify_tx_read_rsp_gen(uint8_t att_op,
+ uint8_t *attr_data, int attr_len)
{
struct os_mbuf *om;
uint8_t u8;
@@ -940,7 +941,7 @@ ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len)
rc = os_mbuf_copydata(om, 0, 1, &u8);
TEST_ASSERT(rc == 0);
- TEST_ASSERT(u8 == BLE_ATT_OP_READ_RSP);
+ TEST_ASSERT(u8 == att_op);
for (i = 0; i < attr_len; i++) {
rc = os_mbuf_copydata(om, i + 1, 1, &u8);
@@ -953,6 +954,20 @@ ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len)
}
void
+ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len)
+{
+ ble_hs_test_util_verify_tx_read_rsp_gen(BLE_ATT_OP_READ_RSP,
+ attr_data, attr_len);
+}
+
+void
+ble_hs_test_util_verify_tx_read_blob_rsp(uint8_t *attr_data, int attr_len)
+{
+ ble_hs_test_util_verify_tx_read_rsp_gen(BLE_ATT_OP_READ_BLOB_RSP,
+ attr_data, attr_len);
+}
+
+void
ble_hs_test_util_set_static_rnd_addr(void)
{
uint8_t addr[6] = { 1, 2, 3, 4, 5, 0xc1 };
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/245d516e/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index 350f8e5..3b4fe94 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -119,6 +119,8 @@ uint8_t *ble_hs_test_util_verify_tx_hci(uint8_t ogf, uint16_t ocf,
void ble_hs_test_util_tx_all(void);
void ble_hs_test_util_verify_tx_exec_write(uint8_t expected_flags);
void ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len);
+void ble_hs_test_util_verify_tx_read_blob_rsp(uint8_t *attr_data,
+ int attr_len);
void ble_hs_test_util_set_static_rnd_addr(void);
void ble_hs_test_util_init(void);
[2/2] incubator-mynewt-core git commit: blecent - Handle rx notify;
don't disconnect.
Posted by cc...@apache.org.
blecent - Handle rx notify; don't disconnect.
Prior to this change:
1. blecent disconnected immediately after subscribing to
notifications.
2. blecent did not do anything with incoming notifications /
indications.
Now:
1. blecent does not terminate the connection after subscription.
2. blecent logs a message for incoming notifications / indications.
The first change makes sense in light of the second change: if we
disconnect immediately after subscribing (and we don't bond), we will
never receive any notifications!
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/1f79ee28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1f79ee28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1f79ee28
Branch: refs/heads/develop
Commit: 1f79ee28288cdb4d585681c243728fc17a02a1ee
Parents: 245d516
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jul 19 11:10:14 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jul 19 11:10:14 2016 -0700
----------------------------------------------------------------------
apps/blecent/src/main.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1f79ee28/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index f41a313..f4f11f4 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -127,13 +127,6 @@ blecent_on_subscribe(uint16_t conn_handle,
"attr_handle=%d\n",
error->status, conn_handle, attr->handle);
- /* Now that notifications have been enabled, we can terminate the
- * connection.
- */
- BLECENT_LOG(INFO, "Terminating the connection; conn_handle=%d\n",
- conn_handle);
- ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
-
return 0;
}
@@ -146,11 +139,8 @@ blecent_on_subscribe(uint16_t conn_handle,
*
* If the peer does not support a required service, characteristic, or
* descriptor, then the peer lied when it claimed support for the alert
- * notification service! When this happens, or if a GATT procedure fails, this
- * function immediately terminates the connection.
- *
- * When all three procedures have completed, the connection is terminated (this
- * happens in the subscribe callback, not in this function).
+ * notification service! When this happens, or if a GATT procedure fails,
+ * this function immediately terminates the connection.
*/
static void
blecent_read_write_subscribe(const struct peer *peer)
@@ -440,6 +430,20 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
print_conn_desc(&desc);
return 0;
+ case BLE_GAP_EVENT_NOTIFY_RX:
+ /* Peer sent us a notification or indication. */
+ BLECENT_LOG(INFO, "received %s; conn_handle=%d attr_handle=%d "
+ "attr_len=%d\n",
+ event->notify_rx.indication ?
+ "indication" :
+ "notification",
+ event->notify_rx.conn_handle,
+ event->notify_rx.attr_handle,
+ event->notify_rx.attr_len);
+
+ /* Attribute data is contained in event->notify_rx.attr_data. */
+ return 0;
+
default:
return 0;
}