|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 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 | + |
| 19 | +#pragma once |
| 20 | + |
| 21 | +#include "../common/CHIPCommand.h" |
| 22 | + |
| 23 | +#include <controller/CommissioningWindowOpener.h> |
| 24 | +#include <lib/support/CHIPMem.h> |
| 25 | + |
| 26 | +class OpenJointCommissioningWindowCommand : public CHIPCommand |
| 27 | +{ |
| 28 | +public: |
| 29 | + OpenJointCommissioningWindowCommand(CredentialIssuerCommands * credIssuerCommands) : |
| 30 | + CHIPCommand("open-joint-commissioning-window", credIssuerCommands), |
| 31 | + mOnOpenCommissioningWindowCallback(OnOpenCommissioningWindowResponse, this) |
| 32 | + { |
| 33 | + AddArgument("node-id", 0, UINT64_MAX, &mNodeId, "Node to send command to."); |
| 34 | + AddArgument("window-timeout", 0, UINT16_MAX, &mCommissioningWindowTimeout, |
| 35 | + "Time, in seconds, before the commissioning window closes."); |
| 36 | + AddArgument("iteration", chip::Crypto::kSpake2p_Min_PBKDF_Iterations, chip::Crypto::kSpake2p_Max_PBKDF_Iterations, |
| 37 | + &mIteration, "Number of PBKDF iterations to use to derive the verifier. Ignored if 'option' is 0."); |
| 38 | + AddArgument("discriminator", 0, 4095, &mDiscriminator, "Discriminator to use for advertising. Ignored if 'option' is 0."); |
| 39 | + AddArgument("timeout", 0, UINT16_MAX, &mTimeout, "Time, in seconds, before this command is considered to have timed out."); |
| 40 | + } |
| 41 | + |
| 42 | + /////////// CHIPCommand Interface ///////// |
| 43 | + CHIP_ERROR RunCommand() override; |
| 44 | + // We issue multiple data model operations for this command, and the default |
| 45 | + // timeout for those is 10 seconds, so default to 20 seconds. |
| 46 | + chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(mTimeout.ValueOr(20)); } |
| 47 | + |
| 48 | +private: |
| 49 | + NodeId mNodeId; |
| 50 | + uint16_t mCommissioningWindowTimeout; |
| 51 | + uint32_t mIteration; |
| 52 | + uint16_t mDiscriminator; |
| 53 | + |
| 54 | + chip::Optional<uint16_t> mTimeout; |
| 55 | + |
| 56 | + chip::Platform::UniquePtr<chip::Controller::CommissioningWindowOpener> mWindowOpener; |
| 57 | + |
| 58 | + static void OnOpenCommissioningWindowResponse(void * context, NodeId deviceId, CHIP_ERROR status, chip::SetupPayload payload); |
| 59 | + |
| 60 | + chip::Callback::Callback<chip::Controller::OnOpenCommissioningWindow> mOnOpenCommissioningWindowCallback; |
| 61 | +}; |
0 commit comments