Skip to content

Commit

Permalink
[mac] enable/disable radio together with MAC (#9156)
Browse files Browse the repository at this point in the history
Fix the behavior of `Mac::SetEnabled` for also enabling/disabling
the radio.

This ensures that the radio is turned off when `otLinkSetEnabled(false)`
is used.
  • Loading branch information
edmont authored Jun 14, 2023
1 parent 55e3440 commit 068ec09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/core/mac/mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Mac::Mac(Instance &aInstance)
ResetCounters();

SetEnabled(true);
mLinks.Enable();

Get<KeyManager>().UpdateKeyMaterial();
SetPanId(mPanId);
Expand All @@ -129,6 +128,20 @@ Mac::Mac(Instance &aInstance)
mMode2KeyMaterial.SetFrom(AsCoreType(&sMode2Key));
}

void Mac::SetEnabled(bool aEnable)
{
mEnabled = aEnable;

if (aEnable)
{
mLinks.Enable();
}
else
{
mLinks.Disable();
}
}

Error Mac::ActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, ActiveScanHandler aHandler, void *aContext)
{
Error error = kErrorNone;
Expand Down
2 changes: 1 addition & 1 deletion src/core/mac/mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ class Mac : public InstanceLocator, private NonCopyable
* @param[in] aEnable The requested State for the MAC layer. true - Start, false - Stop.
*
*/
void SetEnabled(bool aEnable) { mEnabled = aEnable; }
void SetEnabled(bool aEnable);

/**
* Indicates whether or not the link layer is enabled.
Expand Down

0 comments on commit 068ec09

Please sign in to comment.