2 * Copyright (c) 2020 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "../../config/PersistentStorage.h"
22 #include "../common/Command.h"
24 enum class PairingMode
32 class PairingCommand : public Command, public chip::Controller::DevicePairingDelegate
35 PairingCommand(const char * commandName, PairingMode mode) :
36 Command(commandName), mPairingMode(mode), mRemoteAddr{ IPAddress::Any, INET_NULL_INTERFACEID }
40 case PairingMode::None:
42 case PairingMode::Bypass:
43 AddArgument("device-remote-ip", &mRemoteAddr);
44 AddArgument("device-remote-port", 0, UINT16_MAX, &mRemotePort);
46 case PairingMode::Ble:
47 AddArgument("ssid", &mSSID);
48 AddArgument("password", &mPassword);
49 AddArgument("setup-pin-code", 0, 134217727, &mSetupPINCode);
50 AddArgument("discriminator", 0, 4096, &mDiscriminator);
52 case PairingMode::SoftAP:
53 AddArgument("setup-pin-code", 0, 134217727, &mSetupPINCode);
54 AddArgument("discriminator", 0, 4096, &mDiscriminator);
55 AddArgument("device-remote-ip", &mRemoteAddr);
56 AddArgument("device-remote-port", 0, UINT16_MAX, &mRemotePort);
61 /////////// Command Interface /////////
62 CHIP_ERROR Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) override;
64 /////////// DevicePairingDelegate Interface /////////
65 void OnStatusUpdate(chip::RendezvousSessionDelegate::Status status) override;
66 void OnNetworkCredentialsRequested(chip::RendezvousDeviceCredentialsDelegate * callback) override;
67 void OnOperationalCredentialsRequested(const char * csr, size_t csr_length,
68 chip::RendezvousDeviceCredentialsDelegate * callback) override;
69 void OnPairingComplete(CHIP_ERROR error) override;
70 void OnPairingDeleted(CHIP_ERROR error) override;
73 CHIP_ERROR RunInternal(NodeId remoteId);
74 CHIP_ERROR Pair(NodeId remoteId, PeerAddress address);
75 CHIP_ERROR PairWithoutSecurity(NodeId remoteId, PeerAddress address);
76 CHIP_ERROR Unpair(NodeId remoteId);
78 const PairingMode mPairingMode;
79 Command::AddressWithInterface mRemoteAddr;
81 uint16_t mDiscriminator;
82 uint32_t mSetupPINCode;
86 ChipDeviceCommissioner mCommissioner;