Skip to content

Commit

Permalink
Revert "Remove SED related common code as it is deprecated and replac…
Browse files Browse the repository at this point in the history
…ed by ICD (project-chip#29023)"

This reverts commit 29fd8dc.
  • Loading branch information
s07641069 committed Sep 14, 2023
1 parent 52caffd commit 546f1b8
Show file tree
Hide file tree
Showing 22 changed files with 503 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
return SL_STATUS_OK;
}

#if SL_ICD_ENABLED
#if CHIP_DEVICE_CONFIG_ENABLE_SED
/******************************************************************
* @fn wfx_rsi_power_save()
* @brief
Expand Down Expand Up @@ -222,7 +222,7 @@ int32_t wfx_rsi_power_save()
SILABS_LOG("Powersave Config Success");
return status;
}
#endif /* SL_ICD_ENABLED */
#endif /* CHIP_DEVICE_CONFIG_ENABLE_SED */

/*************************************************************************************
* @fn static int32_t wfx_wifi_rsi_init(void)
Expand Down
2 changes: 1 addition & 1 deletion examples/pump-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void AppTask::AppTaskMain(void * pvParameter)
appError(err);
}

#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
sAppTask.StartStatusLEDTimer();
#endif

Expand Down
2 changes: 1 addition & 1 deletion examples/window-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void AppTask::AppTaskMain(void * pvParameter)
appError(err);
}

#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
#if !(defined(CHIP_DEVICE_CONFIG_ENABLE_SED) && CHIP_DEVICE_CONFIG_ENABLE_SED)
sAppTask.StartStatusLEDTimer();
#endif

Expand Down
8 changes: 8 additions & 0 deletions src/app/FailSafeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ void FailSafeContext::HandleDisarmFailSafe(intptr_t arg)

void FailSafeContext::SetFailSafeArmed(bool armed)
{
#if CHIP_DEVICE_CONFIG_ENABLE_SED
if (IsFailSafeArmed() != armed)
{
// Per spec, we should be staying in active mode while a fail-safe is
// armed.
DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(armed);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
#if CHIP_CONFIG_ENABLE_ICD_SERVER
if (IsFailSafeArmed() != armed)
{
Expand Down
16 changes: 16 additions & 0 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ void CommissioningWindowManager::ResetState()
mECMIterations = 0;
mECMSaltLength = 0;

#if CHIP_DEVICE_CONFIG_ENABLE_SED
if (mSEDActiveModeEnabled)
{
DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(false);
mSEDActiveModeEnabled = false;
}
#endif

UpdateWindowStatus(CommissioningWindowStatusEnum::kWindowNotOpen);

UpdateOpenerFabricIndex(NullNullable);
Expand Down Expand Up @@ -237,6 +245,14 @@ CHIP_ERROR CommissioningWindowManager::AdvertiseAndListenForPASE()

mPairingSession.Clear();

#if CHIP_DEVICE_CONFIG_ENABLE_SED
if (!mSEDActiveModeEnabled)
{
mSEDActiveModeEnabled = true;
DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(true);
}
#endif

ReturnErrorOnFailure(mServer->GetExchangeManager().RegisterUnsolicitedMessageHandlerForType(
Protocols::SecureChannel::MsgType::PBKDFParamRequest, this));
mListeningForPASE = true;
Expand Down
4 changes: 4 additions & 0 deletions src/app/server/CommissioningWindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ class CommissioningWindowManager : public Messaging::UnsolicitedMessageHandler,
uint32_t mECMSaltLength = 0;
uint8_t mECMSalt[kSpake2p_Max_PBKDF_Salt_Length];

#if CHIP_DEVICE_CONFIG_ENABLE_SED
bool mSEDActiveModeEnabled = false;
#endif

// For tests only, so that we can test the commissioning window timeout
// without having to wait 3 minutes.
Optional<System::Clock::Seconds16> mMinCommissioningTimeoutOverride;
Expand Down
39 changes: 39 additions & 0 deletions src/include/platform/ConnectivityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ class ConnectivityManager
void ResetThreadNetworkDiagnosticsCounts();
CHIP_ERROR WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, app::AttributeValueEncoder & encoder);

// Sleepy end device methods
#if CHIP_DEVICE_CONFIG_ENABLE_SED
CHIP_ERROR GetSEDIntervalsConfig(SEDIntervalsConfig & intervalsConfig);

/**
* Sets Sleepy End Device intervals configuration and posts kSEDIntervalChange event to inform other software
* modules about the change.
*
* @param[in] intervalsConfig intervals configuration to be set
*/
CHIP_ERROR SetSEDIntervalsConfig(const SEDIntervalsConfig & intervalsConfig);

/**
* Requests setting Sleepy End Device active interval on or off.
* Every method call with onOff parameter set to true or false results in incrementing or decrementing the active mode
* consumers counter. Active mode is set if the consumers counter is bigger than 0.
*
* @param[in] onOff true if active mode should be enabled and false otherwise.
*/
CHIP_ERROR RequestSEDActiveMode(bool onOff, bool delayIdle = false);
#endif

CHIP_ERROR SetPollingInterval(System::Clock::Milliseconds32 pollingInterval);

// CHIPoBLE service methods
Expand Down Expand Up @@ -448,6 +470,23 @@ inline CHIP_ERROR ConnectivityManager::SetThreadDeviceType(ThreadDeviceType devi
return static_cast<ImplClass *>(this)->_SetThreadDeviceType(deviceType);
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED
inline CHIP_ERROR ConnectivityManager::GetSEDIntervalsConfig(SEDIntervalsConfig & intervalsConfig)
{
return static_cast<ImplClass *>(this)->_GetSEDIntervalsConfig(intervalsConfig);
}

inline CHIP_ERROR ConnectivityManager::SetSEDIntervalsConfig(const SEDIntervalsConfig & intervalsConfig)
{
return static_cast<ImplClass *>(this)->_SetSEDIntervalsConfig(intervalsConfig);
}

inline CHIP_ERROR ConnectivityManager::RequestSEDActiveMode(bool onOff, bool delayIdle)
{
return static_cast<ImplClass *>(this)->_RequestSEDActiveMode(onOff, delayIdle);
}
#endif

inline CHIP_ERROR ConnectivityManager::SetPollingInterval(System::Clock::Milliseconds32 pollingInterval)
{
#if CHIP_CONFIG_ENABLE_ICD_SERVER
Expand Down
37 changes: 37 additions & 0 deletions src/include/platform/ThreadStackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ class ThreadStackManager
ConnectivityManager::ThreadDeviceType GetThreadDeviceType();
CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole);

#if CHIP_DEVICE_CONFIG_ENABLE_SED
CHIP_ERROR GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig);

/**
* Sets Sleepy End Device intervals configuration and posts kICDPollingIntervalChange event to inform other software
* modules about the change.
*
* @param[in] intervalsConfig intervals configuration to be set
*/
CHIP_ERROR SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig);

/**
* Requests setting Sleepy End Device active interval on or off.
* Every method call with onOff parameter set to true or false results in incrementing or decrementing the active mode
* consumers counter. Active mode is set if the consumers counter is bigger than 0.
*
* @param[in] onOff true if active mode should be enabled and false otherwise.
*/
CHIP_ERROR RequestSEDActiveMode(bool onOff, bool delayIdle = false);
#endif
#if CHIP_CONFIG_ENABLE_ICD_SERVER
CHIP_ERROR SetPollingInterval(System::Clock::Milliseconds32 pollingInterval);
#endif
Expand Down Expand Up @@ -373,6 +393,23 @@ inline CHIP_ERROR ThreadStackManager::SetThreadDeviceType(ConnectivityManager::T
return static_cast<ImplClass *>(this)->_SetThreadDeviceType(deviceType);
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED
inline CHIP_ERROR ThreadStackManager::GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig)
{
return static_cast<ImplClass *>(this)->_GetSEDIntervalsConfig(intervalsConfig);
}

inline CHIP_ERROR ThreadStackManager::SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig)
{
return static_cast<ImplClass *>(this)->_SetSEDIntervalsConfig(intervalsConfig);
}

