From d103d827ad5fa5e7142109d7821c386448b99452 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 15 Dec 2020 10:29:55 -0800 Subject: [PATCH] [link-raw] disable/enable MAC layer when link-raw is enabled/disabled (#5956) This commit addresses an issue with `LinkRaw` on FTD/MTD builds. In FTD/MTD builds, we add code to disable/enable MAC layer when link-raw is being enabled/disabled. This ensures to avoid any conflict in control of radio and sub-mac between `Mac` and `LinkRaw`. In RADIO build, we directly enable/disable sub-mac (note that in FTD/MTD build then `Mac` layer would be enable sub-mac). --- src/core/mac/link_raw.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/mac/link_raw.cpp b/src/core/mac/link_raw.cpp index dc0f5c22d..5f8766c03 100644 --- a/src/core/mac/link_raw.cpp +++ b/src/core/mac/link_raw.cpp @@ -72,8 +72,14 @@ otError LinkRaw::SetReceiveDone(otLinkRawReceiveDone aCallback) #if OPENTHREAD_MTD || OPENTHREAD_FTD VerifyOrExit(!Get().IsUp(), error = OT_ERROR_INVALID_STATE); -#endif + // In MTD/FTD build, `Mac` has already enabled sub-mac. We ensure to + // disable/enable MAC layer when link-raw is being enabled/disabled to + // avoid any conflict in control of radio and sub-mac between `Mac` and + // `LinkRaw`. in RADIO build, we directly enable/disable sub-mac. + + Get().SetEnabled(aCallback == nullptr); +#else if (aCallback) { SuccessOrExit(error = mSubMac.Enable()); @@ -82,6 +88,7 @@ otError LinkRaw::SetReceiveDone(otLinkRawReceiveDone aCallback) { IgnoreError(mSubMac.Disable()); } +#endif mReceiveDoneCallback = aCallback;