Skip to content

Commit

Permalink
time synchronization cluster (#26082)
Browse files Browse the repository at this point in the history
* update time sync cluster XML based on updated spec

added attribute access interface handled attributes

GNSS

Co-authored-by: Boris Zbarsky <[email protected]>

TrustedTimeSource is optional with TSC feature

Co-authored-by: Boris Zbarsky <[email protected]>

SetUTCTime

Co-authored-by: Boris Zbarsky <[email protected]>

SetTrustedTimeSource is optional

Co-authored-by: Boris Zbarsky <[email protected]>

UTCTime

Co-authored-by: Boris Zbarsky <[email protected]>

TimeZoneDatabase default 2 (None)
MissingTrustedTimeSource is optional

regenerate code

update default values

* update time sync cluster XML based on updated spec

* added attribute access interface handled attributes

* GNSS

Co-authored-by: Boris Zbarsky <[email protected]>

* TrustedTimeSource is optional with TSC feature

Co-authored-by: Boris Zbarsky <[email protected]>

* SetUTCTime

Co-authored-by: Boris Zbarsky <[email protected]>

* SetTrustedTimeSource is optional

Co-authored-by: Boris Zbarsky <[email protected]>

* UTCTime

Co-authored-by: Boris Zbarsky <[email protected]>

* TimeZoneDatabase default 2 (None)
MissingTrustedTimeSource is optional

* regenerate code

* update default values

* updated time-synchronization cluster definition based on PR #6352

add Time Synchronization cluster in all-clusters-app, controller-app and light-switch-app zap and regenerate all

remove constraint from a single element attribute

first code commit

initialize timezone and trustedtimesource to 0 and null

added statuscode and changed to fabricIndex

regenerate zap

use time sync server code

set default zap setting to external for complex time sync attributes

add endpoint to trustedtimesourcestruct and set command for it

regenerate

using updated trustedtimesourcestruct

update time sync xml definition

update zap files

regenerate

added persistent data provider for time sync cluster

added new commands based on PR #6353

added test template for TimeSyncDataProvider

changed command arguments to list type

regenerate

update SetTrustedTimeSource definition

regenerate

use consistent data types of attributes

user CHIP_CONFIG to set size of lists

clean up read handler

adde TSC feature and change attribute ids

include time sync related resource for build

regenerate after changing attribute ids and adding time sync client feature

reorganize code and implement defaultNTP handlers

handle span data the right way
improved overall implementation

change default time zone list size to 1

made settrustedtimesource command to be fabric scoped

update time sync cluster definition based on latest PR merges

regenerate and changes related to attribute names and access

setdefaultntp parameter is nullable

implemented setdefaultntp

changed the id of settimezoneresponse command to the current in spec

removed curly brace that sneaked in to previous commits

ValidUntil of DSTOffsetStruct is nullable

added basic rules of operation in comment/psuedo-code

added DSTOffsetActive predicate for DSTStatus event

fixed clang compiler errors

added skeleton delegate implementation for time sync

use delegate placeholder and implemented events

clean up usage of namespaces

seems like unused code

skleton verifiers for NTP address

moved init from header

removed conflicting generated files

regenerate all

enum now starts at 0, name field is optional in timezonestatus event

force external storage for UTCTime and LocalTime attributes

moved time sync cluster code to cpp file
added mechanism to track real size of list data
removed custom encoder for TimeZone attribute
changed TimeZone list size to 2 for better testing behavior
addressed multiple PR comments

improved defaultNTP implementation and storage usage
cleaned up return usage

changed time logic to be able to set older time but not old than default LastKnownTime

ignore attribute storage values for sizes with F quality

resolve rebase conflicts

some random generated code that needs to be there

use consistent data types

changes based on CI failures

TrustedTimeSource is not a list

fixed response behavior of setttimezone command

missed generated code

* added SupportsDNSResolve attribute and corrected featuremap value

* code improvements

* truncate span size to actual data when retreiving defaultNTP
wrote test for time sync persistent storage

* bring back section removed by rebase

Signed-off-by: Fesseha <[email protected]>

* fix CI error do not use 'else' after 'return'

* updated descriptor cluster test to include time sync server

* added mechanisms to get local time and set utc time from application

* regenerate after merge to master and fix missed server implementation reference

* added CI test for time sync cluster

* improved time zone and dst offset attributes validation,
skeleton functions for validating and purging time zone and dst offset,
made dst offset list size to 2 for testing purposes

* logic to purge expired time zone and dst offset

* set default value for time zone attribute

* use AttributeAccessInterface for Granularity attribute

* UTCTime is in chipepoch and not unixepoch

* localtime should be null if dstoffset is empty

* regen after merge to master

* update feature map attribute name
validate offset in timezone
bring back merge removed code in CHIPConfig.h

* use static_cast instead

* cast the whole thing since the operator is causing int usage

* timezone always has a default UTC zone

* improved handling of setting empty lists

* run restyler

* update external hanlded attributes in ZAP files

* update tests and remove dstoffset sorting on server side

* update yaml test and generate code
fix type error

* use TLV size estimator

* addressed a bunch of PR comments

* declare attributes handled by AAI

* Update src/app/clusters/time-synchronization-server/TimeSyncDataProvider.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* added mechanism to better track when events shall be emitted

* address PR comments

Co-authored-by: Boris Zbarsky <[email protected]>

* typo changes

* Revert parts of "address PR comments"

This reverts commit e2a2f10.

* clean up time sync persistent storage interface

* error if list sizes are not correct

* addressed PR comments

* rename default delegate implementation

* few more improvements based on PR comments

* changed time zone stuct, improved tests, fixed local time calculation overflow and more PR comments fix

* restyle, use DSTOffsetobj with size element, improved error response in few instances, and some more minor tweaks

* replace list with span, not sure if it is needed

* update dstoffset NL test

* cleaned up for loop indexes, catch dst validUntil expiring, nullable localtime, generate dst table empty event correctly

* disabled darwin time sync SDK test

* change indexer to size_t type

* validate NTP addresses in default delegate and few more improvements


Co-authored-by: C Freeman <[email protected]>

* fixed few overflow potentials, lots of minor improvements

* fix uninitialized corner case and update NL tests

* apply restyle patch

* another restyle patch

* return tz and dst lists by reference, fixed based on TC_TIMESYNC results

* apply restyler patch

* fix readability-else-after-return

* kickout all DST items if they are all in the past

* use const and reference whenever possible

---------

Signed-off-by: Fesseha <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: C Freeman <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Jan 9, 2024
1 parent 512d1df commit d7bbd5e
Show file tree
Hide file tree
Showing 32 changed files with 4,061 additions and 136 deletions.
166 changes: 166 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,146 @@ server cluster EthernetNetworkDiagnostics = 55 {
command ResetCounts(): DefaultSuccess = 0;
}

/** Accurate time is required for a number of reasons, including scheduling, display and validating security materials. */
server cluster TimeSynchronization = 56 {
enum GranularityEnum : ENUM8 {
kNoTimeGranularity = 0;
kMinutesGranularity = 1;
kSecondsGranularity = 2;
kMillisecondsGranularity = 3;
kMicrosecondsGranularity = 4;
}

enum StatusCode : ENUM8 {
kTimeNotAccepted = 2;
}

enum TimeSourceEnum : ENUM8 {
kNone = 0;
kUnknown = 1;
kAdmin = 2;
kNodeTimeCluster = 3;
kNonMatterSNTP = 4;
kNonMatterNTP = 5;
kMatterSNTP = 6;
kMatterNTP = 7;
kMixedNTP = 8;
kNonMatterSNTPNTS = 9;
kNonMatterNTPNTS = 10;
kMatterSNTPNTS = 11;
kMatterNTPNTS = 12;
kMixedNTPNTS = 13;
kCloudSource = 14;
kPTP = 15;
kGNSS = 16;
}

enum TimeZoneDatabaseEnum : ENUM8 {
kFull = 0;
kPartial = 1;
kNone = 2;
}

bitmap Feature : BITMAP32 {
kTimeZone = 0x1;
kNTPClient = 0x2;
kNTPServer = 0x4;
kTimeSyncClient = 0x8;
}

struct DSTOffsetStruct {
int32s offset = 0;
epoch_us validStarting = 1;
nullable epoch_us validUntil = 2;
}

struct FabricScopedTrustedTimeSourceStruct {
node_id nodeID = 0;
endpoint_no endpoint = 1;
}

struct TimeZoneStruct {
int32s offset = 0;
epoch_us validAt = 1;
optional char_string<64> name = 2;
}

struct TrustedTimeSourceStruct {
fabric_idx fabricIndex = 0;
node_id nodeID = 1;
endpoint_no endpoint = 2;
}

info event DSTTableEmpty = 0 {
}

info event DSTStatus = 1 {
boolean DSTOffsetActive = 0;
}

info event TimeZoneStatus = 2 {
INT32S offset = 0;
optional CHAR_STRING name = 1;
}

info event TimeFailure = 3 {
}

info event MissingTrustedTimeSource = 4 {
}

readonly attribute nullable epoch_us UTCTime = 0;
readonly attribute GranularityEnum granularity = 1;
readonly attribute TimeSourceEnum timeSource = 2;
readonly attribute nullable TrustedTimeSourceStruct trustedTimeSource = 3;
readonly attribute nullable char_string<128> defaultNTP = 4;
readonly attribute TimeZoneStruct timeZone[] = 5;
readonly attribute DSTOffsetStruct DSTOffset[] = 6;
readonly attribute nullable epoch_us localTime = 7;
readonly attribute TimeZoneDatabaseEnum timeZoneDatabase = 8;
readonly attribute int8u timeZoneListMaxSize = 10;
readonly attribute int8u DSTOffsetListMaxSize = 11;
readonly attribute boolean supportsDNSResolve = 12;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct SetUTCTimeRequest {
epoch_us UTCTime = 0;
GranularityEnum granularity = 1;
optional TimeSourceEnum timeSource = 2;
}

request struct SetTrustedTimeSourceRequest {
nullable FabricScopedTrustedTimeSourceStruct trustedTimeSource = 0;
}

request struct SetTimeZoneRequest {
TimeZoneStruct timeZone[] = 0;
}

request struct SetDSTOffsetRequest {
DSTOffsetStruct DSTOffset[] = 0;
}

request struct SetDefaultNTPRequest {
nullable CHAR_STRING<128> defaultNTP = 0;
}

response struct SetTimeZoneResponse = 3 {
boolean DSTOffsetRequired = 0;
}

command access(invoke: administer) SetUTCTime(SetUTCTimeRequest): DefaultSuccess = 0;
fabric command access(invoke: administer) SetTrustedTimeSource(SetTrustedTimeSourceRequest): DefaultSuccess = 1;
command access(invoke: manage) SetTimeZone(SetTimeZoneRequest): SetTimeZoneResponse = 2;
command access(invoke: manage) SetDSTOffset(SetDSTOffsetRequest): DefaultSuccess = 4;
command access(invoke: administer) SetDefaultNTP(SetDefaultNTPRequest): DefaultSuccess = 5;
}

/** This cluster exposes interactions with a switch device, for the purpose of using those interactions by other devices.
Two types of switch devices are supported: latching switch (e.g. rocker switch) and momentary switch (e.g. push button), distinguished with their feature flags.
Interactions with the switch device are exposed as attributes (for the latching switch) and as events (for both types of switches). An interested party MAY subscribe to these attributes/events and thus be informed of the interactions, and can perform actions based on this, for example by sending commands to perform an action such as controlling a light or a window shade. */
Expand Down Expand Up @@ -5929,6 +6069,32 @@ endpoint 0 {
ram attribute clusterRevision default = 1;
}

server cluster TimeSynchronization {
emits event DSTTableEmpty;
emits event DSTStatus;
emits event TimeZoneStatus;
emits event TimeFailure;
emits event MissingTrustedTimeSource;
callback attribute UTCTime;
callback attribute granularity default = 0x00;
ram attribute timeSource default = 0x00;
callback attribute trustedTimeSource;
callback attribute defaultNTP;
callback attribute timeZone default = 1;
callback attribute DSTOffset;
callback attribute localTime default = 1;
ram attribute timeZoneDatabase default = 0;
callback attribute timeZoneListMaxSize default = 3;
callback attribute DSTOffsetListMaxSize;
ram attribute supportsDNSResolve default = false;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0x0B;
ram attribute clusterRevision default = 2;
}

server cluster AdministratorCommissioning {
callback attribute windowStatus default = 0;
callback attribute adminFabricIndex default = 1;
Expand Down
Loading

0 comments on commit d7bbd5e

Please sign in to comment.