inline CHIP_ERROR ThreadStackManager::RequestSEDActiveMode(bool onOff, bool delayIdle)
{
return static_cast<ImplClass *>(this)->_RequestSEDActiveMode(onOff, delayIdle);
}
#endif

#if CHIP_CONFIG_ENABLE_ICD_SERVER
inline CHIP_ERROR ThreadStackManager::SetPollingInterval(System::Clock::Milliseconds32 pollingInterval)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class GenericConnectivityManagerImpl_Thread
bool _IsThreadApplicationControlled();
ConnectivityManager::ThreadDeviceType _GetThreadDeviceType();
CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType);
#if CHIP_DEVICE_CONFIG_ENABLE_SED
CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig);
CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig);
CHIP_ERROR _RequestSEDActiveMode(bool onOff, bool delayIdle = false);
#endif
#if CHIP_CONFIG_ENABLE_ICD_SERVER
CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval);
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */
Expand Down Expand Up @@ -139,6 +144,28 @@ GenericConnectivityManagerImpl_Thread<ImplClass>::_SetThreadDeviceType(Connectiv
return ThreadStackMgrImpl().SetThreadDeviceType(deviceType);
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED
template <class ImplClass>
inline CHIP_ERROR
GenericConnectivityManagerImpl_Thread<ImplClass>::_GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig)
{
return ThreadStackMgrImpl().GetSEDIntervalsConfig(intervalsConfig);
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_Thread<ImplClass>::_SetSEDIntervalsConfig(
const ConnectivityManager::SEDIntervalsConfig & intervalsConfig)
{
return ThreadStackMgrImpl().SetSEDIntervalsConfig(intervalsConfig);
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_Thread<ImplClass>::_RequestSEDActiveMode(bool onOff, bool delayIdle)
{
return ThreadStackMgrImpl().RequestSEDActiveMode(onOff, delayIdle);
}
#endif

#if CHIP_CONFIG_ENABLE_ICD_SERVER
template <class ImplClass>
inline CHIP_ERROR
Expand Down
48 changes: 48 additions & 0 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,45 @@ void ExchangeContext::SetResponseTimeout(Timeout timeout)
mResponseTimeout = timeout;
}

#if CONFIG_DEVICE_LAYER && CHIP_DEVICE_CONFIG_ENABLE_SED
void ExchangeContext::UpdateSEDIntervalMode()
{
if (!HasSessionHandle())
{
// After the session has been deleted, no further communication can occur on the exchange,
// so withdraw a SED active mode request.
UpdateSEDIntervalMode(false);
return;
}

Transport::PeerAddress address;

switch (GetSessionHandle()->GetSessionType())
{
case Transport::Session::SessionType::kSecure:
address = GetSessionHandle()->AsSecureSession()->GetPeerAddress();
break;
case Transport::Session::SessionType::kUnauthenticated:
address = GetSessionHandle()->AsUnauthenticatedSession()->GetPeerAddress();
break;
default:
return;
}

VerifyOrReturn(address.GetTransportType() != Transport::Type::kBle);
UpdateSEDIntervalMode(IsResponseExpected() || IsSendExpected() || IsMessageNotAcked());
}

void ExchangeContext::UpdateSEDIntervalMode(bool activeMode)
{
if (activeMode != IsRequestingActiveMode())
{
SetRequestingActiveMode(activeMode);
DeviceLayer::ConnectivityMgr().RequestSEDActiveMode(activeMode, true);
}
}
#endif

CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgType, PacketBufferHandle && msgBuf,
const SendFlags & sendFlags)
{
Expand Down Expand Up @@ -361,6 +400,11 @@ ExchangeContext::~ExchangeContext()
//
VerifyOrDie(mFlags.Has(Flags::kFlagClosed));

#if CONFIG_DEVICE_LAYER && CHIP_DEVICE_CONFIG_ENABLE_SED
// Make sure that the exchange withdraws the request for Sleepy End Device active mode.
UpdateSEDIntervalMode(false);
#endif

// Ideally, in this scenario, the retransmit table should
// be clear of any outstanding messages for this context and
// the boolean parameter passed to DoClose() should not matter.
Expand Down Expand Up @@ -644,6 +688,10 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload

void ExchangeContext::MessageHandled()
{
#if CONFIG_DEVICE_LAYER && CHIP_DEVICE_CONFIG_ENABLE_SED
UpdateSEDIntervalMode();
#endif

if (mFlags.Has(Flags::kFlagClosed) || IsResponseExpected() || IsSendExpected())
{
return;
Expand Down
7 changes: 7 additions & 0 deletions src/messaging/ReliableMessageMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ System::Clock::Timestamp ReliableMessageMgr::GetBackoff(System::Clock::Timestamp
// "An ICD sender SHOULD increase t to also account for its own sleepy interval
// required to receive the acknowledgment"
mrpBackoffTime += app::ICDManager::GetFastPollingInterval();
#elif CHIP_DEVICE_CONFIG_ENABLE_SED
DeviceLayer::ConnectivityManager::SEDIntervalsConfig sedIntervals;

if (DeviceLayer::ConnectivityMgr().GetSEDIntervalsConfig(sedIntervals) == CHIP_NO_ERROR)
{
mrpBackoffTime += System::Clock::Timestamp(sedIntervals.ActiveIntervalMS);
}
#endif

mrpBackoffTime += CHIP_CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST;
Expand Down
10 changes: 10 additions & 0 deletions src/messaging/ReliableMessageProtocolConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ Optional<ReliableMessageProtocolConfig> GetLocalMRPConfig()
config.mIdleRetransTimeout += app::ICDManager::GetSlowPollingInterval();
config.mActiveRetransTimeout += app::ICDManager::GetFastPollingInterval();
config.mActiveThresholdTime = System::Clock::Milliseconds16(IcdManagementServer::GetInstance().GetActiveModeThreshold());
#elif CHIP_DEVICE_CONFIG_ENABLE_SED
DeviceLayer::ConnectivityManager::SEDIntervalsConfig sedIntervalsConfig;

if (DeviceLayer::ConnectivityMgr().GetSEDIntervalsConfig(sedIntervalsConfig) == CHIP_NO_ERROR)
{
// Increase local MRP retry intervals by SED intervals. That is, intervals for
// which the device can be at sleep and not be able to receive any messages).
config.mIdleRetransTimeout += sedIntervalsConfig.IdleIntervalMS;
config.mActiveRetransTimeout += sedIntervalsConfig.ActiveIntervalMS;
}
#endif

#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
Expand Down
26 changes: 26 additions & 0 deletions src/platform/Linux/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,32 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadDeviceType(ConnectivityManager::Thr
return CHIP_NO_ERROR;
}

#if CHIP_DEVICE_CONFIG_ENABLE_SED
CHIP_ERROR ThreadStackManagerImpl::_GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig)
{
(void) intervalsConfig;

ChipLogError(DeviceLayer, "SED intervals config is not supported on linux");
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR ThreadStackManagerImpl::_SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig)
{
(void) intervalsConfig;

ChipLogError(DeviceLayer, "SED intervals config is not supported on linux");
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR ThreadStackManagerImpl::_RequestSEDActiveMode(bool onOff, bool delayIdle)
{
(void) onOff;
(void) delayIdle;

ChipLogError(DeviceLayer, "SED intervals config is not supported on linux");
return CHIP_ERROR_NOT_IMPLEMENTED;
}
#endif
#if CHIP_CONFIG_ENABLE_ICD_SERVER
CHIP_ERROR ThreadStackManagerImpl::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval)
{
Expand Down
5 changes: 5 additions & 0 deletions src/platform/Linux/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class ThreadStackManagerImpl : public ThreadStackManager

CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType);

#if CHIP_DEVICE_CONFIG_ENABLE_SED
CHIP_ERROR _GetSEDIntervalsConfig(ConnectivityManager::SEDIntervalsConfig & intervalsConfig);
CHIP_ERROR _SetSEDIntervalsConfig(const ConnectivityManager::SEDIntervalsConfig & intervalsConfig);
CHIP_ERROR _RequestSEDActiveMode(bool onOff, bool delayIdle = false);
#endif
#if CHIP_CONFIG_ENABLE_ICD_SERVER
CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval);
#endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */
Expand Down
Loading

0 comments on commit 546f1b8

Please sign in to comment.