Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / chip-tool / commands / pairing / PairingCommand.h
1 /*
2  *   Copyright (c) 2020 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 "../../config/PersistentStorage.h"
22 #include "../common/Command.h"
23
24 enum class PairingMode
25 {
26     None,
27     Bypass,
28     Ble,
29     SoftAP,
30 };
31
32 class PairingCommand : public Command, public chip::Controller::DevicePairingDelegate
33 {
34 public:
35     PairingCommand(const char * commandName, PairingMode mode) :
36         Command(commandName), mPairingMode(mode), mRemoteAddr{ IPAddress::Any, INET_NULL_INTERFACEID }
37     {
38         switch (mode)
39         {
40         case PairingMode::None:
41             break;
42         case PairingMode::Bypass:
43             AddArgument("device-remote-ip", &mRemoteAddr);
44             AddArgument("device-remote-port", 0, UINT16_MAX, &mRemotePort);
45             break;
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);
51             break;
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);
57             break;
58         }
59     }
60
61     /////////// Command Interface /////////
62     CHIP_ERROR Run(PersistentStorage & storage, NodeId localId, NodeId remoteId) override;
63
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;
71
72 private:
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);
77
78     const PairingMode mPairingMode;
79     Command::AddressWithInterface mRemoteAddr;
80     uint16_t mRemotePort;
81     uint16_t mDiscriminator;
82     uint32_t mSetupPINCode;
83     char * mSSID;
84     char * mPassword;
85
86     ChipDeviceCommissioner mCommissioner;
87 };