mirror of
https://github.com/espressif/openthread.git
synced 2026-08-29 13:29:54 +00:00
[mac] move key material update to Init() (#12590)
This commit introduces an `Init()` method to the `Mac` class and moves the invocation of `KeyManager::UpdateKeyMaterial()` from the `Mac` constructor into this new method. `Mac::Init()` is then called from `Instance::AfterInit()`, immediately after `KeyManager` is initialized. This ensures that `KeyManager` and other OpenThread core components are fully constructed and properly initialized before attempting to update the key material. The key material update interacts with `SubMac` to configure the MAC keys. Performing this operation during the `Mac` constructor phase can be problematic because the `KeyManager` (under `OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE`) may not be fully initialized and ready yet.
This commit is contained in:
@@ -433,6 +433,7 @@ void Instance::AfterInit(void)
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
|
||||
Get<KeyManager>().Init();
|
||||
Get<Mac::Mac>().Init();
|
||||
|
||||
// Restore datasets and network information
|
||||
|
||||
|
||||
@@ -115,7 +115,6 @@ Mac::Mac(Instance &aInstance)
|
||||
|
||||
SetEnabled(true);
|
||||
|
||||
Get<KeyManager>().UpdateKeyMaterial();
|
||||
SetPanId(mPanId);
|
||||
SetExtAddress(randomExtAddress);
|
||||
SetShortAddress(GetShortAddress());
|
||||
@@ -126,6 +125,8 @@ Mac::Mac(Instance &aInstance)
|
||||
mMode2KeyMaterial.SetFrom(AsCoreType(&sMode2Key));
|
||||
}
|
||||
|
||||
void Mac::Init(void) { Get<KeyManager>().UpdateKeyMaterial(); }
|
||||
|
||||
void Mac::SetEnabled(bool aEnable)
|
||||
{
|
||||
mEnabled = aEnable;
|
||||
|
||||
@@ -130,6 +130,14 @@ public:
|
||||
*/
|
||||
~Mac(void) { ClearMode2Key(); }
|
||||
|
||||
/**
|
||||
* Initializes the `Mac`.
|
||||
*
|
||||
* This method MUST be called after OpenThread `Instance` is fully initialized (from `Instance::AfterInit()`) and
|
||||
* only after `KeyManager` is also fully initialized.
|
||||
*/
|
||||
void Init(void);
|
||||
|
||||
/**
|
||||
* Starts an IEEE 802.15.4 Active Scan.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user