Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2021 Project CHIP Authors
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #pragma once
19 :
20 : #include <credentials/GroupDataProvider.h>
21 : #include <messaging/ExchangeMgr.h>
22 : #include <messaging/ReliableMessageProtocolConfig.h>
23 : #include <protocols/secure_channel/CASESession.h>
24 :
25 : namespace chip {
26 :
27 : class CASEClient;
28 :
29 : struct CASEClientInitParams
30 : {
31 : SessionManager * sessionManager = nullptr;
32 : SessionResumptionStorage * sessionResumptionStorage = nullptr;
33 : Credentials::CertificateValidityPolicy * certificateValidityPolicy = nullptr;
34 : Messaging::ExchangeManager * exchangeMgr = nullptr;
35 : FabricTable * fabricTable = nullptr;
36 : Credentials::GroupDataProvider * groupDataProvider = nullptr;
37 :
38 : // mrpLocalConfig should not generally be set to anything other than
39 : // NullOptional. Doing that can lead to different parts of the system
40 : // claiming different MRP parameters for the same node.
41 : Optional<ReliableMessageProtocolConfig> mrpLocalConfig = NullOptional;
42 :
43 : // The minimum backoff interval for LIT devices. This is used to calculate the sigma1
44 : // retransmission timeout for LIT devices, ensuring it's at least `minimumLITBackoffInterval`.
45 : // Specifically, the timeout is `max(LIT activeRetransTimeout,
46 : // minimumLITBackoffInterval)`. This prevents issues with MRP retransmission in Thread
47 : // networks when activeRetransTimeout is too small.
48 : // Note: Setting this parameter to a nonzero value is not spec-compliant.
49 : Optional<uint32_t> minimumLITBackoffInterval = NullOptional;
50 :
51 76 : CHIP_ERROR Validate() const
52 : {
53 : // sessionResumptionStorage can be nullptr when resumption is disabled.
54 : // certificateValidityPolicy is optional, too.
55 76 : VerifyOrReturnError(sessionManager != nullptr, CHIP_ERROR_INCORRECT_STATE);
56 2 : VerifyOrReturnError(exchangeMgr != nullptr, CHIP_ERROR_INCORRECT_STATE);
57 2 : VerifyOrReturnError(fabricTable != nullptr, CHIP_ERROR_INCORRECT_STATE);
58 2 : VerifyOrReturnError(groupDataProvider != nullptr, CHIP_ERROR_INCORRECT_STATE);
59 :
60 2 : return CHIP_NO_ERROR;
61 : }
62 : };
63 :
64 : class DLL_EXPORT CASEClient
65 : {
66 : public:
67 : void SetRemoteMRPIntervals(const ReliableMessageProtocolConfig & remoteMRPConfig);
68 :
69 : const ReliableMessageProtocolConfig & GetRemoteMRPIntervals();
70 :
71 : CHIP_ERROR EstablishSession(const CASEClientInitParams & params, const ScopedNodeId & peer,
72 : const Transport::PeerAddress & peerAddress, const ReliableMessageProtocolConfig & remoteMRPConfig,
73 : SessionEstablishmentDelegate * delegate);
74 :
75 : private:
76 : CASESession mCASESession;
77 : };
78 :
79 : } // namespace chip
|