From d7f4d5b0bddf28d33f14ccd9becae72ee23ecd16 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Thu, 7 Oct 2021 14:34:20 +0200 Subject: [PATCH 1/3] ieee802154/submac: avoid race condition between RX_DONE and ACK_TIMEOUT --- sys/include/net/ieee802154/submac.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/include/net/ieee802154/submac.h b/sys/include/net/ieee802154/submac.h index 49e26e2dc7..5a1baa1925 100644 --- a/sys/include/net/ieee802154/submac.h +++ b/sys/include/net/ieee802154/submac.h @@ -544,7 +544,9 @@ ieee802154_fsm_state_t ieee802154_submac_process_ev(ieee802154_submac_t *submac, * * This function must be called when the ACK timeout timer fires. * - * @note this function should not be called inside ISR context. + * @note this function should not be called inside ISR context and MUST NOT + * be invoked if @ref ieee802154_submac_ack_timer_cancel was already + * called. * * @param[in] submac pointer to the SubMAC descriptor */ From cb6e242b652f3c87444f45d0be044b10c31d6f17 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Thu, 7 Oct 2021 14:37:05 +0200 Subject: [PATCH 2/3] net/netdev_ieee802154_submac: prevent calling ACK TO fired if cancelled --- drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c b/drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c index baa1efd509..d5692a5f57 100644 --- a/drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c +++ b/drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c @@ -151,6 +151,9 @@ void ieee802154_submac_ack_timer_cancel(ieee802154_submac_t *submac) submac); xtimer_remove(&netdev_submac->ack_timer); + /* Prevent a race condition between the RX_DONE event and the ACK timeout */ + netdev_submac->isr_flags &= ~NETDEV_SUBMAC_FLAGS_ACK_TIMEOUT; + } static int _send(netdev_t *netdev, const iolist_t *pkt) From a7a0b8f59258fe125a92a6c5b2629501db635f49 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Thu, 7 Oct 2021 14:48:36 +0200 Subject: [PATCH 3/3] tests/ieee802154_submac: prevent calling ACK TO fired if cancelled --- tests/ieee802154_submac/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ieee802154_submac/main.c b/tests/ieee802154_submac/main.c index 0e25a04279..0de03bd8dd 100644 --- a/tests/ieee802154_submac/main.c +++ b/tests/ieee802154_submac/main.c @@ -139,6 +139,10 @@ void ieee802154_submac_ack_timer_cancel(ieee802154_submac_t *submac) { (void)submac; ztimer_remove(ZTIMER_USEC, &ack_timer); + /* Avoid race conditions between RX_DONE and ACK_TIMEOUT */ + if (ev_ack_timeout.list_node.next) { + event_cancel(EVENT_PRIO_HIGHEST, &ev_ack_timeout); + } } static void _ack_timeout(void *arg)