From 5bd53db88fbc16be93587a48de5ab0f375602438 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 29 Apr 2019 16:15:23 +0200 Subject: [PATCH] tests/l2cap: use newly introduced TX_UNSTALLED evt --- tests/nimble_l2cap/main.c | 15 ++++++++++++--- tests/nimble_l2cap_server/main.c | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/nimble_l2cap/main.c b/tests/nimble_l2cap/main.c index 9671fe027b..3ea1b567e0 100644 --- a/tests/nimble_l2cap/main.c +++ b/tests/nimble_l2cap/main.c @@ -29,6 +29,8 @@ #include "assert.h" #include "shell.h" +#include "thread.h" +#include "thread_flags.h" #include "net/bluetil/ad.h" #include "nimble_l2cap_test_conf.h" @@ -36,8 +38,9 @@ #define ENABLE_DEBUG (1) #include "debug.h" -#define FLAG_UP (1u << 0) -#define FLAG_SYNC (1u << 1) +#define FLAG_UP (1u << 0) +#define FLAG_SYNC (1u << 1) +#define FLAG_TX_UNSTALLED (1u << 2) /* synchronization state */ static thread_t *_main; @@ -96,6 +99,9 @@ static int _on_l2cap_evt(struct ble_l2cap_event *event, void *arg) case BLE_L2CAP_EVENT_COC_DATA_RECEIVED: _on_data(event); break; + case BLE_L2CAP_EVENT_COC_TX_UNSTALLED: + thread_flags_set(_main, FLAG_TX_UNSTALLED); + break; case BLE_L2CAP_EVENT_COC_ACCEPT: /* this event should never be triggered for the L2CAP client */ /* fallthrough */ @@ -191,9 +197,12 @@ static void _send(uint32_t type, uint32_t seq, size_t len) do { res = ble_l2cap_send(_coc, txd); + if (res == BLE_HS_EBUSY) { + thread_flags_wait_all(FLAG_TX_UNSTALLED); + } } while (res == BLE_HS_EBUSY); - if (res != 0) { + if ((res != 0) && (res != BLE_HS_ESTALLED)) { printf("# err: failed to send (%i)\n", res); assert(0); } diff --git a/tests/nimble_l2cap_server/main.c b/tests/nimble_l2cap_server/main.c index d15e4c4f89..3903c6407c 100644 --- a/tests/nimble_l2cap_server/main.c +++ b/tests/nimble_l2cap_server/main.c @@ -63,7 +63,7 @@ static void _on_data(struct ble_l2cap_event *event) printf("# Received: len %5i, seq %5u\n", rx_len, (unsigned)_rxbuf[POS_SEQ]); res = ble_l2cap_send(_coc, rxd); - assert(res == 0); + assert((res == 0) || (res == BLE_HS_ESTALLED)); /* allocate new mbuf for receiving new data */ rxd = os_mbuf_get_pkthdr(&_coc_mbuf_pool, 0); @@ -118,6 +118,9 @@ static int _on_l2cap_evt(struct ble_l2cap_event *event, void *arg) case BLE_L2CAP_EVENT_COC_DATA_RECEIVED: _on_data(event); break; + case BLE_L2CAP_EVENT_COC_TX_UNSTALLED: + /* this event is expected, but we have nothing to do here */ + break; default: assert(0); break;