Skip to content

Commit e86bb35

Browse files
IP cluster-based commissioning (project-chip#6798)
* Cluster-based commissioning - phase 1. Adds calls to clusters to commission a device properly. This is intended to be used to setup a device that is already on the network, but not already on a CHIP network. Hence, network credentials are not required, but we do need to send all the remaining commissioning information. Challenges: IM cluster commands time out more often than the non-IM commands, even when the device is clearly sending a reply. Need to find the race and get rid of it. Still to do: - add operational credentials into state machine - add more commissioning phases (time set etc.) - add proper scan command for determining ethernet netif name - swap over to CASE before sending commissioning complete command - once we're totally in IM, combine some commands - add post commissioning setup commands (trusted node ids etc.) * Restyled by gn * Address review comments. * Add back some lines lost in a rebase. * Address review comments - remove heap allocation from callbacks - overwrite node ID resolution functions rather than using a delegate * Restyled by gn * Restyled by shfmt Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 7f841f0 commit e86bb35

File tree

16 files changed

+439
-26
lines changed

16 files changed

+439
-26
lines changed

config/esp32/components/chip/Kconfig

+12
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,18 @@ menu "CHIP Device Layer"
654654

655655
endmenu
656656

657+
menu "Commissioning options"
658+
config RENDEZVOUS_WAIT_FOR_COMMISSIONING_COMPLETE
659+
int "Use full IP-based commissioning (expect cluster commands)"
660+
default 0
661+
help
662+
Setting this to y will cause the commissioner to send commissioning commands to the
663+
various clusters after establishing a PASE session.
664+
665+
endmenu
666+
667+
668+
657669
menu "Testing Options"
658670

659671
config ENABLE_TEST_DEVICE_IDENTITY

examples/all-clusters-app/esp32/main/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class SetupListModel : public ListScreen::Model
339339
else if (i == 2)
340340
{
341341
app::Mdns::AdvertiseCommissionableNode();
342-
OpenDefaultPairingWindow(ResetAdmins::kNo, PairingWindowAdvertisement::kMdns);
342+
OpenDefaultPairingWindow(ResetAdmins::kYes, PairingWindowAdvertisement::kMdns);
343343
}
344344
}
345345

scripts/build_python.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ENVIRONMENT_ROOT="$CHIP_ROOT/out/python_env"
4040

4141
declare chip_detail_logging=false
4242
declare chip_mdns="minimal"
43+
declare clusters=true
4344

4445
help() {
4546

@@ -52,6 +53,8 @@ Input Options:
5253
By default it is false.
5354
-m, --chip_mdns ChipMDNSValue Specify ChipMDNSValue as platform or minimal.
5455
By default it is minimal.
56+
-c, --clusters_for_ip_commissioning true/false Specify whether to use clusters for IP commissioning.
57+
By default it is true.
5558
"
5659
}
5760

@@ -71,6 +74,10 @@ while (($#)); do
7174
chip_mdns=$2
7275
shift
7376
;;
77+
--clusters_for_ip_commissioning | -c)
78+
clusters=$2
79+
shift
80+
;;
7481
-*)
7582
help
7683
echo "Unknown Option \"$1\""
@@ -87,7 +94,7 @@ echo "Input values: chip_detail_logging = $chip_detail_logging , chip_mdns = \"$
8794
source "$CHIP_ROOT/scripts/activate.sh"
8895

8996
# Generates ninja files
90-
gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging chip_mdns=\"$chip_mdns\""
97+
gn --root="$CHIP_ROOT" gen "$OUTPUT_ROOT" --args="chip_detail_logging=$chip_detail_logging chip_mdns=\"$chip_mdns\" chip_use_clusters_for_ip_commissioning=$clusters"
9198

9299
# Compiles python files
93100
ninja -C "$OUTPUT_ROOT" python

src/app/clusters/network-commissioning/network-commissioning.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <lib/support/logging/CHIPLogging.h>
2929
#include <platform/CHIPDeviceLayer.h>
3030
#include <platform/ConnectivityManager.h>
31+
#include <platform/internal/DeviceControlServer.h>
3132

