Line data Source code
1 : /*
2 : * Copyright (c) 2021 Project CHIP Authors
3 : * All rights reserved.
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 <app-common/zap-generated/cluster-objects.h>
21 : #include <controller/CommissioningDelegate.h>
22 : #include <lib/core/CHIPError.h>
23 : #include <lib/core/NodeId.h>
24 : #include <lib/support/DLLUtil.h>
25 : #include <stdint.h>
26 :
27 : namespace chip {
28 : namespace Controller {
29 :
30 : /**
31 : * A delegate that can be notified of progress as a "pairing" (which might mean
32 : * "PASE session establishment" or "commissioning") proceeds.
33 : */
34 : class DLL_EXPORT DevicePairingDelegate
35 : {
36 : public:
37 0 : virtual ~DevicePairingDelegate() {}
38 :
39 : enum Status : uint8_t
40 : {
41 : SecurePairingSuccess = 0,
42 : SecurePairingFailed,
43 : };
44 :
45 : /**
46 : * @brief
47 : * Called when the pairing reaches a certain stage.
48 : *
49 : * @param status Current status of pairing
50 : */
51 0 : virtual void OnStatusUpdate(DevicePairingDelegate::Status status) {}
52 :
53 : /**
54 : * @brief
55 : * Called when PASE session establishment is complete (with success or error)
56 : *
57 : * @param error Error cause, if any
58 : */
59 0 : virtual void OnPairingComplete(CHIP_ERROR error) {}
60 :
61 : /**
62 : * @brief
63 : * Called when the pairing is deleted (with success or error)
64 : *
65 : * @param error Error cause, if any
66 : */
67 0 : virtual void OnPairingDeleted(CHIP_ERROR error) {}
68 :
69 : /**
70 : * Called when the commissioning process is complete (with success or error)
71 : */
72 0 : virtual void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR error) {}
73 :
74 : /**
75 : * Called when the commissioning process is complete (with success or error)
76 : * Should be overriden by DevicePairingDelegates which are JF compatible
77 : * - trustedIcacPublicKeyB has a value only when Joint Commissioning Method is executed
78 : */
79 0 : virtual void OnCommissioningComplete(NodeId deviceId, const Optional<Crypto::P256PublicKey> & trustedIcacPublicKeyB,
80 : CHIP_ERROR error)
81 : {
82 0 : OnCommissioningComplete(deviceId, error);
83 0 : }
84 :
85 0 : virtual void OnCommissioningSuccess(PeerId peerId) {}
86 0 : virtual void OnCommissioningFailure(PeerId peerId, CHIP_ERROR error, CommissioningStage stageFailed,
87 : Optional<Credentials::AttestationVerificationResult> additionalErrorInfo)
88 0 : {}
89 :
90 0 : virtual void OnCommissioningStatusUpdate(PeerId peerId, CommissioningStage stageCompleted, CHIP_ERROR error) {}
91 :
92 : /**
93 : * @brief
94 : * Called with the ReadCommissioningInfo returned from the target
95 : */
96 0 : virtual void OnReadCommissioningInfo(const ReadCommissioningInfo & info) {}
97 :
98 : /**
99 : * @brief
100 : * Called when MatchingFabricInfo returned from target
101 : */
102 0 : virtual void OnFabricCheck(NodeId matchingNodeId) {}
103 :
104 : /**
105 : * @brief
106 : * Called with the NetworkScanResponse returned from the target.
107 : *
108 : * The DeviceCommissioner will be waiting in the kNeedsNetworkCreds step and not advancing the commissioning process.
109 : *
110 : * The implementation should set the network credentials on the CommissioningParameters of the CommissioningDelegate
111 : * using CommissioningDelegate.SetCommissioningParameters(), and then call DeviceCommissioner.NetworkCredentialsReady()
112 : * in order to resume the commissioning process.
113 : */
114 : virtual void
115 0 : OnScanNetworksSuccess(const app::Clusters::NetworkCommissioning::Commands::ScanNetworksResponse::DecodableType & dataResponse)
116 0 : {}
117 :
118 : /**
119 : * @brief
120 : * Called when the NetworkScan request fails.
121 : *
122 : * The DeviceCommissioner will be waiting in the kNeedsNetworkCreds step and not advancing the commissioning process.
123 : *
124 : * The implementation should set the network credentials on the CommissioningParameters of the CommissioningDelegate
125 : * using CommissioningDelegate.SetCommissioningParameters(), and then call DeviceCommissioner.NetworkCredentialsReady()
126 : * in order to resume the commissioning process.
127 : */
128 0 : virtual void OnScanNetworksFailure(CHIP_ERROR error) {}
129 :
130 : /**
131 : * @brief
132 : * Called when the ICD registration information (ICD symmetric key, check-in node ID and monitored subject) is required.
133 : *
134 : * The DeviceCommissioner will be waiting in the kICDGetRegistrationInfo step and not advancing the commissioning process.
135 : *
136 : * The implementation should set the ICD registration info on the CommissioningParameters of the CommissioningDelegate
137 : * using CommissioningDelegate.SetCommissioningParameters(), and then call DeviceCommissioner.ICDRegistrationInfoReady()
138 : * in order to resume the commissioning process.
139 : *
140 : * Not called if the ICD registration info is provided up front.
141 : */
142 0 : virtual void OnICDRegistrationInfoRequired() {}
143 :
144 : /**
145 : * @brief
146 : * Called when the registration flow for the ICD completes.
147 : *
148 : * @param[in] icdNodeId The node id of the ICD.
149 : * @param[in] icdCounter The ICD Counter received from the device.
150 : */
151 0 : virtual void OnICDRegistrationComplete(ScopedNodeId icdNodeId, uint32_t icdCounter) {}
152 :
153 : /**
154 : * @brief
155 : * Called upon completion of the LIT ICD commissioning flow, when ICDStayActiveDuration is set
156 : * and the corresponding stayActive command response is received
157 : *
158 : * @param[in] icdNodeId The node id of the ICD.
159 : * @param[in] promisedActiveDurationMsec The actual duration that the ICD server can stay active
160 : * from the time it receives the StayActiveRequest command.
161 : */
162 0 : virtual void OnICDStayActiveComplete(ScopedNodeId icdNodeId, uint32_t promisedActiveDurationMsec) {}
163 : };
164 :
165 : } // namespace Controller
166 : } // namespace chip
|