chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2020-2021 Project CHIP Authors |
| 4 | * Copyright (c) 2013-2017 Nest Labs, Inc. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | /** |
| 21 | * @file |
| 22 | * Declaration of Commissioner Discovery Controller, |
| 23 | * a common class that manages state and callbacks |
| 24 | * for handling the Commissioner Discovery |
| 25 | * and User Directed Commissioning workflow |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | #pragma once |
| 30 | |
Terence Hampson | b6859d7 | 2022-08-05 13:48:11 -0400 | [diff] [blame] | 31 | #include <app/OperationalSessionSetup.h> |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 32 | #include <lib/core/CHIPConfig.h> |
| 33 | #include <lib/core/CHIPError.h> |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 34 | #include <lib/core/NodeId.h> |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 35 | #include <platform/CHIPDeviceLayer.h> |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 36 | #include <platform/PlatformManager.h> |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 37 | #include <protocols/user_directed_commissioning/UserDirectedCommissioning.h> |
| 38 | |
| 39 | #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY |
| 40 | |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 41 | using chip::NodeId; |
Terence Hampson | b6859d7 | 2022-08-05 13:48:11 -0400 | [diff] [blame] | 42 | using chip::OperationalSessionSetup; |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 43 | using chip::Protocols::UserDirectedCommissioning::UDCClientState; |
| 44 | using chip::Protocols::UserDirectedCommissioning::UserConfirmationProvider; |
| 45 | using chip::Protocols::UserDirectedCommissioning::UserDirectedCommissioningServer; |
| 46 | using chip::Transport::PeerAddress; |
| 47 | |
| 48 | class DLL_EXPORT UserPrompter |
| 49 | { |
| 50 | public: |
| 51 | /** |
| 52 | * @brief |
| 53 | * Called to prompt the user for consent to allow the given commissioneeName/vendorId/productId to be commissioned. |
| 54 | * For example "[commissioneeName] is requesting permission to cast to this TV, approve?" |
| 55 | * |
| 56 | * If user responds with OK then implementor should call CommissionerRespondOk(); |
| 57 | * If user responds with Cancel then implementor should call CommissionerRespondCancel(); |
| 58 | * |
| 59 | * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. |
| 60 | * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. |
| 61 | * @param[in] commissioneeName The commissioneeName in the DNS-SD advertisement of the requesting commissionee. |
| 62 | * |
| 63 | */ |
| 64 | virtual void PromptForCommissionOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) = 0; |
| 65 | |
| 66 | /** |
| 67 | * @brief |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 68 | * Called to prompt the user to enter the setup passcode displayed by the given commissioneeName/vendorId/productId to be |
| 69 | * commissioned. For example "Please enter passcode displayed in casting app." |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 70 | * |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 71 | * If user enters passcode then implementor should call CommissionerRespondPasscode(uint32_t passcode); |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 72 | * If user responds with Cancel then implementor should call CommissionerRespondCancel(); |
| 73 | * |
| 74 | * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. |
| 75 | * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. |
| 76 | * @param[in] commissioneeName The commissioneeName in the DNS-SD advertisement of the requesting commissionee. |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 77 | * @param[in] pairingHint The pairingHint in the DNS-SD advertisement of the requesting commissionee. |
| 78 | * @param[in] pairingInstruction The pairingInstruction in the DNS-SD advertisement of the requesting commissionee. |
| 79 | * |
| 80 | */ |
| 81 | virtual void PromptForCommissionPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName, |
| 82 | uint16_t pairingHint, const char * pairingInstruction) = 0; |
| 83 | |
| 84 | /** |
| 85 | * @brief |
| 86 | * Called to when CancelCommissioning is received via UDC. |
| 87 | * Indicates that commissioner can stop showing the passcode entry or display dialog. |
| 88 | * For example, can show text such as "Commissioning cancelled by client" before hiding dialog. |
| 89 | * |
| 90 | * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. |
| 91 | * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. |
| 92 | * @param[in] commissioneeName The commissioneeName in the DNS-SD advertisement of the requesting commissionee. |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 93 | * |
| 94 | */ |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 95 | virtual void HidePromptsOnCancel(uint16_t vendorId, uint16_t productId, const char * commissioneeName) = 0; |
| 96 | |
| 97 | /** |
| 98 | * @brief |
| 99 | * Return true if this UserPrompter displays QR code along with passcode |
| 100 | * When PromptWithCommissionerPasscode is called during Commissioner Passcode functionality. |
| 101 | */ |
| 102 | virtual bool DisplaysPasscodeAndQRCode() = 0; |
| 103 | |
| 104 | /** |
| 105 | * @brief |
| 106 | * Called to display the given setup passcode to the user, |
| 107 | * for commissioning the given commissioneeName with the given vendorId and productId, |
| 108 | * and provide instructions for where to enter it in the commissionee (when pairingHint and pairingInstruction are provided). |
| 109 | * For example "Casting Passcode: [passcode]. For more instructions, click here." |
| 110 | * |
| 111 | * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. |
| 112 | * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. |
| 113 | * @param[in] commissioneeName The commissioneeName in the DNS-SD advertisement of the requesting commissionee. |
| 114 | * @param[in] passcode The passcode to display. |
| 115 | * @param[in] pairingHint The pairingHint in the DNS-SD advertisement of the requesting commissionee. |
| 116 | * @param[in] pairingInstruction The pairingInstruction in the DNS-SD advertisement of the requesting commissionee. |
| 117 | * |
| 118 | */ |
| 119 | virtual void PromptWithCommissionerPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName, |
| 120 | uint32_t passcode, uint16_t pairingHint, const char * pairingInstruction) = 0; |
| 121 | |
| 122 | /** |
| 123 | * @brief |
| 124 | * Called to alert the user that commissioning has begun." |
| 125 | * |
| 126 | * @param[in] vendorId The vendorid from the DAC of the new node. |
| 127 | * @param[in] productId The productid from the DAC of the new node. |
| 128 | * @param[in] commissioneeName The commissioneeName in the DNS-SD advertisement of the requesting commissionee. |
| 129 | * |
| 130 | */ |
| 131 | virtual void PromptCommissioningStarted(uint16_t vendorId, uint16_t productId, const char * commissioneeName) = 0; |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 132 | |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 133 | /** |
| 134 | * @brief |
| 135 | * Called to prompt the user that commissioning and post-commissioning steps have completed successfully." |
| 136 | * |
| 137 | * @param[in] vendorId The vendorid from the DAC of the new node. |
| 138 | * @param[in] productId The productid from the DAC of the new node. |
| 139 | * @param[in] commissioneeName The commissioneeName in the DNS-SD advertisement of the requesting commissionee. |
| 140 | * |
| 141 | */ |
| 142 | virtual void PromptCommissioningSucceeded(uint16_t vendorId, uint16_t productId, const char * commissioneeName) = 0; |
| 143 | |
| 144 | /** |
| 145 | * @brief |
| 146 | * Called to prompt the user that commissioning and post-commissioning steps have failed." |
| 147 | * |
| 148 | * @param[in] commissioneeName The commissioneeName in the DNS-SD advertisement of the requesting commissionee. |
| 149 | * |
| 150 | */ |
| 151 | virtual void PromptCommissioningFailed(const char * commissioneeName, CHIP_ERROR error) = 0; |
| 152 | |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 153 | virtual ~UserPrompter() = default; |
| 154 | }; |
| 155 | |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 156 | class DLL_EXPORT PasscodeService |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 157 | { |
| 158 | public: |
| 159 | /** |
| 160 | * @brief |
Lazar Kovacic | 78b6ae5 | 2024-05-22 18:40:01 +0200 | [diff] [blame] | 161 | * Called to determine if the given target app is available to the commissionee with the given |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 162 | * vendorId/productId, and if so, return the passcode. |
| 163 | * |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 164 | * This will be called by the main chip thread so any blocking work should be moved to a separate thread. |
| 165 | * |
| 166 | * After lookup and attempting to obtain the passcode, implementor should call HandleContentAppCheck(); |
| 167 | * |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 168 | * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. |
| 169 | * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. |
| 170 | * @param[in] rotatingId The rotatingId in the DNS-SD advertisement of the requesting commissionee. |
| 171 | * @param[in] info App info to look for. |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 172 | * |
| 173 | */ |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 174 | virtual void LookupTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId, |
| 175 | chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info) = 0; |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 176 | |
| 177 | /** |
| 178 | * @brief |
| 179 | * Called to get the commissioner-generated setup passcode. |
| 180 | * Returns 0 if feature is disabled. |
| 181 | * |
| 182 | * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. |
| 183 | * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. |
| 184 | * @param[in] rotatingId The rotatingId in the DNS-SD advertisement of the requesting commissionee. |
| 185 | * |
| 186 | */ |
| 187 | virtual uint32_t GetCommissionerPasscode(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) = 0; |
| 188 | |
| 189 | /** |
| 190 | * @brief |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 191 | * Called to get the setup passcode from the content app corresponding to the given vendorId/productId. |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 192 | * |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 193 | * This will be called by the main chip thread so any blocking work should be moved to a separate thread. |
| 194 | * |
| 195 | * After attempting to obtain the passcode, implementor should call HandleContentAppPasscodeResponse(); |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 196 | * |
| 197 | * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. |
| 198 | * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. |
| 199 | * @param[in] rotatingId The rotatingId in the DNS-SD advertisement of the requesting commissionee. |
| 200 | * |
| 201 | */ |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 202 | virtual void FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) = 0; |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 203 | |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 204 | virtual ~PasscodeService() = default; |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 205 | }; |
| 206 | |
Lazar Kovacic | 78b6ae5 | 2024-05-22 18:40:01 +0200 | [diff] [blame] | 207 | class DLL_EXPORT AppInstallationService |
| 208 | { |
| 209 | public: |
| 210 | /** |
| 211 | * @brief |
| 212 | * Called to check if the given target app is available to the commissione with th given |
| 213 | * vendorId/productId |
| 214 | * |
Lazar Kovacic | 78b6ae5 | 2024-05-22 18:40:01 +0200 | [diff] [blame] | 215 | * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. |
| 216 | * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. |
| 217 | * |
| 218 | */ |
| 219 | virtual bool LookupTargetContentApp(uint16_t vendorId, uint16_t productId) = 0; |
| 220 | |
| 221 | virtual ~AppInstallationService() = default; |
| 222 | }; |
| 223 | |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 224 | class DLL_EXPORT PostCommissioningListener |
| 225 | { |
| 226 | public: |
| 227 | /** |
| 228 | * @brief |
| 229 | * Called to when commissioning completed to allow the listener to perform additional |
| 230 | * steps such as binding and ACL creation. |
| 231 | * |
| 232 | * @param[in] vendorId The vendorid from the DAC of the new node. |
| 233 | * @param[in] productId The productid from the DAC of the new node. |
| 234 | * @param[in] nodeId The node id for the newly commissioned node. |
mthiesc | bbd21f4 | 2024-08-23 00:59:53 +0200 | [diff] [blame] | 235 | * @param[in] rotatingId The rotating ID to handle account login. |
| 236 | * @param[in] passcode The passcode to handle account login. |
Terence Hampson | b6859d7 | 2022-08-05 13:48:11 -0400 | [diff] [blame] | 237 | * @param[in] exchangeMgr The exchange manager to be used to get an exchange context. |
| 238 | * @param[in] sessionHandle A reference to an established session. |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 239 | * |
| 240 | */ |
mthiesc | bbd21f4 | 2024-08-23 00:59:53 +0200 | [diff] [blame] | 241 | virtual void CommissioningCompleted(uint16_t vendorId, uint16_t productId, NodeId nodeId, chip::CharSpan rotatingId, |
| 242 | uint32_t passcode, chip::Messaging::ExchangeManager & exchangeMgr, |
Marcos B | cae6319 | 2023-01-13 14:53:14 -0700 | [diff] [blame] | 243 | const chip::SessionHandle & sessionHandle) = 0; |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 244 | |
| 245 | virtual ~PostCommissioningListener() = default; |
| 246 | }; |
| 247 | |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 248 | class DLL_EXPORT CommissionerCallback |
| 249 | { |
| 250 | public: |
| 251 | /** |
| 252 | * @brief |
| 253 | * Called to notify the commissioner that commissioning can now proceed for |
| 254 | * the node identified by the given arguments. |
| 255 | * |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 256 | * @param[in] passcode The passcode to use for the commissionee. |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 257 | * @param[in] longDiscriminator The long discriminator for the commissionee. |
| 258 | * @param[in] peerAddress The peerAddress for the commissionee. |
| 259 | * |
| 260 | */ |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 261 | virtual void ReadyForCommissioning(uint32_t passcode, uint16_t longDiscriminator, PeerAddress peerAddress) = 0; |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 262 | |
| 263 | virtual ~CommissionerCallback() = default; |
| 264 | }; |
| 265 | |
| 266 | class CommissionerDiscoveryController : public chip::Protocols::UserDirectedCommissioning::UserConfirmationProvider |
| 267 | { |
| 268 | public: |
| 269 | /** |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 270 | * This controller can only handle one outstanding UDC session at a time and will |
| 271 | * reject attempts to start a second when one is outstanding. |
| 272 | * |
| 273 | * A session ends when post-commissioning completes: |
| 274 | * - PostCommissioningSucceeded() |
| 275 | * or when one of the following failure methods is called: |
| 276 | * - PostCommissioningFailed() |
| 277 | * - CommissioningFailed() |
| 278 | * |
| 279 | * Reset the state of this controller so that a new sessions will be accepted. |
| 280 | */ |
| 281 | void ResetState(); |
| 282 | |
| 283 | /** |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 284 | * Check whether we have a valid session (and reset state if not). |
| 285 | */ |
| 286 | void ValidateSession(); |
| 287 | |
| 288 | /** |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 289 | * UserConfirmationProvider callback. |
| 290 | * |
| 291 | * Notification that a UDC protocol message was received. |
| 292 | * |
| 293 | * This code will call the registered UserPrompter's PromptForCommissionOKPermission |
| 294 | */ |
Andrei Litvin | d80d593 | 2022-03-16 21:15:16 -0400 | [diff] [blame] | 295 | void OnUserDirectedCommissioningRequest(UDCClientState state) override; |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 296 | |
| 297 | /** |
chrisdecenzo | 03d2fa8 | 2024-04-15 10:01:41 -0700 | [diff] [blame] | 298 | * UserConfirmationProvider callback. |
| 299 | * |
| 300 | * Notification that a Cancel UDC protocol message was received. |
| 301 | * |
| 302 | * This code will call the registered UserPrompter's HidePromptsOnCancel |
| 303 | */ |
| 304 | void OnCancel(UDCClientState state) override; |
| 305 | |
| 306 | /** |
| 307 | * UserConfirmationProvider callback. |
| 308 | * |
| 309 | * Notification that a CommissionerPasscodeReady UDC protocol message was received. |
| 310 | * |
| 311 | * This code will trigger the Commissioner to begin commissioning |
| 312 | */ |
| 313 | void OnCommissionerPasscodeReady(UDCClientState state) override; |
| 314 | |
| 315 | /** |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 316 | * This method should be called after the user has given consent for commissioning of the client |
| 317 | * indicated in the UserPrompter's PromptForCommissionOKPermission callback |
| 318 | */ |
| 319 | void Ok(); |
chrisdecenzo | bbf5f75 | 2024-03-01 14:34:46 -0800 | [diff] [blame] | 320 | void InternalOk(); |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 321 | |
| 322 | /** |
| 323 | * This method should be called after the user has declined to give consent for commissioning of the client |
| 324 | * indicated in the UserPrompter's PromptForCommissionOKPermission callback |
| 325 | */ |
| 326 | void Cancel(); |
| 327 | |
| 328 | /** |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 329 | * @brief |
| 330 | * Called with the result of attempting to obtain the passcode from the content app corresponding to the given |
| 331 | * vendorId/productId. |
| 332 | * |
| 333 | * @param[in] passcode Passcode for the given commissionee, or 0 if passcode cannot be obtained. |
| 334 | * |
| 335 | */ |
| 336 | void HandleContentAppPasscodeResponse(uint32_t passcode); |
| 337 | void InternalHandleContentAppPasscodeResponse(); |
| 338 | |
| 339 | /** |
| 340 | * Cache the passcode to use for commissioning |
| 341 | */ |
| 342 | inline void SetPasscode(uint32_t passcode) { mPasscode = passcode; } |
| 343 | |
| 344 | /** |
| 345 | * @brief |
| 346 | * Called with the result of attempting to lookup and obtain the passcode from the content app corresponding to the given |
| 347 | * target. |
| 348 | * |
| 349 | * @param[in] target Target app info for app check. |
| 350 | * @param[in] passcode Passcode for the given commissionee, or 0 if passcode cannot be obtained. |
| 351 | * |
| 352 | */ |
| 353 | void HandleTargetContentAppCheck(chip::Protocols::UserDirectedCommissioning::TargetAppInfo target, uint32_t passcode); |
| 354 | |
| 355 | /** |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 356 | * This method should be called with the passcode for the client |
| 357 | * indicated in the UserPrompter's PromptForCommissionPasscode callback |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 358 | */ |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 359 | void CommissionWithPasscode(uint32_t passcode); |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 360 | void InternalCommissionWithPasscode(); |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 361 | |
| 362 | /** |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 363 | * This method should be called by the commissioner to indicate that commissioning succeeded. |
| 364 | * The PostCommissioningCallback will then be invoked to complete setup |
| 365 | * |
| 366 | * @param[in] vendorId The vendorid from the DAC of the new node. |
| 367 | * @param[in] productId The productid from the DAC of the new node. |
| 368 | * @param[in] nodeId The node id for the newly commissioned node. |
Terence Hampson | b6859d7 | 2022-08-05 13:48:11 -0400 | [diff] [blame] | 369 | * @param[in] exchangeMgr The exchange manager to be used to get an exchange context. |
| 370 | * @param[in] sessionHandle A reference to an established session. |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 371 | * |
| 372 | */ |
Terence Hampson | b6859d7 | 2022-08-05 13:48:11 -0400 | [diff] [blame] | 373 | void CommissioningSucceeded(uint16_t vendorId, uint16_t productId, NodeId nodeId, |
Marcos B | cae6319 | 2023-01-13 14:53:14 -0700 | [diff] [blame] | 374 | chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle); |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 375 | |
| 376 | /** |
| 377 | * This method should be called by the commissioner to indicate that commissioning failed. |
| 378 | * The UserPrompter will then be invoked to notify the user of the failure. |
| 379 | */ |
| 380 | void CommissioningFailed(CHIP_ERROR error); |
| 381 | |
| 382 | /** |
| 383 | * This method should be called by the PostCommissioningListener to indicate that post-commissioning steps completed. |
| 384 | * The PromptCommissioningSucceeded will then be invoked to notify the user of success. |
| 385 | */ |
| 386 | void PostCommissioningSucceeded(); |
| 387 | |
| 388 | /** |
| 389 | * This method should be called by the PostCommissioningListener to indicate that post-commissioning steps failed. |
| 390 | * The PromptCommissioningFailed will then be invoked to notify the user of failure. |
| 391 | */ |
| 392 | void PostCommissioningFailed(CHIP_ERROR error); |
| 393 | |
| 394 | /** |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 395 | * Assign a DeviceCommissioner |
| 396 | */ |
| 397 | inline void SetUserDirectedCommissioningServer(UserDirectedCommissioningServer * udcServer) |
| 398 | { |
| 399 | mUdcServer = udcServer; |
| 400 | mUdcServer->SetUserConfirmationProvider(this); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Assign a UserPromper |
| 405 | */ |
| 406 | inline void SetUserPrompter(UserPrompter * userPrompter) { mUserPrompter = userPrompter; } |
| 407 | |
| 408 | /** |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 409 | * Assign a PasscodeService |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 410 | */ |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 411 | inline void SetPasscodeService(PasscodeService * passcodeService) { mPasscodeService = passcodeService; } |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 412 | inline PasscodeService * GetPasscodeService() { return mPasscodeService; } |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 413 | |
| 414 | /** |
Lazar Kovacic | 78b6ae5 | 2024-05-22 18:40:01 +0200 | [diff] [blame] | 415 | * Assign an AppInstallationService |
| 416 | */ |
| 417 | inline void SetAppInstallationService(AppInstallationService * appInstallationService) |
| 418 | { |
| 419 | mAppInstallationService = appInstallationService; |
| 420 | } |
| 421 | |
| 422 | /** |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 423 | * Assign a Commissioner Callback to perform commissioning once user consent has been given |
| 424 | */ |
| 425 | inline void SetCommissionerCallback(CommissionerCallback * commissionerCallback) |
| 426 | { |
| 427 | mCommissionerCallback = commissionerCallback; |
| 428 | } |
| 429 | |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 430 | /** |
| 431 | * Assign a PostCommissioning Listener to perform post-commissioning operations |
| 432 | */ |
| 433 | inline void SetPostCommissioningListener(PostCommissioningListener * postCommissioningListener) |
| 434 | { |
| 435 | mPostCommissioningListener = postCommissioningListener; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Get the commissioneeName in the DNS-SD advertisement of the requesting commissionee. |
| 440 | */ |
| 441 | const char * GetCommissioneeName(); |
| 442 | |
| 443 | /** |
| 444 | * Get the UDCClientState of the requesting commissionee. |
| 445 | */ |
| 446 | UDCClientState * GetUDCClientState(); |
| 447 | |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 448 | protected: |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 449 | bool mReady = true; // ready to start commissioning |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 450 | bool mPendingConsent = false; |
| 451 | char mCurrentInstance[chip::Dnssd::Commission::kInstanceNameMaxLength + 1]; |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 452 | uint16_t mVendorId = 0; |
| 453 | uint16_t mProductId = 0; |
| 454 | NodeId mNodeId = 0; |
chrisdecenzo | 31fa02f | 2024-03-26 09:38:19 -0700 | [diff] [blame] | 455 | uint32_t mPasscode = 0; |
mthiesc | bbd21f4 | 2024-08-23 00:59:53 +0200 | [diff] [blame] | 456 | std::string mRotatingId; |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 457 | |
| 458 | UserDirectedCommissioningServer * mUdcServer = nullptr; |
| 459 | UserPrompter * mUserPrompter = nullptr; |
chrisdecenzo | 7dbacc6 | 2024-01-18 11:57:05 -0800 | [diff] [blame] | 460 | PasscodeService * mPasscodeService = nullptr; |
Lazar Kovacic | 78b6ae5 | 2024-05-22 18:40:01 +0200 | [diff] [blame] | 461 | AppInstallationService * mAppInstallationService = nullptr; |
chrisdecenzo | d7af12d | 2022-02-07 06:47:41 -0800 | [diff] [blame] | 462 | CommissionerCallback * mCommissionerCallback = nullptr; |
| 463 | PostCommissioningListener * mPostCommissioningListener = nullptr; |
chrisdecenzo | 0c94a80 | 2022-01-27 09:05:43 -0800 | [diff] [blame] | 464 | }; |
| 465 | |
| 466 | #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY |