-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathFabricSyncCommand.h
159 lines (123 loc) · 5.73 KB
/
FabricSyncCommand.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#pragma once
#include <commands/common/CHIPCommand.h>
#include <commands/pairing/PairingCommand.h>
#include <device_manager/PairingManager.h>
// Constants
constexpr uint32_t kCommissionPrepareTimeMs = 500;
constexpr uint16_t kMaxManualCodeLength = 21;
class FabricSyncAddBridgeCommand : public CHIPCommand, public CommissioningDelegate
{
public:
FabricSyncAddBridgeCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("add-bridge", credIssuerCommands)
{
AddArgument("node-id", 0, UINT64_MAX, &mNodeId);
AddArgument("setup-pin-code", 0, 0x7FFFFFF, &mSetupPINCode, "Setup PIN code for the remote bridge device.");
AddArgument("device-remote-ip", &mRemoteAddr, "The IP address of the remote bridge device.");
AddArgument("device-remote-port", 0, UINT16_MAX, &mRemotePort, "The secured device port of the remote bridge device.");
}
void OnCommissioningComplete(chip::NodeId deviceId, CHIP_ERROR err) override;
/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override { return RunCommand(mNodeId); }
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }
private:
chip::NodeId mNodeId;
chip::NodeId mBridgeNodeId;
uint32_t mSetupPINCode;
chip::ByteSpan mRemoteAddr;
uint16_t mRemotePort;
CHIP_ERROR RunCommand(NodeId remoteId);
};
class FabricSyncRemoveBridgeCommand : public CHIPCommand, public PairingDelegate
{
public:
FabricSyncRemoveBridgeCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("remove-bridge", credIssuerCommands)
{}
void OnDeviceRemoved(chip::NodeId deviceId, CHIP_ERROR err) override;
/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override;
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }
private:
chip::NodeId mBridgeNodeId;
};
class FabricSyncAddLocalBridgeCommand : public CHIPCommand, public CommissioningDelegate
{
public:
FabricSyncAddLocalBridgeCommand(CredentialIssuerCommands * credIssuerCommands) :
CHIPCommand("add-local-bridge", credIssuerCommands)
{
AddArgument("node-id", 0, UINT64_MAX, &mNodeId);
AddArgument("setup-pin-code", 0, 0x7FFFFFF, &mSetupPINCode, "Setup PIN code for the local bridge device.");
AddArgument("local-port", 0, UINT16_MAX, &mLocalPort, "The secured device port of the local bridge device.");
}
void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err) override;
/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override { return RunCommand(mNodeId); }
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }
private:
chip::NodeId mNodeId;
chip::Optional<uint32_t> mSetupPINCode;
chip::Optional<uint16_t> mLocalPort;
chip::NodeId mLocalBridgeNodeId;
CHIP_ERROR RunCommand(chip::NodeId deviceId);
};
class FabricSyncRemoveLocalBridgeCommand : public CHIPCommand, public PairingDelegate
{
public:
FabricSyncRemoveLocalBridgeCommand(CredentialIssuerCommands * credIssuerCommands) :
CHIPCommand("remove-local-bridge", credIssuerCommands)
{}
void OnDeviceRemoved(chip::NodeId deviceId, CHIP_ERROR err) override;
/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override;
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }
private:
chip::NodeId mLocalBridgeNodeId;
};
class FabricSyncDeviceCommand : public CHIPCommand, public CommissioningWindowDelegate, public CommissioningDelegate
{
public:
FabricSyncDeviceCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("sync-device", credIssuerCommands)
{
AddArgument("endpointid", 0, UINT16_MAX, &mRemoteEndpointId);
}
void OnCommissioningWindowOpened(NodeId deviceId, CHIP_ERROR status, chip::SetupPayload payload) override;
void OnCommissioningComplete(NodeId deviceId, CHIP_ERROR err) override;
/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override { return RunCommand(mRemoteEndpointId); }
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }
private:
chip::EndpointId mRemoteEndpointId = chip::kInvalidEndpointId;
chip::NodeId mAssignedNodeId = chip::kUndefinedNodeId;
CHIP_ERROR RunCommand(chip::EndpointId remoteId);
};
class FabricAutoSyncCommand : public CHIPCommand
{
public:
FabricAutoSyncCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("enable-auto-sync", credIssuerCommands)
{
AddArgument("state", 0, 1, &mEnableAutoSync, "Set to true to enable auto Fabric Sync, false to disable.");
}
/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override { return RunCommand(mEnableAutoSync); }
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }
private:
bool mEnableAutoSync;
CHIP_ERROR RunCommand(bool enableAutoSync);
};