Line data Source code
1 : /* 2 : * 3 : * Copyright (c) 2023 Project CHIP Authors 4 : * All rights reserved. 5 : * 6 : * Licensed under the Apache License, Version 2.0 (the "License"); 7 : * you may not use this file except in compliance with the License. 8 : * You may obtain a copy of the License at 9 : * 10 : * http://www.apache.org/licenses/LICENSE-2.0 11 : * 12 : * Unless required by applicable law or agreed to in writing, software 13 : * distributed under the License is distributed on an "AS IS" BASIS, 14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 : * See the License for the specific language governing permissions and 16 : * limitations under the License. 17 : */ 18 : 19 : #pragma once 20 : 21 : #include <lib/core/TLV.h> 22 : #include <messaging/ReliableMessageProtocolConfig.h> 23 : 24 : namespace chip { 25 : 26 : // TODO We should get part of this from constexpr that is in ReliableMessageProtocolConfig.h 27 : 28 : class SessionParameters 29 : { 30 : public: 31 133681 : SessionParameters(ReliableMessageProtocolConfig mrpConfig = GetDefaultMRPConfig()) : mMRPConfig(mrpConfig) {} 32 : 33 : // This estimated TLV size calc is here instead of messaging/ReliableMessageProtocolConfig.h 34 : // because we would need to add `include <lib/core/TLV.h>`. While we could make it all work 35 : // from a build standpoint, if any new MRP config gets added accessors will still need to be 36 : // added here so having this calc done here isn't problematic. 37 : static constexpr size_t kSizeOfSessionIdleInterval = sizeof(uint32_t); 38 : static constexpr size_t kSizeOfSessionActiveInterval = sizeof(uint32_t); 39 : static constexpr size_t kSizeOfSessionActiveThreshold = sizeof(uint16_t); 40 : static constexpr size_t kSizeOfDataModelRevision = sizeof(uint16_t); 41 : static constexpr size_t kSizeOfInteractionModelRevision = sizeof(uint16_t); 42 : static constexpr size_t kSizeOfSpecificationVersion = sizeof(uint32_t); 43 : static constexpr size_t kSizeOfMaxPathsPerInvoke = sizeof(uint16_t); 44 : 45 : static constexpr size_t kEstimatedTLVSize = TLV::EstimateStructOverhead( 46 : kSizeOfSessionIdleInterval, kSizeOfSessionActiveInterval, kSizeOfSessionActiveThreshold, kSizeOfDataModelRevision, 47 : kSizeOfInteractionModelRevision, kSizeOfSpecificationVersion, kSizeOfMaxPathsPerInvoke); 48 : 49 : // From Section 4.12.8 "Parameters and Constants" in chapter "Secure Channel". 50 : enum Tag : uint32_t 51 : { 52 : kSessionIdleInterval = 1, 53 : kSessionActiveInterval = 2, 54 : kSessionActiveThreshold = 3, 55 : kDataModelRevision = 4, 56 : kInteractionModelRevision = 5, 57 : kSpecificationVersion = 6, 58 : kMaxPathsPerInvoke = 7, 59 : }; 60 : 61 15594 : const ReliableMessageProtocolConfig & GetMRPConfig() const { return mMRPConfig; } 62 0 : void SetMRPConfig(const ReliableMessageProtocolConfig & config) { mMRPConfig = config; } 63 30 : void SetMRPIdleRetransTimeout(const System::Clock::Milliseconds32 idleRetransTimeout) 64 : { 65 30 : mMRPConfig.mIdleRetransTimeout = idleRetransTimeout; 66 30 : } 67 30 : void SetMRPActiveRetransTimeout(const System::Clock::Milliseconds32 activeRetransTimeout) 68 : { 69 30 : mMRPConfig.mActiveRetransTimeout = activeRetransTimeout; 70 30 : } 71 30 : void SetMRPActiveThresholdTime(const System::Clock::Milliseconds16 activeThresholdTime) 72 : { 73 30 : mMRPConfig.mActiveThresholdTime = activeThresholdTime; 74 30 : } 75 : 76 : const Optional<uint16_t> & GetDataModelRevision() const { return mDataModelRevision; } 77 30 : void SetDataModelRevision(const uint16_t dataModelRevision) { mDataModelRevision = MakeOptional(dataModelRevision); } 78 : 79 : const Optional<uint16_t> & GetInteractionModelRevision() const { return mInteractionModelRevision; } 80 30 : void SetInteractionModelRevision(const uint16_t interactionModelRevision) 81 : { 82 30 : mInteractionModelRevision = MakeOptional(interactionModelRevision); 83 30 : } 84 : 85 : const Optional<uint32_t> & GetSpecificationVersion() const { return mSpecificationVersion; } 86 30 : void SetSpecificationVersion(const uint32_t specificationVersion) 87 : { 88 30 : mSpecificationVersion = MakeOptional(specificationVersion); 89 30 : } 90 : 91 : uint16_t GetMaxPathsPerInvoke() const { return mMaxPathsPerInvoke; } 92 30 : void SetMaxPathsPerInvoke(const uint16_t maxPathsPerInvoke) { mMaxPathsPerInvoke = maxPathsPerInvoke; } 93 : 94 : private: 95 : ReliableMessageProtocolConfig mMRPConfig; 96 : // For legacy reasons if we do not get DataModelRevision it means either 16 or 17. But there isn't 97 : // a way to know for certain. 98 : Optional<uint16_t> mDataModelRevision; 99 : // For legacy reasons if we do not get InteractionModelRevision it means either 10 or 11. But there 100 : // isn't a way to know for certain. 101 : Optional<uint16_t> mInteractionModelRevision; 102 : // For legacy reasons if we do not get SpecificationVersion it means that version is less than 103 : // 0x01030000. But there isn't a way to know for certain. 104 : Optional<uint32_t> mSpecificationVersion; 105 : // When maxPathsPerInvoke is not provided legacy is always 1 106 : uint16_t mMaxPathsPerInvoke = 1; 107 : }; 108 : 109 : } // namespace chip