@@ -36,7 +36,7 @@ namespace chip {
36
36
// Check the Setup Payload for validity
37
37
//
38
38
// `vendor_id` and `product_id` are allowed all of uint16_t
39
- bool PayloadContents::isValidQRCodePayload () const
39
+ bool PayloadContents::isValidQRCodePayload (ValidationMode mode ) const
40
40
{
41
41
// 3-bit value specifying the QR code payload version.
42
42
if (version >= 1 << kVersionFieldLengthInBits )
@@ -50,6 +50,7 @@ bool PayloadContents::isValidQRCodePayload() const
50
50
}
51
51
52
52
// Device Commissioning Flow
53
+ // Even in ValidatoinMode::kConsume we can only handle modes that we understand.
53
54
// 0: Standard commissioning flow: such a device, when uncommissioned, always enters commissioning mode upon power-up, subject
54
55
// to the rules in [ref_Announcement_Commencement]. 1: User-intent commissioning flow: user action required to enter
55
56
// commissioning mode. 2: Custom commissioning flow: interaction with a vendor-specified means is needed before commissioning.
@@ -60,13 +61,6 @@ bool PayloadContents::isValidQRCodePayload() const
60
61
return false ;
61
62
}
62
63
63
- chip::RendezvousInformationFlags allvalid (RendezvousInformationFlag::kBLE , RendezvousInformationFlag::kOnNetwork ,
64
- RendezvousInformationFlag::kSoftAP );
65
- if (!rendezvousInformation.HasValue () || !rendezvousInformation.Value ().HasOnly (allvalid))
66
- {
67
- return false ;
68
- }
69
-
70
64
// General discriminator validity is enforced by the SetupDiscriminator class, but it can't be short for QR a code.
71
65
if (discriminator.IsShortDiscriminator ())
72
66
{
@@ -78,13 +72,21 @@ bool PayloadContents::isValidQRCodePayload() const
78
72
return false ;
79
73
}
80
74
75
+ // RendevouzInformation must be present for a QR code.
76
+ VerifyOrReturnValue (rendezvousInformation.HasValue (), false );
77
+ if (mode == ValidationMode::kProduce )
78
+ {
79
+ chip::RendezvousInformationFlags valid (RendezvousInformationFlag::kBLE , RendezvousInformationFlag::kOnNetwork ,
80
+ RendezvousInformationFlag::kSoftAP );
81
+ VerifyOrReturnValue (rendezvousInformation.Value ().HasOnly (valid), false );
82
+ }
83
+
81
84
return CheckPayloadCommonConstraints ();
82
85
}
83
86
84
- bool PayloadContents::isValidManualCode () const
87
+ bool PayloadContents::isValidManualCode (ValidationMode mode ) const
85
88
{
86
89
// Discriminator validity is enforced by the SetupDiscriminator class.
87
-
88
90
if (setUpPINCode >= 1 << kSetupPINCodeFieldLengthInBits )
89
91
{
90
92
return false ;
@@ -109,7 +111,9 @@ bool PayloadContents::IsValidSetupPIN(uint32_t setupPIN)
109
111
110
112
bool PayloadContents::CheckPayloadCommonConstraints () const
111
113
{
112
- // A version not equal to 0 would be invalid for v1 and would indicate new format (e.g. version 2)
114
+ // Validation rules in this method apply to all validation modes.
115
+
116
+ // Even in ValidationMode::kConsume we don't understand how to handle any payload version other than 0.
113
117
if (version != 0 )
114
118
{
115
119
return false ;
0 commit comments