Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into minor-editorial-f…
Browse files Browse the repository at this point in the history
…abrictable
  • Loading branch information
tcarmelveilleux committed Jun 10, 2022
2 parents 9e2483b + d1d5ca8 commit 6ed3c41
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
.environment/gn_out/.ninja_log
.environment/pigweed-venv/*.log
- name: Build Apps
timeout-minutes: 30
timeout-minutes: 45
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py \
Expand Down
90 changes: 90 additions & 0 deletions examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/clusters/software-diagnostics-server/software-diagnostics-server.h>
#include <app/clusters/switch-server/switch-server.h>
#include <app/server/Server.h>
#include <app/util/af.h>
#include <lib/support/CHIPMem.h>
Expand Down Expand Up @@ -147,6 +148,52 @@ void HandleGeneralFaultEvent(intptr_t arg)
}
}

/**
* Should be called when a switch operation takes place on the Node.
*/
void HandleSwitchEvent(intptr_t arg)
{
uint32_t eventId = static_cast<uint32_t>(arg);

EndpointId endpoint = 1;
uint8_t newPosition = 20;
uint8_t previousPosition = 10;
uint8_t count = 3;

if (eventId == Clusters::Switch::Events::SwitchLatched::Id)
{
Clusters::SwitchServer::Instance().OnSwitchLatch(endpoint, newPosition);
}
else if (eventId == Clusters::Switch::Events::InitialPress::Id)
{
Clusters::SwitchServer::Instance().OnInitialPress(endpoint, newPosition);
}
else if (eventId == Clusters::Switch::Events::LongPress::Id)
{
Clusters::SwitchServer::Instance().OnLongPress(endpoint, newPosition);
}
else if (eventId == Clusters::Switch::Events::ShortRelease::Id)
{
Clusters::SwitchServer::Instance().OnShortRelease(endpoint, previousPosition);
}
else if (eventId == Clusters::Switch::Events::LongRelease::Id)
{
Clusters::SwitchServer::Instance().OnLongRelease(endpoint, previousPosition);
}
else if (eventId == Clusters::Switch::Events::MultiPressOngoing::Id)
{
Clusters::SwitchServer::Instance().OnMultiPressOngoing(endpoint, newPosition, count);
}
else if (eventId == Clusters::Switch::Events::MultiPressComplete::Id)
{
Clusters::SwitchServer::Instance().OnMultiPressComplete(endpoint, newPosition, count);
}
else
{
ChipLogError(DeviceLayer, "Unknow event ID:%d", eventId);
}
}

// when the shell is enabled, don't intercept signals since it prevents the user from
// using expected commands like CTRL-C to quit the application. (see issue #17845)
// We should stop using signals for those faults, and move to a different notification
Expand Down Expand Up @@ -223,6 +270,42 @@ void OnGeneralFaultSignalHandler(int signum)
PlatformMgr().ScheduleWork(HandleGeneralFaultEvent, static_cast<intptr_t>(eventId));
}

void OnSwitchSignalHandler(int signum)
{
ChipLogDetail(DeviceLayer, "Caught signal %d", signum);

uint32_t eventId;
switch (signum)
{
case SIGTSTP:
eventId = Clusters::Switch::Events::SwitchLatched::Id;
break;
case SIGSTOP:
eventId = Clusters::Switch::Events::InitialPress::Id;
break;
case SIGTTOU:
eventId = Clusters::Switch::Events::LongPress::Id;
break;
case SIGWINCH:
eventId = Clusters::Switch::Events::ShortRelease::Id;
break;
case SIGQUIT:
eventId = Clusters::Switch::Events::LongRelease::Id;
break;
case SIGFPE:
eventId = Clusters::Switch::Events::MultiPressOngoing::Id;
break;
case SIGPIPE:
eventId = Clusters::Switch::Events::MultiPressComplete::Id;
break;
default:
ChipLogError(NotSpecified, "Unhandled signal: Should never happens");
chipDie();
break;
}

PlatformMgr().ScheduleWork(HandleSwitchEvent, static_cast<intptr_t>(eventId));
}
void SetupSignalHandlers()
{
// sigaction is not used here because Tsan interceptors seems to
Expand All @@ -238,6 +321,13 @@ void SetupSignalHandlers()
signal(SIGUSR2, OnGeneralFaultSignalHandler);
signal(SIGHUP, OnGeneralFaultSignalHandler);
signal(SIGTTIN, OnGeneralFaultSignalHandler);
signal(SIGTSTP, OnSwitchSignalHandler);
signal(SIGSTOP, OnSwitchSignalHandler);
signal(SIGTTOU, OnSwitchSignalHandler);
signal(SIGWINCH, OnSwitchSignalHandler);
signal(SIGQUIT, OnSwitchSignalHandler);
signal(SIGFPE, OnSwitchSignalHandler);
signal(SIGPIPE, OnSwitchSignalHandler);
}
#endif // !defined(ENABLE_CHIP_SHELL)

