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/05/17 20:51:50 UTC
[27/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Enforce
thread safety in unit tests.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/net/nimble/host/src/test/ble_gatt_find_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_find_s_test.c b/net/nimble/host/src/test/ble_gatt_find_s_test.c
index 6b360c6..9db15ff 100644
--- a/net/nimble/host/src/test/ble_gatt_find_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_find_s_test.c
@@ -63,10 +63,9 @@ ble_gatt_find_s_test_misc_cb(uint16_t conn_handle,
}
static int
ble_gatt_find_s_test_misc_rx_read_type(
- struct ble_hs_conn *conn, struct ble_gatt_find_s_test_entry *entries)
+ uint16_t conn_handle, struct ble_gatt_find_s_test_entry *entries)
{
struct ble_att_read_type_rsp rsp;
- struct ble_l2cap_chan *chan;
uint16_t uuid16;
uint8_t buf[1024];
int off;
@@ -109,36 +108,31 @@ ble_gatt_find_s_test_misc_rx_read_type(
}
if (i == 0) {
- ble_hs_test_util_rx_att_err_rsp(conn, BLE_ATT_OP_READ_TYPE_REQ,
+ ble_hs_test_util_rx_att_err_rsp(conn_handle, BLE_ATT_OP_READ_TYPE_REQ,
BLE_ATT_ERR_ATTR_NOT_FOUND, 0);
return 0;
}
ble_att_read_type_rsp_write(buf + 0, BLE_ATT_READ_TYPE_RSP_BASE_SZ, &rsp);
- chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
- TEST_ASSERT_FATAL(chan != NULL);
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, off);
TEST_ASSERT(rc == 0);
return i;
}
static void
-ble_gatt_find_s_test_misc_rx_read(struct ble_hs_conn *conn, uint8_t *uuid128)
+ble_gatt_find_s_test_misc_rx_read(uint16_t conn_handle, uint8_t *uuid128)
{
- struct ble_l2cap_chan *chan;
uint8_t buf[17];
int rc;
buf[0] = BLE_ATT_OP_READ_RSP;
memcpy(buf + 1, uuid128, 16);
- chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
- TEST_ASSERT_FATAL(chan != NULL);
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, 17);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, 17);
TEST_ASSERT(rc == 0);
}
@@ -182,7 +176,7 @@ ble_gatt_find_s_test_misc_verify_tx_read(uint16_t handle)
}
static void
-ble_gatt_find_s_test_misc_find_inc(struct ble_hs_conn *conn,
+ble_gatt_find_s_test_misc_find_inc(uint16_t conn_handle,
uint16_t start_handle, uint16_t end_handle,
struct ble_gatt_find_s_test_entry *entries)
{
@@ -193,7 +187,7 @@ ble_gatt_find_s_test_misc_find_inc(struct ble_hs_conn *conn,
int rc;
int i;
- rc = ble_gattc_find_inc_svcs(conn->bhc_handle, start_handle, end_handle,
+ rc = ble_gattc_find_inc_svcs(conn_handle, start_handle, end_handle,
ble_gatt_find_s_test_misc_cb, &service);
TEST_ASSERT(rc == 0);
@@ -201,7 +195,7 @@ ble_gatt_find_s_test_misc_find_inc(struct ble_hs_conn *conn,
idx = 0;
while (1) {
ble_gatt_find_s_test_misc_verify_tx_read_type(cur_start, end_handle);
- num_found = ble_gatt_find_s_test_misc_rx_read_type(conn,
+ num_found = ble_gatt_find_s_test_misc_rx_read_type(conn_handle,
entries + idx);
if (num_found == 0) {
break;
@@ -211,7 +205,8 @@ ble_gatt_find_s_test_misc_find_inc(struct ble_hs_conn *conn,
TEST_ASSERT(num_found == 1);
ble_gatt_find_s_test_misc_verify_tx_read(
entries[idx].start_handle);
- ble_gatt_find_s_test_misc_rx_read(conn, entries[idx].uuid128);
+ ble_gatt_find_s_test_misc_rx_read(conn_handle,
+ entries[idx].uuid128);
}
idx += num_found;
@@ -232,13 +227,11 @@ ble_gatt_find_s_test_misc_find_inc(struct ble_hs_conn *conn,
TEST_CASE(ble_gatt_find_s_test_1)
{
- struct ble_hs_conn *conn;
-
/* Two 16-bit UUID services; one response. */
ble_gatt_find_s_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
- ble_gatt_find_s_test_misc_find_inc(conn, 5, 10,
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
+ ble_gatt_find_s_test_misc_find_inc(2, 5, 10,
((struct ble_gatt_find_s_test_entry[]) { {
.inc_handle = 6,
.start_handle = 35,
@@ -256,9 +249,9 @@ TEST_CASE(ble_gatt_find_s_test_1)
/* One 128-bit UUID service; two responses. */
ble_gatt_find_s_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
- ble_gatt_find_s_test_misc_find_inc(conn, 34, 100,
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
+ ble_gatt_find_s_test_misc_find_inc(2, 34, 100,
((struct ble_gatt_find_s_test_entry[]) { {
.inc_handle = 36,
.start_handle = 403,
@@ -271,9 +264,9 @@ TEST_CASE(ble_gatt_find_s_test_1)
/* Two 128-bit UUID service; four responses. */
ble_gatt_find_s_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
- ble_gatt_find_s_test_misc_find_inc(conn, 34, 100,
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
+ ble_gatt_find_s_test_misc_find_inc(2, 34, 100,
((struct ble_gatt_find_s_test_entry[]) { {
.inc_handle = 36,
.start_handle = 403,
@@ -291,9 +284,9 @@ TEST_CASE(ble_gatt_find_s_test_1)
/* Two 16-bit UUID; three 128-bit UUID; seven responses. */
ble_gatt_find_s_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
- ble_gatt_find_s_test_misc_find_inc(conn, 1, 100,
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
+ ble_gatt_find_s_test_misc_find_inc(2, 1, 100,
((struct ble_gatt_find_s_test_entry[]) { {
.inc_handle = 36,
.start_handle = 403,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/net/nimble/host/src/test/ble_gatt_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_read_test.c b/net/nimble/host/src/test/ble_gatt_read_test.c
index edf7d63..03df56e 100644
--- a/net/nimble/host/src/test/ble_gatt_read_test.c
+++ b/net/nimble/host/src/test/ble_gatt_read_test.c
@@ -149,11 +149,10 @@ ble_gatt_read_test_long_cb(uint16_t conn_handle, struct ble_gatt_error *error,
}
static void
-ble_gatt_read_test_misc_rx_rsp_good_raw(struct ble_hs_conn *conn,
+ble_gatt_read_test_misc_rx_rsp_good_raw(uint16_t conn_handle,
uint8_t att_op,
void *data, int data_len)
{
- struct ble_l2cap_chan *chan;
uint8_t buf[1024];
int rc;
@@ -165,40 +164,36 @@ ble_gatt_read_test_misc_rx_rsp_good_raw(struct ble_hs_conn *conn,
buf[0] = att_op;
memcpy(buf + 1, data, data_len);
- chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
- TEST_ASSERT_FATAL(chan != NULL);
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf,
- 1 + data_len);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, 1 + data_len);
TEST_ASSERT(rc == 0);
}
static void
-ble_gatt_read_test_misc_rx_rsp_good(struct ble_hs_conn *conn,
+ble_gatt_read_test_misc_rx_rsp_good(uint16_t conn_handle,
struct ble_gatt_attr *attr)
{
- ble_gatt_read_test_misc_rx_rsp_good_raw(conn, BLE_ATT_OP_READ_RSP,
+ ble_gatt_read_test_misc_rx_rsp_good_raw(conn_handle, BLE_ATT_OP_READ_RSP,
attr->value,
attr->value_len);
}
static void
-ble_gatt_read_test_misc_rx_rsp_bad(struct ble_hs_conn *conn,
+ble_gatt_read_test_misc_rx_rsp_bad(uint16_t conn_handle,
uint8_t att_error, uint16_t err_handle)
{
/* Send the pending ATT Read Request. */
ble_hs_test_util_tx_all();
- ble_hs_test_util_rx_att_err_rsp(conn, BLE_ATT_OP_READ_REQ, att_error,
- err_handle);
+ ble_hs_test_util_rx_att_err_rsp(conn_handle, BLE_ATT_OP_READ_REQ,
+ att_error, err_handle);
}
static int
-ble_gatt_read_test_misc_uuid_rx_rsp_good(struct ble_hs_conn *conn,
+ble_gatt_read_test_misc_uuid_rx_rsp_good(uint16_t conn_handle,
struct ble_gatt_attr *attrs)
{
struct ble_att_read_type_rsp rsp;
- struct ble_l2cap_chan *chan;
uint8_t buf[1024];
int prev_len;
int off;
@@ -230,10 +225,8 @@ ble_gatt_read_test_misc_uuid_rx_rsp_good(struct ble_hs_conn *conn,
off += attrs[i].value_len;
}
- chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
- TEST_ASSERT_FATAL(chan != NULL);
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, off);
TEST_ASSERT(rc == 0);
return i;
@@ -242,21 +235,19 @@ ble_gatt_read_test_misc_uuid_rx_rsp_good(struct ble_hs_conn *conn,
static void
ble_gatt_read_test_misc_verify_good(struct ble_gatt_attr *attr)
{
- struct ble_hs_conn *conn;
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
- rc = ble_gattc_read(conn->bhc_handle, attr->handle, ble_gatt_read_test_cb,
- NULL);
+ rc = ble_gattc_read(2, attr->handle, ble_gatt_read_test_cb, NULL);
TEST_ASSERT_FATAL(rc == 0);
- ble_gatt_read_test_misc_rx_rsp_good(conn, attr);
+ ble_gatt_read_test_misc_rx_rsp_good(2, attr);
TEST_ASSERT(ble_gatt_read_test_num_attrs == 1);
- TEST_ASSERT(ble_gatt_read_test_attrs[0].conn_handle == conn->bhc_handle);
+ TEST_ASSERT(ble_gatt_read_test_attrs[0].conn_handle == 2);
TEST_ASSERT(ble_gatt_read_test_attrs[0].handle == attr->handle);
TEST_ASSERT(ble_gatt_read_test_attrs[0].value_len == attr->value_len);
TEST_ASSERT(memcmp(ble_gatt_read_test_attrs[0].value, attr->value,
@@ -267,21 +258,19 @@ static void
ble_gatt_read_test_misc_verify_bad(uint8_t att_status,
struct ble_gatt_attr *attr)
{
- struct ble_hs_conn *conn;
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
- rc = ble_gattc_read(conn->bhc_handle, attr->handle, ble_gatt_read_test_cb,
- NULL);
+ rc = ble_gattc_read(2, attr->handle, ble_gatt_read_test_cb, NULL);
TEST_ASSERT_FATAL(rc == 0);
- ble_gatt_read_test_misc_rx_rsp_bad(conn, att_status, attr->handle);
+ ble_gatt_read_test_misc_rx_rsp_bad(2, att_status, attr->handle);
TEST_ASSERT(ble_gatt_read_test_num_attrs == 0);
- TEST_ASSERT(ble_gatt_read_test_bad_conn_handle == conn->bhc_handle);
+ TEST_ASSERT(ble_gatt_read_test_bad_conn_handle == 2);
TEST_ASSERT(ble_gatt_read_test_bad_status ==
BLE_HS_ERR_ATT_BASE + att_status);
TEST_ASSERT(!ble_gattc_any_jobs());
@@ -293,26 +282,25 @@ ble_gatt_read_test_misc_uuid_verify_good(uint16_t start_handle,
int stop_after,
struct ble_gatt_attr *attrs)
{
- struct ble_hs_conn *conn;
int num_read;
int idx;
int rc;
int i;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
- rc = ble_gattc_read_by_uuid(conn->bhc_handle, start_handle, end_handle,
- uuid128, ble_gatt_read_test_cb, &stop_after);
+ rc = ble_gattc_read_by_uuid(2, start_handle, end_handle, uuid128,
+ ble_gatt_read_test_cb, &stop_after);
TEST_ASSERT_FATAL(rc == 0);
idx = 0;
while (1) {
- num_read = ble_gatt_read_test_misc_uuid_rx_rsp_good(conn, attrs + idx);
+ num_read = ble_gatt_read_test_misc_uuid_rx_rsp_good(2, attrs + idx);
if (num_read == 0) {
ble_hs_test_util_tx_all();
- ble_hs_test_util_rx_att_err_rsp(conn, BLE_ATT_OP_READ_TYPE_REQ,
+ ble_hs_test_util_rx_att_err_rsp(2, BLE_ATT_OP_READ_TYPE_REQ,
BLE_ATT_ERR_ATTR_NOT_FOUND,
start_handle);
break;
@@ -325,8 +313,7 @@ ble_gatt_read_test_misc_uuid_verify_good(uint16_t start_handle,
TEST_ASSERT(idx == ble_gatt_read_test_num_attrs);
for (i = 0; i < idx; i++) {
- TEST_ASSERT(ble_gatt_read_test_attrs[i].conn_handle ==
- conn->bhc_handle);
+ TEST_ASSERT(ble_gatt_read_test_attrs[i].conn_handle == 2);
TEST_ASSERT(ble_gatt_read_test_attrs[i].handle == attrs[i].handle);
TEST_ASSERT(ble_gatt_read_test_attrs[i].value_len ==
attrs[i].value_len);
@@ -340,7 +327,6 @@ static void
ble_gatt_read_test_misc_long_verify_good(int max_reads,
struct ble_gatt_attr *attr)
{
- struct ble_hs_conn *conn;
int reads_left;
int chunk_sz;
int rem_len;
@@ -349,15 +335,15 @@ ble_gatt_read_test_misc_long_verify_good(int max_reads,
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
if (max_reads == 0) {
max_reads = INT_MAX;
}
reads_left = max_reads;
- rc = ble_gattc_read_long(conn->bhc_handle, attr->handle,
- ble_gatt_read_test_long_cb, &reads_left);
+ rc = ble_gattc_read_long(2, attr->handle, ble_gatt_read_test_long_cb,
+ &reads_left);
TEST_ASSERT_FATAL(rc == 0);
off = 0;
@@ -373,7 +359,7 @@ ble_gatt_read_test_misc_long_verify_good(int max_reads,
} else {
att_op = BLE_ATT_OP_READ_BLOB_RSP;
}
- ble_gatt_read_test_misc_rx_rsp_good_raw(conn, att_op,
+ ble_gatt_read_test_misc_rx_rsp_good_raw(2, att_op,
attr->value + off, chunk_sz);
rem_len -= chunk_sz;
off += chunk_sz;
@@ -381,7 +367,7 @@ ble_gatt_read_test_misc_long_verify_good(int max_reads,
TEST_ASSERT(ble_gatt_read_test_complete);
TEST_ASSERT(!ble_gattc_any_jobs());
- TEST_ASSERT(ble_gatt_read_test_attrs[0].conn_handle == conn->bhc_handle);
+ TEST_ASSERT(ble_gatt_read_test_attrs[0].conn_handle == 2);
TEST_ASSERT(ble_gatt_read_test_attrs[0].handle == attr->handle);
if (reads_left > 0) {
TEST_ASSERT(ble_gatt_read_test_attrs[0].value_len == attr->value_len);
@@ -394,21 +380,20 @@ static void
ble_gatt_read_test_misc_long_verify_bad(uint8_t att_status,
struct ble_gatt_attr *attr)
{
- struct ble_hs_conn *conn;
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
- rc = ble_gattc_read_long(conn->bhc_handle, attr->handle,
+ rc = ble_gattc_read_long(2, attr->handle,
ble_gatt_read_test_long_cb, NULL);
TEST_ASSERT_FATAL(rc == 0);
- ble_gatt_read_test_misc_rx_rsp_bad(conn, att_status, attr->handle);
+ ble_gatt_read_test_misc_rx_rsp_bad(2, att_status, attr->handle);
TEST_ASSERT(ble_gatt_read_test_num_attrs == 0);
- TEST_ASSERT(ble_gatt_read_test_bad_conn_handle == conn->bhc_handle);
+ TEST_ASSERT(ble_gatt_read_test_bad_conn_handle == 2);
TEST_ASSERT(ble_gatt_read_test_bad_status ==
BLE_HS_ERR_ATT_BASE + att_status);
TEST_ASSERT(!ble_gattc_any_jobs());
@@ -430,7 +415,6 @@ static void
ble_gatt_read_test_misc_mult_verify_good(struct ble_gatt_attr *attrs)
{
uint8_t expected_value[512];
- struct ble_hs_conn *conn;
uint16_t handles[256];
int num_attrs;
int chunk_sz;
@@ -439,8 +423,8 @@ ble_gatt_read_test_misc_mult_verify_good(struct ble_gatt_attr *attrs)
int i;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
num_attrs = ble_gatt_read_test_misc_extract_handles(attrs, handles);
@@ -458,16 +442,16 @@ ble_gatt_read_test_misc_mult_verify_good(struct ble_gatt_attr *attrs)
}
}
- rc = ble_gattc_read_mult(conn->bhc_handle, handles, num_attrs,
+ rc = ble_gattc_read_mult(2, handles, num_attrs,
ble_gatt_read_test_cb, NULL);
TEST_ASSERT_FATAL(rc == 0);
- ble_gatt_read_test_misc_rx_rsp_good_raw(conn, BLE_ATT_OP_READ_MULT_RSP,
+ ble_gatt_read_test_misc_rx_rsp_good_raw(2, BLE_ATT_OP_READ_MULT_RSP,
expected_value, off);
TEST_ASSERT(ble_gatt_read_test_complete);
TEST_ASSERT(!ble_gattc_any_jobs());
- TEST_ASSERT(ble_gatt_read_test_attrs[0].conn_handle == conn->bhc_handle);
+ TEST_ASSERT(ble_gatt_read_test_attrs[0].conn_handle == 2);
TEST_ASSERT(ble_gatt_read_test_attrs[0].value_len == off);
TEST_ASSERT(memcmp(ble_gatt_read_test_attrs[0].value, expected_value,
off) == 0);
@@ -478,25 +462,24 @@ ble_gatt_read_test_misc_mult_verify_bad(uint8_t att_status,
uint16_t err_handle,
struct ble_gatt_attr *attrs)
{
- struct ble_hs_conn *conn;
uint16_t handles[256];
int num_attrs;
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
num_attrs = ble_gatt_read_test_misc_extract_handles(attrs, handles);
- rc = ble_gattc_read_mult(conn->bhc_handle, handles, num_attrs,
+ rc = ble_gattc_read_mult(2, handles, num_attrs,
ble_gatt_read_test_cb, NULL);
TEST_ASSERT_FATAL(rc == 0);
- ble_gatt_read_test_misc_rx_rsp_bad(conn, att_status, err_handle);
+ ble_gatt_read_test_misc_rx_rsp_bad(2, att_status, err_handle);
TEST_ASSERT(ble_gatt_read_test_num_attrs == 0);
- TEST_ASSERT(ble_gatt_read_test_bad_conn_handle == conn->bhc_handle);
+ TEST_ASSERT(ble_gatt_read_test_bad_conn_handle == 2);
TEST_ASSERT(ble_gatt_read_test_bad_status ==
BLE_HS_ERR_ATT_BASE + att_status);
TEST_ASSERT(!ble_gattc_any_jobs());
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/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
index b452e79..f12ea77 100644
--- a/net/nimble/host/src/test/ble_gatt_write_test.c
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -74,33 +74,26 @@ ble_gatt_write_test_cb_good(uint16_t conn_handle, struct ble_gatt_error *error,
}
static void
-ble_gatt_write_test_rx_rsp(struct ble_hs_conn *conn)
+ble_gatt_write_test_rx_rsp(uint16_t conn_handle)
{
- 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);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ &op, 1);
TEST_ASSERT(rc == 0);
}
static void
-ble_gatt_write_test_rx_prep_rsp(struct ble_hs_conn *conn, uint16_t attr_handle,
+ble_gatt_write_test_rx_prep_rsp(uint16_t conn_handle, uint16_t attr_handle,
uint16_t offset,
void *attr_data, uint16_t attr_data_len)
{
struct ble_att_prep_write_cmd rsp;
- struct ble_l2cap_chan *chan;
uint8_t buf[512];
int rc;
- chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
- TEST_ASSERT_FATAL(chan != NULL);
-
rsp.bapc_handle = attr_handle;
rsp.bapc_offset = offset;
ble_att_prep_write_rsp_write(buf, sizeof buf, &rsp);
@@ -108,40 +101,36 @@ ble_gatt_write_test_rx_prep_rsp(struct ble_hs_conn *conn, uint16_t attr_handle,
memcpy(buf + BLE_ATT_PREP_WRITE_CMD_BASE_SZ, attr_data, attr_data_len);
rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn, chan, buf, BLE_ATT_PREP_WRITE_CMD_BASE_SZ + attr_data_len);
+ conn_handle, BLE_L2CAP_CID_ATT, buf,
+ BLE_ATT_PREP_WRITE_CMD_BASE_SZ + attr_data_len);
TEST_ASSERT(rc == 0);
}
static void
-ble_gatt_write_test_rx_exec_rsp(struct ble_hs_conn *conn)
+ble_gatt_write_test_rx_exec_rsp(uint16_t conn_handle)
{
- 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_EXEC_WRITE_RSP;
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, &op, 1);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ &op, 1);
TEST_ASSERT(rc == 0);
}
static void
ble_gatt_write_test_misc_long_good(int attr_len)
{
- struct ble_hs_conn *conn;
int off;
int len;
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}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
- rc = ble_gattc_write_long(conn->bhc_handle, 100,
- ble_gatt_write_test_attr_value,
+ rc = ble_gattc_write_long(2, 100, ble_gatt_write_test_attr_value,
attr_len, ble_gatt_write_test_cb_good,
&attr_len);
TEST_ASSERT(rc == 0);
@@ -156,7 +145,7 @@ ble_gatt_write_test_misc_long_good(int attr_len)
if (off + len > attr_len) {
len = attr_len - off;
}
- ble_gatt_write_test_rx_prep_rsp(conn, 100, off,
+ ble_gatt_write_test_rx_prep_rsp(2, 100, off,
ble_gatt_write_test_attr_value + off,
len);
@@ -168,20 +157,19 @@ ble_gatt_write_test_misc_long_good(int attr_len)
/* Receive Exec Write response. */
ble_hs_test_util_tx_all();
- ble_gatt_write_test_rx_exec_rsp(conn);
+ ble_gatt_write_test_rx_exec_rsp(2);
/* Verify callback got called. */
TEST_ASSERT(ble_gatt_write_test_cb_called);
}
-typedef void ble_gatt_write_test_long_fail_fn(struct ble_hs_conn *conn,
+typedef void ble_gatt_write_test_long_fail_fn(uint16_t conn_handle,
int off, int len);
static void
ble_gatt_write_test_misc_long_bad(int attr_len,
ble_gatt_write_test_long_fail_fn *cb)
{
- struct ble_hs_conn *conn;
int fail_now;
int off;
int len;
@@ -189,11 +177,10 @@ ble_gatt_write_test_misc_long_bad(int attr_len,
ble_gatt_write_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
- rc = ble_gattc_write_long(conn->bhc_handle, 100,
- ble_gatt_write_test_attr_value,
+ rc = ble_gattc_write_long(2, 100, ble_gatt_write_test_attr_value,
attr_len, ble_gatt_write_test_cb_good, NULL);
TEST_ASSERT(rc == 0);
@@ -211,10 +198,9 @@ ble_gatt_write_test_misc_long_bad(int attr_len,
}
if (!fail_now) {
ble_gatt_write_test_rx_prep_rsp(
- conn, 100, off, ble_gatt_write_test_attr_value + off,
- len);
+ 2, 100, off, ble_gatt_write_test_attr_value + off, len);
} else {
- cb(conn, off, len);
+ cb(2, off, len);
break;
}
@@ -231,38 +217,38 @@ ble_gatt_write_test_misc_long_bad(int attr_len,
}
static void
-ble_gatt_write_test_misc_long_fail_handle(struct ble_hs_conn *conn,
+ble_gatt_write_test_misc_long_fail_handle(uint16_t conn_handle,
int off, int len)
{
ble_gatt_write_test_rx_prep_rsp(
- conn, 99, off, ble_gatt_write_test_attr_value + off,
+ conn_handle, 99, off, ble_gatt_write_test_attr_value + off,
len);
}
static void
-ble_gatt_write_test_misc_long_fail_offset(struct ble_hs_conn *conn,
+ble_gatt_write_test_misc_long_fail_offset(uint16_t conn_handle,
int off, int len)
{
ble_gatt_write_test_rx_prep_rsp(
- conn, 100, off + 1, ble_gatt_write_test_attr_value + off,
+ conn_handle, 100, off + 1, ble_gatt_write_test_attr_value + off,
len);
}
static void
-ble_gatt_write_test_misc_long_fail_value(struct ble_hs_conn *conn,
+ble_gatt_write_test_misc_long_fail_value(uint16_t conn_handle,
int off, int len)
{
ble_gatt_write_test_rx_prep_rsp(
- conn, 100, off, ble_gatt_write_test_attr_value + off + 1,
+ conn_handle, 100, off, ble_gatt_write_test_attr_value + off + 1,
len);
}
static void
-ble_gatt_write_test_misc_long_fail_length(struct ble_hs_conn *conn,
+ble_gatt_write_test_misc_long_fail_length(uint16_t conn_handle,
int off, int len)
{
ble_gatt_write_test_rx_prep_rsp(
- conn, 100, off, ble_gatt_write_test_attr_value + off,
+ conn_handle, 100, off, ble_gatt_write_test_attr_value + off,
len - 1);
}
@@ -291,7 +277,6 @@ ble_gatt_write_test_reliable_cb_good(uint16_t conn_handle,
static void
ble_gatt_write_test_misc_reliable_good(struct ble_gatt_attr *attrs)
{
- struct ble_hs_conn *conn;
int num_attrs;
int attr_idx;
int rc;
@@ -302,10 +287,10 @@ ble_gatt_write_test_misc_reliable_good(struct ble_gatt_attr *attrs)
for (num_attrs = 0; attrs[num_attrs].handle != 0; num_attrs++)
;
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
- rc = ble_gattc_write_reliable(conn->bhc_handle, attrs, num_attrs,
+ rc = ble_gattc_write_reliable(2, attrs, num_attrs,
ble_gatt_write_test_reliable_cb_good, NULL);
TEST_ASSERT(rc == 0);
@@ -314,7 +299,7 @@ ble_gatt_write_test_misc_reliable_good(struct ble_gatt_attr *attrs)
ble_hs_test_util_tx_all();
/* Receive Prep Write response. */
- ble_gatt_write_test_rx_prep_rsp(conn, attrs[attr_idx].handle, 0,
+ ble_gatt_write_test_rx_prep_rsp(2, attrs[attr_idx].handle, 0,
attrs[attr_idx].value,
attrs[attr_idx].value_len);
@@ -324,7 +309,7 @@ ble_gatt_write_test_misc_reliable_good(struct ble_gatt_attr *attrs)
/* Receive Exec Write response. */
ble_hs_test_util_tx_all();
- ble_gatt_write_test_rx_exec_rsp(conn);
+ ble_gatt_write_test_rx_exec_rsp(2);
/* Verify callback got called. */
TEST_ASSERT(ble_gatt_write_test_cb_called);
@@ -342,7 +327,7 @@ TEST_CASE(ble_gatt_write_test_no_rsp)
ble_gatt_write_test_init();
ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ NULL, NULL);
attr_len = 4;
rc = ble_gattc_write_no_rsp(2, 100, ble_gatt_write_test_attr_value,
@@ -358,13 +343,12 @@ TEST_CASE(ble_gatt_write_test_no_rsp)
TEST_CASE(ble_gatt_write_test_rsp)
{
- struct ble_hs_conn *conn;
int attr_len;
ble_gatt_write_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
- NULL, NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
attr_len = 4;
ble_gattc_write(2, 100, ble_gatt_write_test_attr_value, attr_len,
@@ -377,7 +361,7 @@ TEST_CASE(ble_gatt_write_test_rsp)
TEST_ASSERT(!ble_gatt_write_test_cb_called);
/* Receive write response. */
- ble_gatt_write_test_rx_rsp(conn);
+ ble_gatt_write_test_rx_rsp(2);
/* Verify callback got called. */
TEST_ASSERT(ble_gatt_write_test_cb_called);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/net/nimble/host/src/test/ble_gatts_notify_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_notify_test.c b/net/nimble/host/src/test/ble_gatts_notify_test.c
index b0e079b..526e6d6 100644
--- a/net/nimble/host/src/test/ble_gatts_notify_test.c
+++ b/net/nimble/host/src/test/ble_gatts_notify_test.c
@@ -67,8 +67,7 @@ static uint8_t ble_gatts_notify_test_chr_2_val[1024];
static int ble_gatts_notify_test_chr_2_len;
static void
-ble_gatts_notify_test_misc_init(struct ble_hs_conn **conn,
- struct ble_l2cap_chan **att_chan)
+ble_gatts_notify_test_misc_init(uint16_t *out_conn_handle)
{
int rc;
@@ -84,16 +83,11 @@ ble_gatts_notify_test_misc_init(struct ble_hs_conn **conn,
ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
NULL, NULL);
- *conn = ble_hs_conn_find(2);
- TEST_ASSERT_FATAL(*conn != NULL);
-
- *att_chan = ble_hs_conn_chan_find(*conn, BLE_L2CAP_CID_ATT);
- TEST_ASSERT_FATAL(*att_chan != NULL);
+ *out_conn_handle = 2;
}
static void
-ble_gatts_notify_test_misc_enable_notify(struct ble_hs_conn *conn,
- struct ble_l2cap_chan *chan,
+ble_gatts_notify_test_misc_enable_notify(uint16_t conn_handle,
uint16_t chr_def_handle,
uint16_t flags)
{
@@ -105,7 +99,8 @@ ble_gatts_notify_test_misc_enable_notify(struct ble_hs_conn *conn,
ble_att_write_req_write(buf, sizeof buf, &req);
htole16(buf + BLE_ATT_WRITE_REQ_BASE_SZ, flags);
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, sizeof buf);
TEST_ASSERT(rc == 0);
}
@@ -161,22 +156,21 @@ ble_gatts_notify_test_misc_access(uint16_t conn_handle,
}
static void
-ble_gatts_notify_test_misc_rx_indicate_rsp(struct ble_hs_conn *conn,
- struct ble_l2cap_chan *chan)
+ble_gatts_notify_test_misc_rx_indicate_rsp(uint16_t conn_handle)
{
uint8_t buf[BLE_ATT_INDICATE_RSP_SZ];
int rc;
ble_att_indicate_rsp_write(buf, sizeof buf);
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, sizeof buf);
TEST_ASSERT(rc == 0);
}
static void
-ble_gatts_notify_test_misc_verify_tx_n(struct ble_l2cap_chan *chan,
- uint8_t *attr_data, int attr_len)
+ble_gatts_notify_test_misc_verify_tx_n(uint8_t *attr_data, int attr_len)
{
struct ble_att_notify_req req;
struct os_mbuf *om;
@@ -196,8 +190,7 @@ ble_gatts_notify_test_misc_verify_tx_n(struct ble_l2cap_chan *chan,
}
static void
-ble_gatts_notify_test_misc_verify_tx_i(struct ble_l2cap_chan *chan,
- uint8_t *attr_data, int attr_len)
+ble_gatts_notify_test_misc_verify_tx_i(uint8_t *attr_data, int attr_len)
{
struct ble_att_indicate_req req;
struct os_mbuf *om;
@@ -218,17 +211,16 @@ ble_gatts_notify_test_misc_verify_tx_i(struct ble_l2cap_chan *chan,
TEST_CASE(ble_gatts_notify_test_n)
{
- struct ble_l2cap_chan *chan;
- struct ble_hs_conn *conn;
+ uint16_t conn_handle;
- ble_gatts_notify_test_misc_init(&conn, &chan);
+ ble_gatts_notify_test_misc_init(&conn_handle);
/* Enable notifications on both characteristics. */
ble_gatts_notify_test_misc_enable_notify(
- conn, chan, ble_gatts_notify_test_chr_1_def_handle,
+ conn_handle, ble_gatts_notify_test_chr_1_def_handle,
BLE_GATTS_CLT_CFG_F_NOTIFY);
ble_gatts_notify_test_misc_enable_notify(
- conn, chan, ble_gatts_notify_test_chr_2_def_handle,
+ conn_handle, ble_gatts_notify_test_chr_2_def_handle,
BLE_GATTS_CLT_CFG_F_NOTIFY);
/* Update characteristic 1's value. */
@@ -237,8 +229,7 @@ TEST_CASE(ble_gatts_notify_test_n)
ble_gatts_chr_updated(ble_gatts_notify_test_chr_1_def_handle);
/* Verify notification sent properly. */
- ble_gatts_notify_test_misc_verify_tx_n(chan,
- ble_gatts_notify_test_chr_1_val,
+ ble_gatts_notify_test_misc_verify_tx_n(ble_gatts_notify_test_chr_1_val,
ble_gatts_notify_test_chr_1_len);
/* Update characteristic 2's value. */
@@ -248,24 +239,22 @@ TEST_CASE(ble_gatts_notify_test_n)
ble_gatts_chr_updated(ble_gatts_notify_test_chr_2_def_handle);
/* Verify notification sent properly. */
- ble_gatts_notify_test_misc_verify_tx_n(chan,
- ble_gatts_notify_test_chr_2_val,
+ ble_gatts_notify_test_misc_verify_tx_n(ble_gatts_notify_test_chr_2_val,
ble_gatts_notify_test_chr_2_len);
}
TEST_CASE(ble_gatts_notify_test_i)
{
- struct ble_l2cap_chan *chan;
- struct ble_hs_conn *conn;
+ uint16_t conn_handle;
- ble_gatts_notify_test_misc_init(&conn, &chan);
+ ble_gatts_notify_test_misc_init(&conn_handle);
/* Enable indications on both characteristics. */
ble_gatts_notify_test_misc_enable_notify(
- conn, chan, ble_gatts_notify_test_chr_1_def_handle,
+ conn_handle, ble_gatts_notify_test_chr_1_def_handle,
BLE_GATTS_CLT_CFG_F_INDICATE);
ble_gatts_notify_test_misc_enable_notify(
- conn, chan, ble_gatts_notify_test_chr_2_def_handle,
+ conn_handle, ble_gatts_notify_test_chr_2_def_handle,
BLE_GATTS_CLT_CFG_F_INDICATE);
/* Toss both write responses. */
@@ -279,10 +268,8 @@ TEST_CASE(ble_gatts_notify_test_i)
ble_gatts_chr_updated(ble_gatts_notify_test_chr_1_def_handle);
/* Verify indication sent properly. */
- ble_gatts_notify_test_misc_verify_tx_i(
- chan,
- ble_gatts_notify_test_chr_1_val,
- ble_gatts_notify_test_chr_1_len);
+ ble_gatts_notify_test_misc_verify_tx_i(ble_gatts_notify_test_chr_1_val,
+ ble_gatts_notify_test_chr_1_len);
/* Update characteristic 2's value. */
ble_gatts_notify_test_chr_2_len = 16;
@@ -297,17 +284,15 @@ TEST_CASE(ble_gatts_notify_test_i)
TEST_ASSERT(ble_hs_test_util_prev_tx_queue_sz() == 0);
/* Receive the confirmation for the first indication. */
- ble_gatts_notify_test_misc_rx_indicate_rsp(conn, chan);
+ ble_gatts_notify_test_misc_rx_indicate_rsp(conn_handle);
/* Verify indication sent properly. */
ble_hs_test_util_tx_all();
- ble_gatts_notify_test_misc_verify_tx_i(
- chan,
- ble_gatts_notify_test_chr_2_val,
- ble_gatts_notify_test_chr_2_len);
+ ble_gatts_notify_test_misc_verify_tx_i(ble_gatts_notify_test_chr_2_val,
+ ble_gatts_notify_test_chr_2_len);
/* Receive the confirmation for the second indication. */
- ble_gatts_notify_test_misc_rx_indicate_rsp(conn, chan);
+ ble_gatts_notify_test_misc_rx_indicate_rsp(conn_handle);
/* Verify no pending GATT jobs. */
TEST_ASSERT(!ble_gattc_any_jobs());
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index fa23c18..c56efe0 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -26,6 +26,18 @@
#include "host/host_hci.h"
#include "ble_hs_test_util.h"
+static int
+ble_hs_conn_test_util_any()
+{
+ struct ble_hs_conn *conn;
+
+ ble_hs_lock();
+ conn = ble_hs_conn_first();
+ ble_hs_unlock();
+
+ return conn != NULL;
+}
+
TEST_CASE(ble_hs_conn_test_direct_connect_success)
{
struct hci_le_conn_complete evt;
@@ -38,7 +50,7 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
/* Ensure no current or pending connections. */
TEST_ASSERT(!ble_gap_master_in_progress());
- TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_hs_conn_test_util_any());
/* Initiate connection. */
rc = ble_hs_test_util_conn_initiate(0, addr, NULL, NULL, NULL, 0);
@@ -57,6 +69,8 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
TEST_ASSERT(rc == 0);
TEST_ASSERT(!ble_gap_master_in_progress());
+ ble_hs_lock();
+
conn = ble_hs_conn_first();
TEST_ASSERT_FATAL(conn != NULL);
TEST_ASSERT(conn->bhc_handle == 2);
@@ -67,6 +81,8 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
TEST_ASSERT(chan->blc_my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
TEST_ASSERT(chan->blc_peer_mtu == 0);
TEST_ASSERT(chan->blc_default_mtu == BLE_ATT_MTU_DFLT);
+
+ ble_hs_unlock();
}
TEST_CASE(ble_hs_conn_test_direct_connect_hci_errors)
@@ -78,14 +94,14 @@ TEST_CASE(ble_hs_conn_test_direct_connect_hci_errors)
/* Ensure no current or pending connections. */
TEST_ASSERT(!ble_gap_master_in_progress());
- TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_hs_conn_test_util_any());
/* Initiate connection; receive no HCI ack. */
rc = ble_gap_conn_initiate(0, addr, NULL, NULL, NULL);
TEST_ASSERT(rc == BLE_HS_ETIMEOUT);
TEST_ASSERT(!ble_gap_master_in_progress());
- TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_hs_conn_test_util_any());
}
TEST_CASE(ble_hs_conn_test_direct_connectable_success)
@@ -101,7 +117,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
/* Ensure no current or pending connections. */
TEST_ASSERT(!ble_gap_master_in_progress());
TEST_ASSERT(!ble_gap_slave_in_progress());
- TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_hs_conn_test_util_any());
/* Initiate advertising. */
rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_NON,
@@ -125,6 +141,8 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
TEST_ASSERT(!ble_gap_master_in_progress());
TEST_ASSERT(!ble_gap_slave_in_progress());
+ ble_hs_lock();
+
conn = ble_hs_conn_first();
TEST_ASSERT_FATAL(conn != NULL);
TEST_ASSERT(conn->bhc_handle == 2);
@@ -135,6 +153,8 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
TEST_ASSERT(chan->blc_my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
TEST_ASSERT(chan->blc_peer_mtu == 0);
TEST_ASSERT(chan->blc_default_mtu == BLE_ATT_MTU_DFLT);
+
+ ble_hs_unlock();
}
TEST_CASE(ble_hs_conn_test_direct_connectable_hci_errors)
@@ -145,9 +165,9 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_hci_errors)
ble_hs_test_util_init();
- /* Ensure no current or pending connections. */
+ /* Ensure no current or pending connections. */
TEST_ASSERT(!ble_gap_slave_in_progress());
- TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_hs_conn_test_util_any());
/* Initiate connection. */
rc = ble_hs_test_util_adv_start(BLE_GAP_DISC_MODE_NON,
@@ -162,7 +182,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_hci_errors)
rc = ble_gap_rx_conn_complete(&evt);
TEST_ASSERT(rc == 0);
TEST_ASSERT(ble_gap_slave_in_progress());
- TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_hs_conn_test_util_any());
}
TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
@@ -179,7 +199,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
/* Ensure no current or pending connections. */
TEST_ASSERT(!ble_gap_master_in_progress());
TEST_ASSERT(!ble_gap_slave_in_progress());
- TEST_ASSERT(ble_hs_conn_first() == NULL);
+ TEST_ASSERT(!ble_hs_conn_test_util_any());
/* Initiate advertising. */
memset(&adv_fields, 0, sizeof adv_fields);
@@ -207,6 +227,8 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
TEST_ASSERT(!ble_gap_master_in_progress());
TEST_ASSERT(!ble_gap_slave_in_progress());
+ ble_hs_lock();
+
conn = ble_hs_conn_first();
TEST_ASSERT_FATAL(conn != NULL);
TEST_ASSERT(conn->bhc_handle == 2);
@@ -217,6 +239,8 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
TEST_ASSERT(chan->blc_my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
TEST_ASSERT(chan->blc_peer_mtu == 0);
TEST_ASSERT(chan->blc_default_mtu == BLE_ATT_MTU_DFLT);
+
+ ble_hs_unlock();
}
TEST_SUITE(conn_suite)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/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 3d7a0b9..d0b8c0b 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -299,12 +299,11 @@ ble_hs_test_util_set_ack_seq(struct ble_hs_test_util_phony_ack *acks)
ble_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb);
}
-struct ble_hs_conn *
+void
ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
ble_gap_conn_fn *cb, void *cb_arg)
{
struct hci_le_conn_complete evt;
- struct ble_hs_conn *conn;
int rc;
ble_hs_test_util_set_ack(
@@ -325,12 +324,7 @@ ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
rc = ble_gap_rx_conn_complete(&evt);
TEST_ASSERT(rc == 0);
- conn = ble_hs_conn_find(handle);
- TEST_ASSERT_FATAL(conn != NULL);
-
ble_hs_test_util_prev_hci_tx_clear();
-
- return conn;
}
int
@@ -534,7 +528,7 @@ ble_hs_test_util_security_initiate(uint16_t conn_handle, uint8_t hci_status)
}
int
-ble_hs_test_util_l2cap_rx_first_frag(struct ble_hs_conn *conn, uint16_t cid,
+ble_hs_test_util_l2cap_rx_first_frag(uint16_t conn_handle, uint16_t cid,
struct hci_data_hdr *hci_hdr,
struct os_mbuf *om)
{
@@ -543,24 +537,35 @@ ble_hs_test_util_l2cap_rx_first_frag(struct ble_hs_conn *conn, uint16_t cid,
om = ble_l2cap_prepend_hdr(om, cid, OS_MBUF_PKTLEN(om));
TEST_ASSERT_FATAL(om != NULL);
- rc = ble_hs_test_util_l2cap_rx(conn, hci_hdr, om);
+ rc = ble_hs_test_util_l2cap_rx(conn_handle, hci_hdr, om);
return rc;
}
int
-ble_hs_test_util_l2cap_rx(struct ble_hs_conn *conn,
+ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
struct hci_data_hdr *hci_hdr,
struct os_mbuf *om)
{
+ struct ble_hs_conn *conn;
ble_l2cap_rx_fn *rx_cb;
struct os_mbuf *rx_buf;
int rc;
- rc = ble_l2cap_rx(conn, hci_hdr, om, &rx_cb, &rx_buf);
- if (rc == 0) {
+ ble_hs_lock();
+
+ conn = ble_hs_conn_find(conn_handle);
+ if (conn != NULL) {
+ rc = ble_l2cap_rx(conn, hci_hdr, om, &rx_cb, &rx_buf);
+ }
+
+ ble_hs_unlock();
+
+ if (conn == NULL) {
+ rc = BLE_HS_ENOTCONN;
+ } else if (rc == 0) {
TEST_ASSERT_FATAL(rx_cb != NULL);
TEST_ASSERT_FATAL(rx_buf != NULL);
- rc = rx_cb(conn->bhc_handle, &rx_buf);
+ rc = rx_cb(conn_handle, &rx_buf);
os_mbuf_free_chain(rx_buf);
} else if (rc == BLE_HS_EAGAIN) {
/* More fragments on the way. */
@@ -571,8 +576,7 @@ ble_hs_test_util_l2cap_rx(struct ble_hs_conn *conn,
}
int
-ble_hs_test_util_l2cap_rx_payload_flat(struct ble_hs_conn *conn,
- struct ble_l2cap_chan *chan,
+ble_hs_test_util_l2cap_rx_payload_flat(uint16_t conn_handle, uint16_t cid,
const void *data, int len)
{
struct hci_data_hdr hci_hdr;
@@ -586,21 +590,19 @@ ble_hs_test_util_l2cap_rx_payload_flat(struct ble_hs_conn *conn,
TEST_ASSERT_FATAL(rc == 0);
hci_hdr.hdh_handle_pb_bc =
- host_hci_handle_pb_bc_join(conn->bhc_handle,
+ host_hci_handle_pb_bc_join(conn_handle,
BLE_HCI_PB_FIRST_FLUSH, 0);
hci_hdr.hdh_len = OS_MBUF_PKTHDR(om)->omp_len;
- rc = ble_hs_test_util_l2cap_rx_first_frag(conn, chan->blc_cid, &hci_hdr,
- om);
+ rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, cid, &hci_hdr, om);
return rc;
}
void
-ble_hs_test_util_rx_att_err_rsp(struct ble_hs_conn *conn, uint8_t req_op,
+ble_hs_test_util_rx_att_err_rsp(uint16_t conn_handle, uint8_t req_op,
uint8_t error_code, uint16_t err_handle)
{
struct ble_att_error_rsp rsp;
- struct ble_l2cap_chan *chan;
uint8_t buf[BLE_ATT_ERROR_RSP_SZ];
int rc;
@@ -610,10 +612,8 @@ ble_hs_test_util_rx_att_err_rsp(struct ble_hs_conn *conn, uint8_t req_op,
ble_att_error_rsp_write(buf, sizeof buf, &rsp);
- chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
- TEST_ASSERT_FATAL(chan != NULL);
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
+ rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
+ buf, sizeof buf);
TEST_ASSERT(rc == 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/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 c642c65..baffffc 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -52,10 +52,8 @@ void ble_hs_test_util_build_cmd_complete(uint8_t *dst, int len,
void ble_hs_test_util_build_cmd_status(uint8_t *dst, int len,
uint8_t status, uint8_t num_pkts,
uint16_t opcode);
-struct ble_hs_conn *ble_hs_test_util_create_conn(uint16_t handle,
- uint8_t *addr,
- ble_gap_conn_fn *cb,
- void *cb_arg);
+void ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
+ ble_gap_conn_fn *cb, void *cb_arg);
int ble_hs_test_util_conn_initiate(int addr_type, uint8_t *addr,
struct ble_gap_crt_params *params,
ble_gap_conn_fn *cb, void *cb_arg,
@@ -81,18 +79,16 @@ int ble_hs_test_util_conn_update(uint16_t conn_handle,
uint8_t hci_status);
int ble_hs_test_util_security_initiate(uint16_t conn_handle,
uint8_t hci_status);
-int ble_hs_test_util_l2cap_rx_first_frag(struct ble_hs_conn *conn,
- uint16_t cid,
+int ble_hs_test_util_l2cap_rx_first_frag(uint16_t conn_handle, uint16_t cid,
struct hci_data_hdr *hci_hdr,
struct os_mbuf *om);
-int ble_hs_test_util_l2cap_rx(struct ble_hs_conn *conn,
+int ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
struct hci_data_hdr *hci_hdr,
struct os_mbuf *om);
-int ble_hs_test_util_l2cap_rx_payload_flat(struct ble_hs_conn *conn,
- struct ble_l2cap_chan *chan,
+int ble_hs_test_util_l2cap_rx_payload_flat(uint16_t conn_handle, uint16_t cid,
const void *data, int len);
void ble_hs_test_util_rx_hci_buf_size_ack(uint16_t buf_size);
-void ble_hs_test_util_rx_att_err_rsp(struct ble_hs_conn *conn, uint8_t req_op,
+void ble_hs_test_util_rx_att_err_rsp(uint16_t conn_handle, uint8_t req_op,
uint8_t error_code, uint16_t err_handle);
void ble_hs_test_util_set_startup_acks(void);
void ble_hs_test_util_rx_num_completed_pkts_event(
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/net/nimble/host/src/test/ble_l2cap_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_sm_test.c b/net/nimble/host/src/test/ble_l2cap_sm_test.c
index e6adb05..43d9350 100644
--- a/net/nimble/host/src/test/ble_l2cap_sm_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_sm_test.c
@@ -141,7 +141,7 @@ ble_l2cap_sm_test_util_conn_cb(int event, int status,
}
static void
-ble_l2cap_sm_test_util_rx_pair_cmd(struct ble_hs_conn *conn, uint8_t op,
+ble_l2cap_sm_test_util_rx_pair_cmd(uint16_t conn_handle, uint8_t op,
struct ble_l2cap_sm_pair_cmd *cmd,
int rx_status)
{
@@ -166,31 +166,31 @@ ble_l2cap_sm_test_util_rx_pair_cmd(struct ble_hs_conn *conn, uint8_t op,
ble_l2cap_sm_pair_cmd_write(v, payload_len, op == BLE_L2CAP_SM_OP_PAIR_REQ,
cmd);
- rc = ble_hs_test_util_l2cap_rx_first_frag(conn, BLE_L2CAP_CID_SM, &hci_hdr,
- om);
+ rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+ &hci_hdr, om);
TEST_ASSERT(rc == rx_status);
}
static void
-ble_l2cap_sm_test_util_rx_pair_req(struct ble_hs_conn *conn,
+ble_l2cap_sm_test_util_rx_pair_req(uint16_t conn_handle,
struct ble_l2cap_sm_pair_cmd *req,
int rx_status)
{
- ble_l2cap_sm_test_util_rx_pair_cmd(conn, BLE_L2CAP_SM_OP_PAIR_REQ, req,
- rx_status);
+ ble_l2cap_sm_test_util_rx_pair_cmd(conn_handle, BLE_L2CAP_SM_OP_PAIR_REQ,
+ req, rx_status);
}
static void
-ble_l2cap_sm_test_util_rx_pair_rsp(struct ble_hs_conn *conn,
+ble_l2cap_sm_test_util_rx_pair_rsp(uint16_t conn_handle,
struct ble_l2cap_sm_pair_cmd *rsp,
int rx_status)
{
- ble_l2cap_sm_test_util_rx_pair_cmd(conn, BLE_L2CAP_SM_OP_PAIR_RSP, rsp,
- rx_status);
+ ble_l2cap_sm_test_util_rx_pair_cmd(conn_handle, BLE_L2CAP_SM_OP_PAIR_RSP,
+ rsp, rx_status);
}
static void
-ble_l2cap_sm_test_util_rx_confirm(struct ble_hs_conn *conn,
+ble_l2cap_sm_test_util_rx_confirm(uint16_t conn_handle,
struct ble_l2cap_sm_pair_confirm *cmd)
{
struct hci_data_hdr hci_hdr;
@@ -213,13 +213,13 @@ ble_l2cap_sm_test_util_rx_confirm(struct ble_hs_conn *conn,
ble_l2cap_sm_pair_confirm_write(v, payload_len, cmd);
- rc = ble_hs_test_util_l2cap_rx_first_frag(conn, BLE_L2CAP_CID_SM, &hci_hdr,
- om);
+ rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+ &hci_hdr, om);
TEST_ASSERT_FATAL(rc == 0);
}
static void
-ble_l2cap_sm_test_util_rx_random(struct ble_hs_conn *conn,
+ble_l2cap_sm_test_util_rx_random(uint16_t conn_handle,
struct ble_l2cap_sm_pair_random *cmd,
int exp_status)
{
@@ -243,8 +243,8 @@ ble_l2cap_sm_test_util_rx_random(struct ble_hs_conn *conn,
ble_l2cap_sm_pair_random_write(v, payload_len, cmd);
- rc = ble_hs_test_util_l2cap_rx_first_frag(conn, BLE_L2CAP_CID_SM, &hci_hdr,
- om);
+ rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+ &hci_hdr, om);
TEST_ASSERT_FATAL(rc == exp_status);
}
@@ -461,9 +461,17 @@ ble_l2cap_sm_test_util_peer_fail_inval(
ble_l2cap_sm_test_util_init();
ble_hs_test_util_set_public_addr(rsp_addr);
- conn = ble_hs_test_util_create_conn(2, init_addr,
- ble_l2cap_sm_test_util_conn_cb,
- NULL);
+ ble_hs_test_util_create_conn(2, init_addr, ble_l2cap_sm_test_util_conn_cb,
+ NULL);
+
+ /* This test inspects and modifies the connection object without locking
+ * the host mutex. It is not OK for real code to do this, but this test
+ * can assume the connection list is unchanging.
+ */
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
+ ble_hs_unlock();
if (!we_are_master) {
conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
@@ -473,7 +481,7 @@ ble_l2cap_sm_test_util_peer_fail_inval(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
/* Receive a pair request from the peer. */
- ble_l2cap_sm_test_util_rx_pair_req(conn, pair_req,
+ ble_l2cap_sm_test_util_rx_pair_req(2, pair_req,
BLE_HS_SM_US_ERR(pair_fail->reason));
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
@@ -676,9 +684,17 @@ ble_l2cap_sm_test_util_peer_lgcy_fail_confirm(
ble_hs_test_util_set_public_addr(rsp_addr);
ble_l2cap_sm_dbg_set_next_pair_rand(random_rsp->value);
- conn = ble_hs_test_util_create_conn(2, init_addr,
- ble_l2cap_sm_test_util_conn_cb,
- NULL);
+ ble_hs_test_util_create_conn(2, init_addr, ble_l2cap_sm_test_util_conn_cb,
+ NULL);
+
+ /* This test inspects and modifies the connection object without locking
+ * the host mutex. It is not OK for real code to do this, but this test
+ * can assume the connection list is unchanging.
+ */
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
+ ble_hs_unlock();
/* Peer is the initiator so we must be the slave. */
conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
@@ -686,7 +702,7 @@ ble_l2cap_sm_test_util_peer_lgcy_fail_confirm(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
/* Receive a pair request from the peer. */
- ble_l2cap_sm_test_util_rx_pair_req(conn, pair_req, 0);
+ ble_l2cap_sm_test_util_rx_pair_req(2, pair_req, 0);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
/* Ensure we sent the expected pair response. */
@@ -695,7 +711,7 @@ ble_l2cap_sm_test_util_peer_lgcy_fail_confirm(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
/* Receive a pair confirm from the peer. */
- ble_l2cap_sm_test_util_rx_confirm(conn, confirm_req);
+ ble_l2cap_sm_test_util_rx_confirm(2, confirm_req);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
/* Ensure we sent the expected pair confirm. */
@@ -705,7 +721,7 @@ ble_l2cap_sm_test_util_peer_lgcy_fail_confirm(
/* Receive a pair random from the peer. */
ble_l2cap_sm_test_util_rx_random(
- conn, random_req, BLE_HS_SM_US_ERR(BLE_L2CAP_SM_ERR_CONFIRM_MISMATCH));
+ 2, random_req, BLE_HS_SM_US_ERR(BLE_L2CAP_SM_ERR_CONFIRM_MISMATCH));
/* Ensure we sent the expected pair fail. */
ble_hs_test_util_tx_all();
@@ -806,9 +822,18 @@ ble_l2cap_sm_test_util_peer_lgcy_good(
ble_hs_test_util_set_public_addr(params->rsp_addr);
ble_l2cap_sm_dbg_set_next_pair_rand(params->random_rsp.value);
- conn = ble_hs_test_util_create_conn(2, params->init_addr,
- ble_l2cap_sm_test_util_conn_cb,
- ¶ms->passkey);
+ ble_hs_test_util_create_conn(2, params->init_addr,
+ ble_l2cap_sm_test_util_conn_cb,
+ ¶ms->passkey);
+
+ /* This test inspects and modifies the connection object without locking
+ * the host mutex. It is not OK for real code to do this, but this test
+ * can assume the connection list is unchanging.
+ */
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
+ ble_hs_unlock();
/* Peer is the initiator so we must be the slave. */
conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
@@ -817,7 +842,7 @@ ble_l2cap_sm_test_util_peer_lgcy_good(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
/* Receive a pair request from the peer. */
- ble_l2cap_sm_test_util_rx_pair_req(conn, ¶ms->pair_req, 0);
+ ble_l2cap_sm_test_util_rx_pair_req(2, ¶ms->pair_req, 0);
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
@@ -828,7 +853,7 @@ ble_l2cap_sm_test_util_peer_lgcy_good(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
/* Receive a pair confirm from the peer. */
- ble_l2cap_sm_test_util_rx_confirm(conn, ¶ms->confirm_req);
+ ble_l2cap_sm_test_util_rx_confirm(2, ¶ms->confirm_req);
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
@@ -839,7 +864,7 @@ ble_l2cap_sm_test_util_peer_lgcy_good(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
/* Receive a pair random from the peer. */
- ble_l2cap_sm_test_util_rx_random(conn, ¶ms->random_req, 0);
+ ble_l2cap_sm_test_util_rx_random(2, ¶ms->random_req, 0);
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
@@ -1023,9 +1048,18 @@ ble_l2cap_sm_test_util_peer_bonding_good(uint8_t *ltk, int authenticated,
memcpy(ltk_info.ltk, ltk, sizeof ltk_info.ltk);
ltk_info.authenticated = authenticated;
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
- ble_l2cap_sm_test_util_conn_cb,
- <k_info);
+ ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
+ ble_l2cap_sm_test_util_conn_cb,
+ <k_info);
+
+ /* This test inspects and modifies the connection object without locking
+ * the host mutex. It is not OK for real code to do this, but this test
+ * can assume the connection list is unchanging.
+ */
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
+ ble_hs_unlock();
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
@@ -1079,9 +1113,18 @@ ble_l2cap_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
ble_l2cap_sm_test_util_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
- ble_l2cap_sm_test_util_conn_cb,
- NULL);
+ ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
+ ble_l2cap_sm_test_util_conn_cb,
+ NULL);
+
+ /* This test inspects and modifies the connection object without locking
+ * the host mutex. It is not OK for real code to do this, but this test
+ * can assume the connection list is unchanging.
+ */
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
+ ble_hs_unlock();
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
@@ -1144,9 +1187,18 @@ ble_l2cap_sm_test_util_us_fail_inval(
ble_l2cap_sm_test_util_init();
ble_hs_test_util_set_public_addr(params->rsp_addr);
- conn = ble_hs_test_util_create_conn(2, params->init_addr,
- ble_l2cap_sm_test_util_conn_cb,
- NULL);
+ ble_hs_test_util_create_conn(2, params->init_addr,
+ ble_l2cap_sm_test_util_conn_cb,
+ NULL);
+
+ /* This test inspects and modifies the connection object without locking
+ * the host mutex. It is not OK for real code to do this, but this test
+ * can assume the connection list is unchanging.
+ */
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
+ ble_hs_unlock();
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
@@ -1163,7 +1215,7 @@ ble_l2cap_sm_test_util_us_fail_inval(
/* Receive a pair response from the peer. */
ble_l2cap_sm_test_util_rx_pair_rsp(
- conn, ¶ms->pair_rsp, BLE_HS_SM_US_ERR(BLE_L2CAP_SM_ERR_INVAL));
+ 2, ¶ms->pair_rsp, BLE_HS_SM_US_ERR(BLE_L2CAP_SM_ERR_INVAL));
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
@@ -1412,9 +1464,18 @@ ble_l2cap_sm_test_util_us_lgcy_good(
ble_l2cap_sm_dbg_set_next_ltk(params->enc_info_req.ltk_le);
}
- conn = ble_hs_test_util_create_conn(2, params->rsp_addr,
- ble_l2cap_sm_test_util_conn_cb,
- NULL);
+ ble_hs_test_util_create_conn(2, params->rsp_addr,
+ ble_l2cap_sm_test_util_conn_cb,
+ NULL);
+
+ /* This test inspects and modifies the connection object without locking
+ * the host mutex. It is not OK for real code to do this, but this test
+ * can assume the connection list is unchanging.
+ */
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
+ ble_hs_unlock();
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
@@ -1430,7 +1491,7 @@ ble_l2cap_sm_test_util_us_lgcy_good(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
/* Receive a pair response from the peer. */
- ble_l2cap_sm_test_util_rx_pair_rsp(conn, ¶ms->pair_rsp, 0);
+ ble_l2cap_sm_test_util_rx_pair_rsp(2, ¶ms->pair_rsp, 0);
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
@@ -1441,7 +1502,7 @@ ble_l2cap_sm_test_util_us_lgcy_good(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
/* Receive a pair confirm from the peer. */
- ble_l2cap_sm_test_util_rx_confirm(conn, ¶ms->confirm_rsp);
+ ble_l2cap_sm_test_util_rx_confirm(2, ¶ms->confirm_rsp);
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
@@ -1452,7 +1513,7 @@ ble_l2cap_sm_test_util_us_lgcy_good(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
/* Receive a pair random from the peer. */
- ble_l2cap_sm_test_util_rx_random(conn, ¶ms->random_rsp, 0);
+ ble_l2cap_sm_test_util_rx_random(2, ¶ms->random_rsp, 0);
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2dd32b7d/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index 0229a54..23c0167 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -50,7 +50,7 @@ ble_l2cap_test_util_init(void)
}
static void
-ble_l2cap_test_util_rx_update_req(struct ble_hs_conn *conn, uint8_t id,
+ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
struct ble_l2cap_sig_update_params *params)
{
struct ble_l2cap_sig_update_req req;
@@ -75,13 +75,13 @@ ble_l2cap_test_util_rx_update_req(struct ble_hs_conn *conn, uint8_t id,
ble_hs_test_util_set_ack(
host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CONN_UPDATE), 0);
- rc = ble_hs_test_util_l2cap_rx_first_frag(conn, BLE_L2CAP_CID_SIG,
+ rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG,
&hci_hdr, om);
TEST_ASSERT_FATAL(rc == 0);
}
static int
-ble_l2cap_test_util_rx_update_rsp(struct ble_hs_conn *conn,
+ble_l2cap_test_util_rx_update_rsp(uint16_t conn_handle,
uint8_t id, uint16_t result)
{
struct ble_l2cap_sig_update_rsp rsp;
@@ -101,7 +101,7 @@ ble_l2cap_test_util_rx_update_rsp(struct ble_hs_conn *conn,
rsp.result = result;
ble_l2cap_sig_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
- rc = ble_hs_test_util_l2cap_rx_first_frag(conn, BLE_L2CAP_CID_SIG,
+ rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG,
&hci_hdr, om);
return rc;
}
@@ -202,14 +202,19 @@ ble_l2cap_test_util_dummy_rx(uint16_t conn_handle, struct os_mbuf **om)
return 0;
}
-static struct ble_hs_conn *
-ble_l2cap_test_util_create_conn(uint16_t handle, uint8_t *addr,
+static void
+ble_l2cap_test_util_create_conn(uint16_t conn_handle, uint8_t *addr,
ble_gap_conn_fn *cb, void *cb_arg)
{
struct ble_l2cap_chan *chan;
struct ble_hs_conn *conn;
- conn = ble_hs_test_util_create_conn(handle, addr, cb, cb_arg);
+ ble_hs_test_util_create_conn(conn_handle, addr, cb, cb_arg);
+
+ ble_hs_lock();
+
+ conn = ble_hs_conn_find(conn_handle);
+ TEST_ASSERT_FATAL(conn != NULL);
chan = ble_l2cap_chan_alloc();
TEST_ASSERT_FATAL(chan != NULL);
@@ -223,11 +228,11 @@ ble_l2cap_test_util_create_conn(uint16_t handle, uint8_t *addr,
ble_hs_test_util_prev_hci_tx_clear();
- return conn;
+ ble_hs_unlock();
}
static int
-ble_l2cap_test_util_rx_first_frag(struct ble_hs_conn *conn,
+ble_l2cap_test_util_rx_first_frag(uint16_t conn_handle,
uint16_t l2cap_frag_len,
uint16_t cid, uint16_t l2cap_len)
{
@@ -247,14 +252,14 @@ ble_l2cap_test_util_rx_first_frag(struct ble_hs_conn *conn,
TEST_ASSERT_FATAL(om != NULL);
hci_len = sizeof hci_hdr + l2cap_frag_len;
- hci_hdr = BLE_L2CAP_TEST_UTIL_HCI_HDR(conn->bhc_handle,
+ hci_hdr = BLE_L2CAP_TEST_UTIL_HCI_HDR(conn_handle,
BLE_HCI_PB_FIRST_FLUSH, hci_len);
- rc = ble_hs_test_util_l2cap_rx(conn, &hci_hdr, om);
+ rc = ble_hs_test_util_l2cap_rx(conn_handle, &hci_hdr, om);
return rc;
}
static int
-ble_l2cap_test_util_rx_next_frag(struct ble_hs_conn *conn, uint16_t hci_len)
+ble_l2cap_test_util_rx_next_frag(uint16_t conn_handle, uint16_t hci_len)
{
struct hci_data_hdr hci_hdr;
struct os_mbuf *om;
@@ -267,47 +272,71 @@ ble_l2cap_test_util_rx_next_frag(struct ble_hs_conn *conn, uint16_t hci_len)
v = os_mbuf_extend(om, hci_len);
TEST_ASSERT_FATAL(v != NULL);
- hci_hdr = BLE_L2CAP_TEST_UTIL_HCI_HDR(conn->bhc_handle,
+ hci_hdr = BLE_L2CAP_TEST_UTIL_HCI_HDR(conn_handle,
BLE_HCI_PB_MIDDLE, hci_len);
- rc = ble_hs_test_util_l2cap_rx(conn, &hci_hdr, om);
+ rc = ble_hs_test_util_l2cap_rx(conn_handle, &hci_hdr, om);
return rc;
}
static void
-ble_l2cap_test_util_verify_first_frag(struct ble_hs_conn *conn,
+ble_l2cap_test_util_verify_first_frag(uint16_t conn_handle,
uint16_t l2cap_frag_len,
uint16_t l2cap_len)
{
+ struct ble_hs_conn *conn;
int rc;
- rc = ble_l2cap_test_util_rx_first_frag(conn, l2cap_frag_len,
+ rc = ble_l2cap_test_util_rx_first_frag(conn_handle, l2cap_frag_len,
BLE_L2CAP_TEST_CID, l2cap_len);
TEST_ASSERT(rc == 0);
+
+ ble_hs_lock();
+
+ conn = ble_hs_conn_find(conn_handle);
+ TEST_ASSERT_FATAL(conn != NULL);
TEST_ASSERT(conn->bhc_rx_chan != NULL &&
conn->bhc_rx_chan->blc_cid == BLE_L2CAP_TEST_CID);
+
+ ble_hs_unlock();
}
static void
-ble_l2cap_test_util_verify_middle_frag(struct ble_hs_conn *conn,
+ble_l2cap_test_util_verify_middle_frag(uint16_t conn_handle,
uint16_t hci_len)
{
+ struct ble_hs_conn *conn;
int rc;
- rc = ble_l2cap_test_util_rx_next_frag(conn, hci_len);
+ rc = ble_l2cap_test_util_rx_next_frag(conn_handle, hci_len);
TEST_ASSERT(rc == 0);
+
+ ble_hs_lock();
+
+ conn = ble_hs_conn_find(conn_handle);
+ TEST_ASSERT_FATAL(conn != NULL);
TEST_ASSERT(conn->bhc_rx_chan != NULL &&
conn->bhc_rx_chan->blc_cid == BLE_L2CAP_TEST_CID);
+
+ ble_hs_unlock();
}
static void
-ble_l2cap_test_util_verify_last_frag(struct ble_hs_conn *conn,
+ble_l2cap_test_util_verify_last_frag(uint16_t conn_handle,
uint16_t hci_len)
{
+ struct ble_hs_conn *conn;
int rc;
- rc = ble_l2cap_test_util_rx_next_frag(conn, hci_len);
+ rc = ble_l2cap_test_util_rx_next_frag(conn_handle, hci_len);
TEST_ASSERT(rc == 0);
+
+ ble_hs_lock();
+
+ conn = ble_hs_conn_find(conn_handle);
+ TEST_ASSERT_FATAL(conn != NULL);
TEST_ASSERT(conn->bhc_rx_chan == NULL);
+
+ ble_hs_unlock();
}
/*****************************************************************************
@@ -316,15 +345,14 @@ ble_l2cap_test_util_verify_last_frag(struct ble_hs_conn *conn,
TEST_CASE(ble_l2cap_test_case_bad_header)
{
- struct ble_hs_conn *conn;
int rc;
ble_l2cap_test_util_init();
- conn = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- NULL, NULL);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ NULL, NULL);
- rc = ble_l2cap_test_util_rx_first_frag(conn, 14, 1234, 10);
+ rc = ble_l2cap_test_util_rx_first_frag(2, 14, 1234, 10);
TEST_ASSERT(rc == BLE_HS_ENOENT);
}
@@ -335,14 +363,13 @@ TEST_CASE(ble_l2cap_test_case_bad_header)
TEST_CASE(ble_l2cap_test_case_frag_single)
{
struct hci_data_hdr hci_hdr;
- struct ble_hs_conn *conn;
struct os_mbuf *om;
int rc;
ble_l2cap_test_util_init();
- conn = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- NULL, NULL);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ NULL, NULL);
/*** HCI header specifies middle fragment without start. */
hci_hdr = BLE_L2CAP_TEST_UTIL_HCI_HDR(2, BLE_HCI_PB_MIDDLE, 10);
@@ -353,44 +380,42 @@ TEST_CASE(ble_l2cap_test_case_frag_single)
om = ble_l2cap_prepend_hdr(om, 0, 5);
TEST_ASSERT_FATAL(om != NULL);
- rc = ble_hs_test_util_l2cap_rx(conn, &hci_hdr, om);
+ rc = ble_hs_test_util_l2cap_rx(2, &hci_hdr, om);
TEST_ASSERT(rc == BLE_HS_EBADDATA);
/*** Packet consisting of three fragments. */
- ble_l2cap_test_util_verify_first_frag(conn, 10, 30);
- ble_l2cap_test_util_verify_middle_frag(conn, 10);
- ble_l2cap_test_util_verify_last_frag(conn, 10);
+ ble_l2cap_test_util_verify_first_frag(2, 10, 30);
+ ble_l2cap_test_util_verify_middle_frag(2, 10);
+ ble_l2cap_test_util_verify_last_frag(2, 10);
/*** Packet consisting of five fragments. */
- ble_l2cap_test_util_verify_first_frag(conn, 8, 49);
- ble_l2cap_test_util_verify_middle_frag(conn, 13);
- ble_l2cap_test_util_verify_middle_frag(conn, 2);
- ble_l2cap_test_util_verify_middle_frag(conn, 21);
- ble_l2cap_test_util_verify_last_frag(conn, 5);
+ ble_l2cap_test_util_verify_first_frag(2, 8, 49);
+ ble_l2cap_test_util_verify_middle_frag(2, 13);
+ ble_l2cap_test_util_verify_middle_frag(2, 2);
+ ble_l2cap_test_util_verify_middle_frag(2, 21);
+ ble_l2cap_test_util_verify_last_frag(2, 5);
}
TEST_CASE(ble_l2cap_test_case_frag_multiple)
{
- struct ble_hs_conn *conns[3];
-
ble_l2cap_test_util_init();
- conns[0] = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- NULL, NULL);
- conns[1] = ble_l2cap_test_util_create_conn(3, ((uint8_t[]){2,3,4,5,6,7}),
- NULL, NULL);
- conns[2] = ble_l2cap_test_util_create_conn(4, ((uint8_t[]){3,4,5,6,7,8}),
- NULL, NULL);
-
- ble_l2cap_test_util_verify_first_frag(conns[0], 3, 10);
- ble_l2cap_test_util_verify_first_frag(conns[1], 2, 5);
- ble_l2cap_test_util_verify_middle_frag(conns[0], 6);
- ble_l2cap_test_util_verify_first_frag(conns[2], 1, 4);
- ble_l2cap_test_util_verify_middle_frag(conns[1], 2);
- ble_l2cap_test_util_verify_last_frag(conns[1], 1);
- ble_l2cap_test_util_verify_middle_frag(conns[2], 2);
- ble_l2cap_test_util_verify_last_frag(conns[2], 1);
- ble_l2cap_test_util_verify_last_frag(conns[0], 1);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ NULL, NULL);
+ ble_l2cap_test_util_create_conn(3, ((uint8_t[]){2,3,4,5,6,7}),
+ NULL, NULL);
+ ble_l2cap_test_util_create_conn(4, ((uint8_t[]){3,4,5,6,7,8}),
+ NULL, NULL);
+
+ ble_l2cap_test_util_verify_first_frag(2, 3, 10);
+ ble_l2cap_test_util_verify_first_frag(3, 2, 5);
+ ble_l2cap_test_util_verify_middle_frag(2, 6);
+ ble_l2cap_test_util_verify_first_frag(4, 1, 4);
+ ble_l2cap_test_util_verify_middle_frag(3, 2);
+ ble_l2cap_test_util_verify_last_frag(3, 1);
+ ble_l2cap_test_util_verify_middle_frag(4, 2);
+ ble_l2cap_test_util_verify_last_frag(4, 1);
+ ble_l2cap_test_util_verify_last_frag(2, 1);
}
TEST_CASE(ble_l2cap_test_case_frag_channels)
@@ -400,22 +425,32 @@ TEST_CASE(ble_l2cap_test_case_frag_channels)
ble_l2cap_test_util_init();
- conn = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- NULL, NULL);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ NULL, NULL);
/* Receive a starting fragment on the first channel. */
- rc = ble_l2cap_test_util_rx_first_frag(conn, 14, BLE_L2CAP_TEST_CID, 30);
+ rc = ble_l2cap_test_util_rx_first_frag(2, 14, BLE_L2CAP_TEST_CID, 30);
TEST_ASSERT(rc == 0);
+
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
TEST_ASSERT(conn->bhc_rx_chan != NULL &&
conn->bhc_rx_chan->blc_cid == BLE_L2CAP_TEST_CID);
+ ble_hs_unlock();
/* Receive a starting fragment on a different channel. The first fragment
* should get discarded.
*/
- rc = ble_l2cap_test_util_rx_first_frag(conn, 14, BLE_L2CAP_CID_ATT, 30);
+ rc = ble_l2cap_test_util_rx_first_frag(2, 14, BLE_L2CAP_CID_ATT, 30);
TEST_ASSERT(rc == 0);
+
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
TEST_ASSERT(conn->bhc_rx_chan != NULL &&
conn->bhc_rx_chan->blc_cid == BLE_L2CAP_CID_ATT);
+ ble_hs_unlock();
}
/*****************************************************************************
@@ -424,16 +459,15 @@ TEST_CASE(ble_l2cap_test_case_frag_channels)
TEST_CASE(ble_l2cap_test_case_sig_unsol_rsp)
{
- struct ble_hs_conn *conn;
int rc;
ble_l2cap_test_util_init();
- conn = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- NULL, NULL);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ NULL, NULL);
/* Receive an unsolicited response. */
- rc = ble_l2cap_test_util_rx_update_rsp(conn, 100, 0);
+ rc = ble_l2cap_test_util_rx_update_rsp(2, 100, 0);
TEST_ASSERT(rc == BLE_HS_ENOENT);
/* Ensure we did not send anything in return. */
@@ -466,19 +500,20 @@ ble_l2cap_test_util_peer_updates(int accept)
{
struct ble_l2cap_sig_update_params l2cap_params;
struct ble_gap_upd_params params;
- struct ble_hs_conn *conn;
+ ble_hs_conn_flags_t conn_flags;
+ int rc;
ble_l2cap_test_util_init();
- conn = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- ble_l2cap_test_util_conn_cb,
- &accept);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ ble_l2cap_test_util_conn_cb,
+ &accept);
l2cap_params.itvl_min = 0x200;
l2cap_params.itvl_max = 0x300;
l2cap_params.slave_latency = 0;
l2cap_params.timeout_multiplier = 0x100;
- ble_l2cap_test_util_rx_update_req(conn, 1, &l2cap_params);
+ ble_l2cap_test_util_rx_update_req(2, 1, &l2cap_params);
/* Ensure an update response command got sent. */
ble_hs_process_tx_data_queue();
@@ -494,7 +529,8 @@ ble_l2cap_test_util_peer_updates(int accept)
ble_l2cap_test_util_verify_tx_update_conn(¶ms);
} else {
/* Ensure no update got scheduled. */
- TEST_ASSERT(!ble_gap_update_in_progress(BLE_HS_CONN_HANDLE_NONE));
+ rc = ble_hs_atomic_conn_flags(2, &conn_flags);
+ TEST_ASSERT(rc == 0 && !(conn_flags & BLE_HS_CONN_F_UPDATE));
}
}
@@ -509,24 +545,22 @@ static void
ble_l2cap_test_util_we_update(int peer_accepts)
{
struct ble_l2cap_sig_update_params params;
- struct ble_hs_conn *conn;
uint8_t id;
int rc;
ble_l2cap_test_util_init();
- conn = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- ble_l2cap_test_util_conn_cb, NULL);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ ble_l2cap_test_util_conn_cb, NULL);
/* Only the slave can initiate the L2CAP connection update procedure. */
- conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+ ble_hs_atomic_conn_set_flags(2, BLE_HS_CONN_F_MASTER, 0);
params.itvl_min = 0x200;
params.itvl_min = 0x300;
params.slave_latency = 0;
params.timeout_multiplier = 0x100;
- rc = ble_l2cap_sig_update(conn->bhc_handle, ¶ms,
- ble_l2cap_test_util_update_cb, NULL);
+ rc = ble_l2cap_sig_update(2, ¶ms, ble_l2cap_test_util_update_cb, NULL);
TEST_ASSERT_FATAL(rc == 0);
ble_hs_test_util_tx_all();
@@ -535,7 +569,7 @@ ble_l2cap_test_util_we_update(int peer_accepts)
id = ble_l2cap_test_util_verify_tx_update_req(¶ms);
/* Receive response from peer. */
- rc = ble_l2cap_test_util_rx_update_rsp(conn, id, !peer_accepts);
+ rc = ble_l2cap_test_util_rx_update_rsp(2, id, !peer_accepts);
TEST_ASSERT(rc == 0);
/* Ensure callback got called. */
@@ -570,20 +604,18 @@ TEST_CASE(ble_l2cap_test_case_sig_update_init_reject)
TEST_CASE(ble_l2cap_test_case_sig_update_init_fail_master)
{
struct ble_l2cap_sig_update_params params;
- struct ble_hs_conn *conn;
int rc;
ble_l2cap_test_util_init();
- conn = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- ble_l2cap_test_util_conn_cb, NULL);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ ble_l2cap_test_util_conn_cb, NULL);
params.itvl_min = 0x200;
params.itvl_min = 0x300;
params.slave_latency = 0;
params.timeout_multiplier = 0x100;
- rc = ble_l2cap_sig_update(conn->bhc_handle, ¶ms,
- ble_l2cap_test_util_update_cb, NULL);
+ rc = ble_l2cap_sig_update(2, ¶ms, ble_l2cap_test_util_update_cb, NULL);
TEST_ASSERT_FATAL(rc == BLE_HS_EINVAL);
/* Ensure callback never called. */
@@ -594,24 +626,22 @@ TEST_CASE(ble_l2cap_test_case_sig_update_init_fail_master)
TEST_CASE(ble_l2cap_test_case_sig_update_init_fail_bad_id)
{
struct ble_l2cap_sig_update_params params;
- struct ble_hs_conn *conn;
uint8_t id;
int rc;
ble_l2cap_test_util_init();
- conn = ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
- ble_l2cap_test_util_conn_cb, NULL);
+ ble_l2cap_test_util_create_conn(2, ((uint8_t[]){1,2,3,4,5,6}),
+ ble_l2cap_test_util_conn_cb, NULL);
/* Only the slave can initiate the L2CAP connection update procedure. */
- conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+ ble_hs_atomic_conn_set_flags(2, BLE_HS_CONN_F_MASTER, 0);
params.itvl_min = 0x200;
params.itvl_min = 0x300;
params.slave_latency = 0;
params.timeout_multiplier = 0x100;
- rc = ble_l2cap_sig_update(conn->bhc_handle, ¶ms,
- ble_l2cap_test_util_update_cb, NULL);
+ rc = ble_l2cap_sig_update(2, ¶ms, ble_l2cap_test_util_update_cb, NULL);
TEST_ASSERT_FATAL(rc == 0);
ble_hs_test_util_tx_all();
@@ -620,14 +650,14 @@ TEST_CASE(ble_l2cap_test_case_sig_update_init_fail_bad_id)
id = ble_l2cap_test_util_verify_tx_update_req(¶ms);
/* Receive response from peer with incorrect ID. */
- rc = ble_l2cap_test_util_rx_update_rsp(conn, id + 1, 0);
+ rc = ble_l2cap_test_util_rx_update_rsp(2, id + 1, 0);
TEST_ASSERT(rc == BLE_HS_ENOENT);
/* Ensure callback did not get called. */
TEST_ASSERT(ble_l2cap_test_update_status == -1);
/* Receive response from peer with correct ID. */
- rc = ble_l2cap_test_util_rx_update_rsp(conn, id, 0);
+ rc = ble_l2cap_test_util_rx_update_rsp(2, id, 0);
TEST_ASSERT(rc == 0);
/* Ensure callback got called. */