From cb2a7800d7cc5fb71f2e28dd8d0d3d74f8e2ba6d Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 23 Mar 2018 15:12:15 -0700 Subject: [PATCH] [key-manager] set default key from KeyManager (#2636) This commit moves the setting/initialization of default key from `ThreadNetif` to `KeyManager` class. --- src/core/thread/key_manager.cpp | 21 +++++++++++++++++++++ src/core/thread/thread_netif.cpp | 20 -------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index 490549ac4..d56245cb8 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -47,8 +47,28 @@ static const uint8_t kThreadString[] = { 'T', 'h', 'r', 'e', 'a', 'd', }; +static const otMasterKey kDefaultMasterKey = {{ + 0x00, + 0x11, + 0x22, + 0x33, + 0x44, + 0x55, + 0x66, + 0x77, + 0x88, + 0x99, + 0xaa, + 0xbb, + 0xcc, + 0xdd, + 0xee, + 0xff, +}}; + KeyManager::KeyManager(Instance &aInstance) : InstanceLocator(aInstance) + , mMasterKey(kDefaultMasterKey) , mKeySequence(0) , mMacFrameCounter(0) , mMleFrameCounter(0) @@ -62,6 +82,7 @@ KeyManager::KeyManager(Instance &aInstance) , mKekFrameCounter(0) , mSecurityPolicyFlags(0xff) { + ComputeKey(mKeySequence, mKey); } void KeyManager::Start(void) diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 1912c9656..9e6df942e 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -49,25 +49,6 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { -static const otMasterKey kThreadMasterKey = {{ - 0x00, - 0x11, - 0x22, - 0x33, - 0x44, - 0x55, - 0x66, - 0x77, - 0x88, - 0x99, - 0xaa, - 0xbb, - 0xcc, - 0xdd, - 0xee, - 0xff, -}}; - ThreadNetif::ThreadNetif(Instance &aInstance) : Netif(aInstance, OT_NETIF_INTERFACE_ID_THREAD) , mCoap(aInstance) @@ -123,7 +104,6 @@ ThreadNetif::ThreadNetif(Instance &aInstance) , mEnergyScan(aInstance) { - mKeyManager.SetMasterKey(kThreadMasterKey); mCoap.SetInterceptor(&ThreadNetif::TmfFilter, this); }