Expand Down
43 changes: 43 additions & 0 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <app/server/AppDelegate.h>
#include <app/server/CommissioningWindowManager.h>
#include <app/server/DefaultAclStorage.h>
#include <credentials/CertificateValidityPolicy.h>
#include <credentials/FabricTable.h>
#include <credentials/GroupDataProvider.h>
#include <credentials/GroupDataProviderImpl.h>
Expand Down Expand Up @@ -118,6 +119,42 @@ struct ServerInitParams
Crypto::OperationalKeystore * operationalKeystore = nullptr;
};

class IgnoreCertificateValidityPolicy : public Credentials::CertificateValidityPolicy
{
public:
IgnoreCertificateValidityPolicy() {}

/**
* @brief
*
* This certificate validity policy does not validate NotBefore or
* NotAfter to accommodate platforms that may have wall clock time, but
* where it is unreliable.
*
* Last Known Good Time is also not considered in this policy.
*
* @param cert CHIP Certificate for which we are evaluating validity
* @param depth the depth of the certificate in the chain, where the leaf is at depth 0
* @return CHIP_NO_ERROR if CHIPCert should accept the certificate; an appropriate CHIP_ERROR if it should be rejected
*/
CHIP_ERROR ApplyCertificateValidityPolicy(const Credentials::ChipCertificateData * cert, uint8_t depth,
Credentials::CertificateValidityResult result) override
{
switch (result)
{
case Credentials::CertificateValidityResult::kValid:
case Credentials::CertificateValidityResult::kNotYetValid:
case Credentials::CertificateValidityResult::kExpired:
case Credentials::CertificateValidityResult::kNotExpiredAtLastKnownGoodTime:
case Credentials::CertificateValidityResult::kExpiredAtLastKnownGoodTime:
case Credentials::CertificateValidityResult::kTimeUnknown:
return CHIP_NO_ERROR;
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
}
};

/**
* Transitional version of ServerInitParams to assist SDK integrators in
* transitioning to injecting product/platform-owned resources. This version
Expand Down Expand Up @@ -167,6 +204,8 @@ struct CommonCaseDeviceServerInitParams : public ServerInitParams
static chip::KvsPersistentStorageDelegate sKvsPersistenStorageDelegate;
static chip::PersistentStorageOperationalKeystore sPersistentStorageOperationalKeystore;
static chip::Credentials::GroupDataProviderImpl sGroupDataProvider;
static IgnoreCertificateValidityPolicy sDefaultCertValidityPolicy;

#if CHIP_CONFIG_ENABLE_SESSION_RESUMPTION
static chip::SimpleSessionResumptionStorage sSessionResumptionStorage;
#endif
Expand Down Expand Up @@ -208,6 +247,10 @@ struct CommonCaseDeviceServerInitParams : public ServerInitParams
// Inject ACL storage. (Don't initialize it.)
this->aclStorage = &sAclStorage;

// Inject certificate validation policy compatible with non-wall-clock-time-synced
// embedded systems.
this->certificateValidityPolicy = &sDefaultCertValidityPolicy;

return CHIP_NO_ERROR;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/suites/commands/log/LogCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CHIP_ERROR LogCommands::UserPrompt(const char * identity,
{
std::string line;
std::getline(std::cin, line);
if (line != value.expectedValue.Value().data())
if (line != std::string(value.expectedValue.Value().data(), value.expectedValue.Value().size()))
{
return ContinueOnChipMainThread(CHIP_ERROR_INVALID_ARGUMENT);
}
Expand Down
8 changes: 8 additions & 0 deletions src/platform/Ameba/SystemTimeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Milliseconds64 ClockImpl::GetMonotonicMilliseconds64(void)

CHIP_ERROR ClockImpl::GetClock_RealTime(Clock::Microseconds64 & curTime)
{
// TODO(19081): This platform does not properly error out if wall clock has
// not been set. For now, short circuit this.
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
#if 0
time_t seconds;
struct rtkTimeVal tv;

Expand All @@ -78,6 +82,7 @@ CHIP_ERROR ClockImpl::GetClock_RealTime(Clock::Microseconds64 & curTime)
curTime = Microseconds64((static_cast<uint64_t>(tv.tv_sec) * UINT64_C(1000000)) + static_cast<uint64_t>(tv.tv_usec));

return CHIP_NO_ERROR;
#endif
}

CHIP_ERROR ClockImpl::GetClock_RealTimeMS(Milliseconds64 & aCurTime)
Expand Down Expand Up @@ -105,6 +110,9 @@ CHIP_ERROR InitClock_RealTime()
Clock::Microseconds64((static_cast<uint64_t>(CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD) * UINT64_C(1000000)));
// Use CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD as the initial value of RealTime.
// Then the RealTime obtained from GetClock_RealTime will be always valid.
//
// TODO(19081): This is broken because it causes the platform to report
// that it does have wall clock time when it actually doesn't.
return System::SystemClock().SetClock_RealTime(curTime);
}

Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/SystemTimeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ CHIP_ERROR ClockImpl::GetClock_RealTime(Microseconds64 & aCurTime)
// TODO(19081): This platform does not properly error out if wall clock has
// not been set. For now, short circuit this.
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
#if 0
struct timeval tv;
if (gettimeofday(&tv, nullptr) != 0)
{
Expand All @@ -69,6 +70,7 @@ CHIP_ERROR ClockImpl::GetClock_RealTime(Microseconds64 & aCurTime)
static_assert(CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD >= 0, "We might be letting through negative tv_sec values!");
aCurTime = Microseconds64((static_cast<uint64_t>(tv.tv_sec) * UINT64_C(1000000)) + static_cast<uint64_t>(tv.tv_usec));
return CHIP_NO_ERROR;
#endif
}

CHIP_ERROR ClockImpl::GetClock_RealTimeMS(Milliseconds64 & aCurTime)
Expand Down
8 changes: 8 additions & 0 deletions src/platform/FreeRTOS/SystemTimeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ uint64_t GetClock_MonotonicHiRes(void)

CHIP_ERROR ClockImpl::GetClock_RealTime(Clock::Microseconds64 & aCurTime)
{
// TODO(19081): This platform does not properly error out if wall clock has
// not been set. For now, short circuit this.
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
#if 0
if (sBootTimeUS == 0)
{
return CHIP_ERROR_REAL_TIME_NOT_SYNCED;
}
aCurTime = Clock::Microseconds64(sBootTimeUS + GetClock_Monotonic());
return CHIP_NO_ERROR;
#endif
}

CHIP_ERROR ClockImpl::GetClock_RealTimeMS(Clock::Milliseconds64 & aCurTime)
Expand Down Expand Up @@ -157,6 +162,9 @@ CHIP_ERROR InitClock_RealTime()
Clock::Microseconds64((static_cast<uint64_t>(CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD) * UINT64_C(1000000)));
// Use CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD as the initial value of RealTime.
// Then the RealTime obtained from GetClock_RealTime will be always valid.
//
// TODO(19081): This is broken because it causes the platform to report
// that it does have wall clock time when it actually doesn't.
return System::SystemClock().SetClock_RealTime(curTime);
}

Expand Down
8 changes: 8 additions & 0 deletions src/platform/mbed/SystemTimeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ Milliseconds64 ClockImpl::GetMonotonicMilliseconds64()

CHIP_ERROR ClockImpl::GetClock_RealTime(Microseconds64 & aCurTime)
{
// TODO(19081): This platform does not properly error out if wall clock has
// not been set. For now, short circuit this.
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
#if 0
struct timeval tv;
if (gettimeofday(&tv, nullptr) != 0)
{
Expand All @@ -89,6 +93,7 @@ CHIP_ERROR ClockImpl::GetClock_RealTime(Microseconds64 & aCurTime)
static_assert(CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD >= 0, "We might be letting through negative tv_sec values!");
aCurTime = Microseconds64((static_cast<uint64_t>(tv.tv_sec) * UINT64_C(1000000)) + static_cast<uint64_t>(tv.tv_usec));
return CHIP_NO_ERROR;
#endif
}

CHIP_ERROR ClockImpl::GetClock_RealTimeMS(Milliseconds64 & aCurTime)
Expand Down Expand Up @@ -124,6 +129,9 @@ CHIP_ERROR InitClock_RealTime()
Clock::Microseconds64((static_cast<uint64_t>(CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD) * UINT64_C(1000000)));
// Use CHIP_SYSTEM_CONFIG_VALID_REAL_TIME_THRESHOLD as the initial value of RealTime.
// Then the RealTime obtained from GetClock_RealTime will be always valid.
//
// TODO(19081): This is broken because it causes the platform to report
// that it does have wall clock time when it actually doesn't.
return System::SystemClock().SetClock_RealTime(curTime);
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocols/interaction_model/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace InteractionModel {
constexpr uint16_t kVersion = 0;

/**
* SecureChannel Protocol Message Types
* Interaction Model Protocol Message Types
*/
enum class MsgType : uint8_t
{
Expand Down

0 comments on commit 6ed3c41

Please sign in to comment.