3233
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
3334
#include <platform/ThreadStackManager.h>
@@ -258,6 +259,14 @@ EmberAfNetworkCommissioningError OnEnableNetworkCommandCallbackInternal(app::Com
258259
{
259260
size_t networkSeq;
260261
EmberAfNetworkCommissioningError err = EMBER_ZCL_NETWORK_COMMISSIONING_ERROR_NETWORK_ID_NOT_FOUND;
262+
// TODO(cecille): This is very dangerous - need to check against real netif name, ensure no password.
263+
constexpr char ethernetNetifMagicCode[] = "ETH0";
264+
if (networkID.size() == sizeof(ethernetNetifMagicCode) &&
265+
memcmp(networkID.data(), ethernetNetifMagicCode, networkID.size()) == 0)
266+
{
267+
ChipLogProgress(Zcl, "Wired network enabling requested. Assuming success.");
268+
ExitNow(err = EMBER_ZCL_NETWORK_COMMISSIONING_ERROR_SUCCESS);
269+
}
261270

262271
for (networkSeq = 0; networkSeq < kMaxNetworks; networkSeq++)
263272
{
@@ -274,6 +283,10 @@ EmberAfNetworkCommissioningError OnEnableNetworkCommandCallbackInternal(app::Com
274283
}
275284
// TODO: We should encode response command here.
276285
exit:
286+
if (err == EMBER_ZCL_NETWORK_COMMISSIONING_ERROR_SUCCESS)
287+
{
288+
DeviceLayer::Internal::DeviceControlServer::DeviceControlSvr().EnableNetworkForOperational(networkID);
289+
}
277290
return err;
278291
}
279292

src/app/server/RendezvousServer.cpp

+43-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <app/server/RendezvousServer.h>
1919

20+
#include <app/server/Mdns.h>
2021
#include <app/server/StorablePeerConnection.h>
2122
#include <core/CHIPError.h>
2223
#include <support/CodeUtils.h>
@@ -33,9 +34,38 @@ using namespace ::chip::Transport;
3334
using namespace ::chip::DeviceLayer;
3435

3536
namespace chip {
37+
38+
namespace {
39+
void OnPlatformEventWrapper(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
40+
{
41+
RendezvousServer * server = reinterpret_cast<RendezvousServer *>(arg);
42+
server->OnPlatformEvent(event);
43+
}
44+
} // namespace
3645
static constexpr uint32_t kSpake2p_Iteration_Count = 100;
3746
static const char * kSpake2pKeyExchangeSalt = "SPAKE2P Key Salt";
3847

48+
void RendezvousServer::OnPlatformEvent(const DeviceLayer::ChipDeviceEvent * event)
49+
{
50+
if (event->Type == DeviceLayer::DeviceEventType::kCommissioningComplete)
51+
{
52+
if (event->CommissioningComplete.status == CHIP_NO_ERROR)
53+
{
54+
ChipLogProgress(Discovery, "Commissioning completed successfully");
55+
}
56+
else
57+
{
58+
ChipLogError(Discovery, "Commissioning errored out with error %u", event->CommissioningComplete.status);
59+
}
60+
// TODO: Commissioning complete means we can finalize the admin in our storage
61+
}
62+
else if (event->Type == DeviceLayer::DeviceEventType::kOperationalNetworkEnabled)
63+
{
64+
app::Mdns::AdvertiseOperational();
65+
ChipLogError(Discovery, "Operational advertising enabled");
66+
}
67+
}
68+
3969
CHIP_ERROR RendezvousServer::WaitForPairing(const RendezvousParameters & params, Messaging::ExchangeManager * exchangeManager,
4070
TransportMgrBase * transportMgr, SecureSessionMgr * sessionMgr,
4171
Transport::AdminPairingInfo * admin)
@@ -129,7 +159,19 @@ void RendezvousServer::OnSessionEstablished()
129159
mDelegate->OnRendezvousStarted();
130160
}
131161

132-
Cleanup();
162+
DeviceLayer::PlatformMgr().AddEventHandler(OnPlatformEventWrapper, reinterpret_cast<intptr_t>(this));
163+
164+
if (mPairingSession.PeerConnection().GetPeerAddress().GetTransportType() == Transport::Type::kBle)
165+
{
166+
Cleanup();
167+
}
168+
else
169+
{
170+
// TODO: remove this once we move all tools / examples onto cluster-based IP commissioning.
171+
#if CONFIG_RENDEZVOUS_WAIT_FOR_COMMISSIONING_COMPLETE
172+
Cleanup();
173+
#endif
174+
}
133175

134176
ChipLogProgress(AppServer, "Device completed Rendezvous process");
135177
StorablePeerConnection connection(mPairingSession, mAdmin->GetAdminId());

src/app/server/RendezvousServer.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class RendezvousServer : public SessionEstablishmentDelegate
4747

4848
uint16_t GetNextKeyId() const { return mNextKeyId; }
4949
void SetNextKeyId(uint16_t id) { mNextKeyId = id; }
50+
void OnPlatformEvent(const DeviceLayer::ChipDeviceEvent * event);
5051

5152
private:
5253
AppDelegate * mDelegate;

src/app/server/Server.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ static void ChipEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_
457457
{
458458
case DeviceLayer::DeviceEventType::kInternetConnectivityChange:
459459
VerifyOrReturn(event->InternetConnectivityChange.IPv4 == DeviceLayer::kConnectivity_Established);
460+
// TODO : Need to check if we're properly commissioned.
460461
advertise();
461462
break;
462463
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD

0 commit comments

Comments
 (0)