forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserDirectedCommissioning.h
693 lines (605 loc) · 24.1 KB
/
UserDirectedCommissioning.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/*
*
* Copyright (c) 2021 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.
*/
/**
* @file
* This file defines objects for a User-Directed Commissioning unsolicited
* initiator (client) and recipient (server).
*
*/
#pragma once
#include "UDCClients.h"
#include <lib/core/CHIPCore.h>
#include <lib/dnssd/Resolver.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/DLLUtil.h>
#include <lib/support/logging/CHIPLogging.h>
#include <messaging/ExchangeContext.h>
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <protocols/Protocols.h>
#include <transport/TransportMgr.h>
namespace chip {
namespace Protocols {
namespace UserDirectedCommissioning {
inline constexpr char kProtocolName[] = "UserDirectedCommissioning";
// Cache contains 16 clients. This may need to be tweaked.
inline constexpr uint8_t kMaxUDCClients = 16;
/**
* User Directed Commissioning Protocol Message Types
*/
enum class MsgType : uint8_t
{
IdentificationDeclaration = 0x00,
};
/**
* Represents the Identification Delaration message
* sent by a UDC client to a UDC server.
*
* ### IdentificationDeclaration format
*
* <pre>
* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
* ┃ instance name '\n' ┃ ignore ┃ additional data TLV ┃
* ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━┛
* │← · · kInstanceNameMaxLength + 1 · · →│← TLV DataLength() →│
*
* Commissioning kInstanceNameMaxLength is 16
* </pre>
*
*/
class DLL_EXPORT IdentificationDeclaration
{
public:
constexpr static size_t kUdcTLVDataMaxBytes = 500;
const char * GetInstanceName() const { return mInstanceName; }
void SetInstanceName(const char * instanceName) { Platform::CopyString(mInstanceName, instanceName); }
bool HasDiscoveryInfo() { return mVendorId != 0 && mProductId != 0 && mCdPort != 0 && strlen(mDeviceName) > 0; }
const char * GetDeviceName() const { return mDeviceName; }
void SetDeviceName(const char * deviceName) { Platform::CopyString(mDeviceName, deviceName); }
uint16_t GetCdPort() const { return mCdPort; }
void SetCdPort(uint16_t port) { mCdPort = port; }
uint16_t GetVendorId() const { return mVendorId; }
void SetVendorId(uint16_t vendorId) { mVendorId = vendorId; }
uint16_t GetProductId() const { return mProductId; }
void SetProductId(uint16_t productId) { mProductId = productId; }
const uint8_t * GetRotatingId() const { return mRotatingId; }
size_t GetRotatingIdLength() const { return mRotatingIdLen; }
void SetRotatingId(const uint8_t * rotatingId, size_t rotatingIdLen)
{
size_t maxSize = ArraySize(mRotatingId);
mRotatingIdLen = (maxSize < rotatingIdLen) ? maxSize : rotatingIdLen;
memcpy(mRotatingId, rotatingId, mRotatingIdLen);
}
bool GetTargetAppInfo(uint8_t index, TargetAppInfo & info) const
{
if (index < mNumTargetAppInfos)
{
info.vendorId = mTargetAppInfos[index].vendorId;
info.productId = mTargetAppInfos[index].productId;
return true;
}
return false;
}
uint8_t GetNumTargetAppInfos() const { return mNumTargetAppInfos; }
bool AddTargetAppInfo(TargetAppInfo vid)
{
if (mNumTargetAppInfos >= sizeof(mTargetAppInfos))
{
// already at max
return false;
}
mTargetAppInfos[mNumTargetAppInfos].vendorId = vid.vendorId;
mTargetAppInfos[mNumTargetAppInfos].productId = vid.productId;
mNumTargetAppInfos++;
return true;
}
const char * GetPairingInst() const { return mPairingInst; }
void SetPairingInst(const char * pairingInst) { Platform::CopyString(mPairingInst, pairingInst); }
uint16_t GetPairingHint() const { return mPairingHint; }
void SetPairingHint(uint16_t pairingHint) { mPairingHint = pairingHint; }
void SetNoPasscode(bool newValue) { mNoPasscode = newValue; };
bool GetNoPasscode() const { return mNoPasscode; };
void SetCdUponPasscodeDialog(bool newValue) { mCdUponPasscodeDialog = newValue; };
bool GetCdUponPasscodeDialog() const { return mCdUponPasscodeDialog; };
void SetCommissionerPasscode(bool newValue) { mCommissionerPasscode = newValue; };
bool GetCommissionerPasscode() const { return mCommissionerPasscode; };
void SetCommissionerPasscodeReady(bool newValue) { mCommissionerPasscodeReady = newValue; };
bool GetCommissionerPasscodeReady() const { return mCommissionerPasscodeReady; };
void SetCancelPasscode(bool newValue) { mCancelPasscode = newValue; };
bool GetCancelPasscode() const { return mCancelPasscode; };
/**
* Writes the IdentificationDeclaration message to the given buffer.
*
* @return Total number of bytes written or 0 if an error occurred.
*/
uint32_t WritePayload(uint8_t * payloadBuffer, size_t payloadBufferSize);
/**
* Reads the IdentificationDeclaration message from the given buffer.
*/
CHIP_ERROR ReadPayload(uint8_t * payloadBuffer, size_t payloadBufferSize);
/**
* Assigns fields from this Identification Declaration to the given UDC client state.
*/
void UpdateClientState(UDCClientState * client)
{
client->SetDeviceName(GetDeviceName());
client->SetVendorId(GetVendorId());
client->SetProductId(GetProductId());
client->SetRotatingId(GetRotatingId(), GetRotatingIdLength());
client->SetPairingInst(GetPairingInst());
client->SetPairingHint(GetPairingHint());
for (uint8_t i = 0; i < GetNumTargetAppInfos(); i++)
{
TargetAppInfo info;
if (GetTargetAppInfo(i, info))
{
client->AddTargetAppInfo(info);
}
}
client->SetCdPort(GetCdPort());
client->SetNoPasscode(GetNoPasscode());
client->SetCdUponPasscodeDialog(GetCdUponPasscodeDialog());
client->SetCommissionerPasscode(GetCommissionerPasscode());
client->SetCommissionerPasscodeReady(GetCommissionerPasscodeReady());
client->SetCancelPasscode(GetCancelPasscode());
}
void DebugLog()
{
ChipLogDetail(AppServer, "---- Identification Declaration Start ----");
ChipLogDetail(AppServer, "\tinstance: %s", mInstanceName);
if (strlen(mDeviceName) != 0)
{
ChipLogDetail(AppServer, "\tdevice Name: %s", mDeviceName);
}
if (mVendorId != 0)
{
ChipLogDetail(AppServer, "\tvendor id: %d", mVendorId);
}
if (mProductId != 0)
{
ChipLogDetail(AppServer, "\tproduct id: %d", mProductId);
}
if (mCdPort != 0)
{
ChipLogDetail(AppServer, "\tcd port: %d", mCdPort);
}
if (mRotatingIdLen > 0)
{
char rotatingIdString[chip::Dnssd::kMaxRotatingIdLen * 2 + 1] = "";
Encoding::BytesToUppercaseHexString(mRotatingId, mRotatingIdLen, rotatingIdString, sizeof(rotatingIdString));
ChipLogDetail(AppServer, "\trotating id: %s", rotatingIdString);
}
for (uint8_t i = 0; i < mNumTargetAppInfos; i++)
{
ChipLogDetail(AppServer, "\tapp vendor id / product id [%d]: %u/%u", i, mTargetAppInfos[i].vendorId,
mTargetAppInfos[i].productId);
}
if (strlen(mPairingInst) != 0)
{
ChipLogDetail(AppServer, "\tpairing instruction: %s", mPairingInst);
}
if (mPairingHint != 0)
{
ChipLogDetail(AppServer, "\tpairing hint: %d", mPairingHint);
}
if (mNoPasscode)
{
ChipLogDetail(AppServer, "\tno passcode: true");
}
if (mCdUponPasscodeDialog)
{
ChipLogDetail(AppServer, "\tcd upon passcode dialog: true");
}
if (mCommissionerPasscode)
{
ChipLogDetail(AppServer, "\tcommissioner passcode: true");
}
if (mCommissionerPasscodeReady)
{
ChipLogDetail(AppServer, "\tcommissioner passcode ready: true");
}
if (mCancelPasscode)
{
ChipLogDetail(AppServer, "\tcancel passcode: true");
}
ChipLogDetail(AppServer, "---- Identification Declaration End ----");
}
private:
// TODO: update spec per the latest tags
enum IdentificationDeclarationTLVTag
{
kVendorIdTag = 1,
kProductIdTag,
kDeviceNameTag,
kDeviceTypeTag,
kPairingInstTag,
kPairingHintTag,
kRotatingIdTag,
kCdPortTag,
kTargetAppListTag,
kTargetAppTag,
kAppVendorIdTag,
kAppProductIdTag,
kNoPasscodeTag,
kCdUponPasscodeDialogTag,
kCommissionerPasscodeTag,
kCommissionerPasscodeReadyTag,
kCancelPasscodeTag,
kMaxNum = UINT8_MAX
};
char mInstanceName[Dnssd::Commission::kInstanceNameMaxLength + 1] = {};
char mDeviceName[Dnssd::kMaxDeviceNameLen + 1] = {};
uint16_t mCdPort = 0;
uint16_t mVendorId = 0;
uint16_t mProductId = 0;
uint8_t mRotatingId[chip::Dnssd::kMaxRotatingIdLen];
size_t mRotatingIdLen = 0;
constexpr static size_t kMaxTargetAppInfos = 10;
uint8_t mNumTargetAppInfos = 0; // number of vendor Ids
TargetAppInfo mTargetAppInfos[kMaxTargetAppInfos];
char mPairingInst[chip::Dnssd::kMaxPairingInstructionLen + 1] = {};
uint16_t mPairingHint = 0;
bool mNoPasscode = false;
bool mCdUponPasscodeDialog = false;
bool mCommissionerPasscode = false;
bool mCommissionerPasscodeReady = false;
bool mCancelPasscode = false;
};
/**
* Represents the Commissioner Delaration message
* sent by a UDC server to a UDC client.
*/
class DLL_EXPORT CommissionerDeclaration
{
public:
enum class CdError : uint16_t
{
kNoError = 0,
kCommissionableDiscoveryFailed = 1,
kPaseConnectionFailed = 2,
kPaseAuthFailed = 3,
kDacValidationFailed = 4,
kAlreadyOnFabric = 5,
kOperationalDiscoveryFailed = 6,
kCaseConnectionFailed = 7,
kCaseAuthFailed = 8,
kConfigurationFailed = 9,
kBindingConfigurationFailed = 10,
kCommissionerPasscodeNotSupported = 11,
kInvalidIdentificationDeclarationParams = 12,
kAppInstallConsentPending = 13,
kAppInstalling = 14,
kAppInstallFailed = 15,
kAppInstalledRetryNeeded = 16,
kCommissionerPasscodeDisabled = 17,
kUnexpectedCommissionerPasscodeReady = 18
};
constexpr static size_t kUdcTLVDataMaxBytes = 500;
void SetErrorCode(CdError newValue) { mErrorCode = newValue; };
CdError GetErrorCode() const { return mErrorCode; };
void SetNeedsPasscode(bool newValue) { mNeedsPasscode = newValue; };
bool GetNeedsPasscode() const { return mNeedsPasscode; };
void SetNoAppsFound(bool newValue) { mNoAppsFound = newValue; };
bool GetNoAppsFound() const { return mNoAppsFound; };
void SetPasscodeDialogDisplayed(bool newValue) { mPasscodeDialogDisplayed = newValue; };
bool GetPasscodeDialogDisplayed() const { return mPasscodeDialogDisplayed; };
void SetCommissionerPasscode(bool newValue) { mCommissionerPasscode = newValue; };
bool GetCommissionerPasscode() const { return mCommissionerPasscode; };
void SetQRCodeDisplayed(bool newValue) { mQRCodeDisplayed = newValue; };
bool GetQRCodeDisplayed() const { return mQRCodeDisplayed; };
void SetCancelPasscode(bool newValue) { mCancelPasscode = newValue; };
bool GetCancelPasscode() const { return mCancelPasscode; };
/**
* Writes the CommissionerDeclaration message to the given buffer.
*
* @return Total number of bytes written or 0 if an error occurred.
*/
uint32_t WritePayload(uint8_t * payloadBuffer, size_t payloadBufferSize);
/**
* Reads the CommissionerDeclaration message from the given buffer.
*/
CHIP_ERROR ReadPayload(uint8_t * payloadBuffer, size_t payloadBufferSize);
void DebugLog()
{
ChipLogDetail(AppServer, "---- Commissioner Declaration Start ----");
if (mErrorCode != CdError::kNoError)
{
ChipLogDetail(AppServer, "\terror code: %d", static_cast<uint16_t>(mErrorCode));
}
if (mNeedsPasscode)
{
ChipLogDetail(AppServer, "\tneeds passcode: true");
}
if (mNoAppsFound)
{
ChipLogDetail(AppServer, "\tno apps found: true");
}
if (mPasscodeDialogDisplayed)
{
ChipLogDetail(AppServer, "\tpasscode dialog displayed: true");
}
if (mCommissionerPasscode)
{
ChipLogDetail(AppServer, "\tcommissioner passcode: true");
}
if (mQRCodeDisplayed)
{
ChipLogDetail(AppServer, "\tQR code displayed: true");
}
if (mCancelPasscode)
{
ChipLogDetail(AppServer, "\tPasscode cancelled: true");
}
ChipLogDetail(AppServer, "---- Commissioner Declaration End ----");
}
private:
// TODO: update spec per the latest tags
enum CommissionerDeclarationTLVTag
{
kErrorCodeTag = 1,
kNeedsPasscodeTag,
kNoAppsFoundTag,
kPasscodeDialogDisplayedTag,
kCommissionerPasscodeTag,
kQRCodeDisplayedTag,
kCancelPasscodeTag,
kMaxNum = UINT8_MAX
};
CdError mErrorCode = CdError::kNoError;
bool mNeedsPasscode = false;
bool mNoAppsFound = false;
bool mPasscodeDialogDisplayed = false;
bool mCommissionerPasscode = false;
bool mQRCodeDisplayed = false;
bool mCancelPasscode = false;
};
class DLL_EXPORT InstanceNameResolver
{
public:
/**
* @brief
* Called when a UDC message is received specifying the given instanceName
* This method indicates that UDC Server needs the Commissionable Node corresponding to
* the given instance name to be found. UDC Server will wait for OnCommissionableNodeFound.
*
* @param instanceName DNS-SD instance name for the client requesting commissioning
*
*/
virtual void FindCommissionableNode(char * instanceName) = 0;
virtual ~InstanceNameResolver() = default;
};
class DLL_EXPORT UserConfirmationProvider
{
public:
/**
* @brief
* Called when an Identification Declaration UDC message has been received
* and corresponding nodeData has been found.
* It is expected that the implementer will prompt the user to confirm their intention to
* commission the given node, and obtain the setup code to allow commissioning to proceed,
* and then invoke commissioning on the given Node (using CHIP Device Controller, for example)
*
* @param[in] state The state for the UDC Client.
*
*/
virtual void OnUserDirectedCommissioningRequest(UDCClientState state) = 0;
/**
* @brief
* Called when an Identification Declaration UDC message has been received
* with the cancel flag set.
* It is expected that the implementer will tear down any dialog prompts for the
* commissionee instance (identified in the UDC client state argument).
*
* @param[in] state The state for the UDC Client.
*
*/
virtual void OnCancel(UDCClientState state) = 0;
/**
* @brief
* Called when an Identification Declaration UDC message has been received
* with the commissioner passcode ready flag set.
* It is expected that the implementer will invoke commissioning on the
* commissionee instance (identified in the UDC client state argument).
*
* @param[in] state The state for the UDC Client.
*
*/
virtual void OnCommissionerPasscodeReady(UDCClientState state) = 0;
virtual ~UserConfirmationProvider() = default;
};
class DLL_EXPORT CommissionerDeclarationHandler
{
public:
/**
* @brief
* Called when a Commissioner Declaration UDC message has been received.
* It is expected that the implementer will de-dup messages received from the
* same source within a short (1 second) time window.
*
* @param[in] source The source of the Commissioner Declaration Message.
* @param[in] cd The Commissioner Declaration Message.
*
*/
virtual void OnCommissionerDeclarationMessage(const chip::Transport::PeerAddress & source, CommissionerDeclaration cd) = 0;
virtual ~CommissionerDeclarationHandler() = default;
};
/**
* TODO:
* - add processing of Commissioner Declaration flags
*/
class DLL_EXPORT UserDirectedCommissioningClient : public TransportMgrDelegate
{
public:
/**
* Send a User Directed Commissioning message to a CHIP node.
*
* @param transportMgr A transport to use for sending the message.
* @param idMessage The Identification Declaration message.
* @param peerAddress Address of destination.
*
* @return CHIP_ERROR_NO_MEMORY if allocation fails.
* Other CHIP_ERROR codes as returned by the lower layers.
*
*/
CHIP_ERROR SendUDCMessage(TransportMgrBase * transportMgr, IdentificationDeclaration idMessage,
chip::Transport::PeerAddress peerAddress);
/**
* Encode a User Directed Commissioning message.
*
* @param payload A PacketBufferHandle with the payload.
*
* @return CHIP_ERROR_NO_MEMORY if allocation fails.
* Other CHIP_ERROR codes as returned by the lower layers.
*
*/
CHIP_ERROR EncodeUDCMessage(const System::PacketBufferHandle & payload);
/**
* Set the listener to be called when a Commissioner Declaration UDC request is received.
*
* @param[in] commissionerDeclarationHandler The callback function to handle the message.
*
*/
void SetCommissionerDeclarationHandler(CommissionerDeclarationHandler * commissionerDeclarationHandler)
{
ChipLogProgress(AppServer, "UserDirectedCommissioningClient::SetCommissionerDeclarationHandler()");
mCommissionerDeclarationHandler = commissionerDeclarationHandler;
}
private:
void OnMessageReceived(const Transport::PeerAddress & source, System::PacketBufferHandle && msgBuf,
Transport::MessageTransportContext * ctxt = nullptr) override;
CommissionerDeclarationHandler * mCommissionerDeclarationHandler = nullptr;
};
/**
* TODO:
* - add processing of Identification Declaration flags
*/
class DLL_EXPORT UserDirectedCommissioningServer : public TransportMgrDelegate
{
public:
/**
* Set the listener to be called when a UDC request is received
* and the Instance Name provided needs to be resolved.
*
* The resolver should call OnCommissionableNodeFound when the instance is found
*
* @param[in] instanceNameResolver The callback function to receive UDC request instance name.
*
*/
void SetInstanceNameResolver(InstanceNameResolver * instanceNameResolver) { mInstanceNameResolver = instanceNameResolver; }
/**
* Set the listener to be called when a UDC request is received
* and the Instance Name has been resolved.
*
* The provider should prompt the user to allow commissioning of the node and provide the setup code.
*
* @param[in] userConfirmationProvider The callback function to obtain user confirmation.
*
*/
void SetUserConfirmationProvider(UserConfirmationProvider * userConfirmationProvider)
{
mUserConfirmationProvider = userConfirmationProvider;
}
/**
* Update the processing state for a UDC Client based upon instance name.
*
* This can be used by the UX to set the state to one of the following values:
* - kUserDeclined
* - kObtainingOnboardingPayload
* - kCommissioningNode
* - kCommissioningFailed
*
* @param[in] instanceName The instance name for the UDC Client.
* @param[in] state The state for the UDC Client.
*
*/
void SetUDCClientProcessingState(char * instanceName, UDCClientProcessingState state);
/**
* Reset the processing states for all UDC Clients
*
*/
void ResetUDCClientProcessingStates() { mUdcClients.ResetUDCClientStates(); }
/**
* Called when a CHIP Node in commissioning mode is found.
*
* Lookup instanceName from nodeData in the active UDC Client states
* and if current state is kDiscoveringNode then change to kPromptingUser and
* call UX Prompt callback
*
* @param[in] nodeData DNS-SD response data.
*
*/
void OnCommissionableNodeFound(const Dnssd::DiscoveredNodeData & nodeData);
/**
* Get the cache of UDC Clients
*
*/
UDCClients<kMaxUDCClients> & GetUDCClients() { return mUdcClients; }
/**
* Print the cache of UDC Clients
*
*/
void PrintUDCClients();
/**
* Send a Commissioner Declaration message to the given peer address
*
* Only one message will be sent.
* Clients should follow spec and send up to 5 times with 100ms sleep between each call.
*/
CHIP_ERROR SendCDCMessage(CommissionerDeclaration cdMessage, chip::Transport::PeerAddress peerAddress);
/**
* Encode a User Directed Commissioning message.
*
* @param payload A PacketBufferHandle with the payload.
*
* @return CHIP_ERROR_NO_MEMORY if allocation fails.
* Other CHIP_ERROR codes as returned by the lower layers.
*
*/
CHIP_ERROR EncodeUDCMessage(const System::PacketBufferHandle & payload);
/**
* Assign the transport manager to use for Commissioner Declaration messages
*/
void SetTransportManager(TransportMgrBase * transportMgr) { mTransportMgr = transportMgr; }
private:
InstanceNameResolver * mInstanceNameResolver = nullptr;
UserConfirmationProvider * mUserConfirmationProvider = nullptr;
void HandleNewUDC(const Transport::PeerAddress & source, IdentificationDeclaration & id);
void HandleUDCCancel(IdentificationDeclaration & id);
void HandleUDCCommissionerPasscodeReady(IdentificationDeclaration & id);
void OnMessageReceived(const Transport::PeerAddress & source, System::PacketBufferHandle && msgBuf,
Transport::MessageTransportContext * ctxt = nullptr) override;
UDCClients<kMaxUDCClients> mUdcClients; // < Active UDC clients
TransportMgrBase * mTransportMgr = nullptr;
};
} // namespace UserDirectedCommissioning
template <>
struct MessageTypeTraits<UserDirectedCommissioning::MsgType>
{
static constexpr const Protocols::Id & ProtocolId() { return UserDirectedCommissioning::Id; }
static auto GetTypeToNameTable()
{
static const std::array<MessageTypeNameLookup, 1> typeToNameTable = {
{
{ UserDirectedCommissioning::MsgType::IdentificationDeclaration, "IdentificationDeclaration" },
},
};
return &typeToNameTable;
}
};
} // namespace Protocols
} // namespace chip