MYNEWT-702 BLE Host - duplicate update entries Fix similar issue for L2CAP updates.
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/e33dbd45 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e33dbd45 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e33dbd45 Branch: refs/heads/develop Commit: e33dbd45aa2de1209ef36d2cc0cf7016d97f2828 Parents: f601422 Author: Christopher Collins <[email protected]> Authored: Mon Apr 3 18:23:58 2017 -0700 Committer: Christopher Collins <[email protected]> Committed: Mon Apr 3 18:29:15 2017 -0700 ---------------------------------------------------------------------- net/nimble/host/src/ble_gap.c | 6 ++++-- net/nimble/host/test/src/ble_gap_test.c | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e33dbd45/net/nimble/host/src/ble_gap.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c index b494613..80bfa7a 100644 --- a/net/nimble/host/src/ble_gap.c +++ b/net/nimble/host/src/ble_gap.c @@ -2620,6 +2620,9 @@ ble_gap_update_entry_free(struct ble_gap_update_entry *entry) int rc; if (entry != NULL) { +#if MYNEWT_VAL(BLE_HS_DEBUG) + memset(entry, 0xff, sizeof *entry); +#endif rc = os_memblock_put(&ble_gap_update_entry_pool, entry); BLE_HS_DBG_ASSERT_EVAL(rc == 0); } @@ -2928,8 +2931,6 @@ done: if (rc == 0) { ble_hs_timer_resched(); } else { - ble_gap_update_entry_free(entry); - /* If the l2cap_params struct is populated, the only error is that the * controller doesn't support the connection parameters request * procedure. In this case, fallback to the L2CAP update procedure. @@ -2945,6 +2946,7 @@ done: if (rc == 0) { SLIST_INSERT_HEAD(&ble_gap_update_entries, entry, next); } else { + ble_gap_update_entry_free(entry); STATS_INC(ble_gap_stats, update_fail); } ble_hs_unlock(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e33dbd45/net/nimble/host/test/src/ble_gap_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_gap_test.c b/net/nimble/host/test/src/ble_gap_test.c index 8471d5b..d161ad9 100644 --- a/net/nimble/host/test/src/ble_gap_test.c +++ b/net/nimble/host/test/src/ble_gap_test.c @@ -1854,6 +1854,15 @@ ble_gap_test_util_update_l2cap(struct ble_gap_upd_params *params, TEST_ASSERT(ble_gap_dbg_update_active(2)); + /* Attempt two duplicate updates; ensure BLE_HS_EALREADY gets returned + * both times. Make sure initial update still completes successfully + * (MYNEWT-702). + */ + rc = ble_hs_test_util_conn_update(2, params, 0); + TEST_ASSERT(rc == BLE_HS_EALREADY); + rc = ble_hs_test_util_conn_update(2, params, 0); + TEST_ASSERT(rc == BLE_HS_EALREADY); + l2cap_params.itvl_min = params->itvl_min; l2cap_params.itvl_max = params->itvl_max; l2cap_params.slave_latency = params->latency;
