@@ -36,60 +36,43 @@ 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
- if (version >= 1 << kVersionFieldLengthInBits )
43
- {
44
- return false ;
45
- }
42
+ VerifyOrReturnValue (version < (1 << kVersionFieldLengthInBits ), false );
46
43
47
- if (static_cast <uint8_t >(commissioningFlow) > static_cast <uint8_t >((1 << kCommissioningFlowFieldLengthInBits ) - 1 ))
48
- {
49
- return false ;
50
- }
44
+ VerifyOrReturnValue (static_cast <uint8_t >(commissioningFlow) < (1 << kCommissioningFlowFieldLengthInBits ), false );
51
45
52
46
// Device Commissioning Flow
47
+ // Even in ValidationMode::kConsume we can only handle modes that we understand.
53
48
// 0: Standard commissioning flow: such a device, when uncommissioned, always enters commissioning mode upon power-up, subject
54
49
// to the rules in [ref_Announcement_Commencement]. 1: User-intent commissioning flow: user action required to enter
55
50
// commissioning mode. 2: Custom commissioning flow: interaction with a vendor-specified means is needed before commissioning.
56
51
// 3: Reserved
57
- if (commissioningFlow != CommissioningFlow::kStandard && commissioningFlow != CommissioningFlow::kUserActionRequired &&
58
- commissioningFlow != CommissioningFlow::kCustom )
59
- {
60
- return false ;
61
- }
62
-
63
- chip::RendezvousInformationFlags allvalid (RendezvousInformationFlag::kBLE , RendezvousInformationFlag::kOnNetwork ,
64
- RendezvousInformationFlag::kSoftAP );
65
- if (!rendezvousInformation.HasValue () || !rendezvousInformation.Value ().HasOnly (allvalid))
66
- {
67
- return false ;
68
- }
52
+ VerifyOrReturnValue (commissioningFlow == CommissioningFlow::kStandard ||
53
+ commissioningFlow == CommissioningFlow::kUserActionRequired ||
54
+ commissioningFlow == CommissioningFlow::kCustom ,
55
+ false );
69
56
70
57
// General discriminator validity is enforced by the SetupDiscriminator class, but it can't be short for QR a code.
71
- if (discriminator.IsShortDiscriminator ())
72
- {
73
- return false ;
74
- }
58
+ VerifyOrReturnValue (!discriminator.IsShortDiscriminator (), false );
75
59
76
- if (setUpPINCode >= 1 << kSetupPINCodeFieldLengthInBits )
60
+ // RendevouzInformation must be present for a QR code.
61
+ VerifyOrReturnValue (rendezvousInformation.HasValue (), false );
62
+ if (mode == ValidationMode::kProduce )
77
63
{
78
- return false ;
64
+ chip::RendezvousInformationFlags valid (RendezvousInformationFlag::kBLE , RendezvousInformationFlag::kOnNetwork ,
65
+ RendezvousInformationFlag::kSoftAP );
66
+ VerifyOrReturnValue (rendezvousInformation.Value ().HasOnly (valid), false );
79
67
}
80
68
81
69
return CheckPayloadCommonConstraints ();
82
70
}
83
71
84
- bool PayloadContents::isValidManualCode () const
72
+ bool PayloadContents::isValidManualCode (ValidationMode mode ) const
85
73
{
86
- // Discriminator validity is enforced by the SetupDiscriminator class.
87
-
88
- if (setUpPINCode >= 1 << kSetupPINCodeFieldLengthInBits )
89
- {
90
- return false ;
91
- }
92
-
74
+ // No additional constraints apply to Manual Pairing Codes.
75
+ // (If the payload has a long discriminator it will be converted automatically.)
93
76
return CheckPayloadCommonConstraints ();
94
77
}
95
78
@@ -109,31 +92,22 @@ bool PayloadContents::IsValidSetupPIN(uint32_t setupPIN)
109
92
110
93
bool PayloadContents::CheckPayloadCommonConstraints () const
111
94
{
112
- // A version not equal to 0 would be invalid for v1 and would indicate new format (e.g. version 2)
113
- if (version != 0 )
114
- {
115
- return false ;
116
- }
95
+ // Validation rules in this method apply to all validation modes.
117
96
118
- if (! IsValidSetupPIN (setUpPINCode))
119
- {
120
- return false ;
121
- }
97
+ // Even in ValidationMode::kConsume we don't understand how to handle any payload version other than 0.
98
+ VerifyOrReturnValue (version == 0 , false );
99
+
100
+ VerifyOrReturnValue ( IsValidSetupPIN (setUpPINCode), false );
122
101
123
102
// VendorID must be unspecified (0) or in valid range expected.
124
- if (!IsVendorIdValidOperationally (vendorID) && (vendorID != VendorId::Unspecified))
125
- {
126
- return false ;
127
- }
103
+ VerifyOrReturnValue ((vendorID == VendorId::Unspecified) || IsVendorIdValidOperationally (vendorID), false );
128
104
129
105
// A value of 0x0000 SHALL NOT be assigned to a product since Product ID = 0x0000 is used for these specific cases:
130
106
// * To announce an anonymized Product ID as part of device discovery
131
107
// * To indicate an OTA software update file applies to multiple Product IDs equally.
132
108
// * To avoid confusion when presenting the Onboarding Payload for ECM with multiple nodes
133
- if (productID == 0 && vendorID != VendorId::Unspecified)
134
- {
135
- return false ;
136
- }
109
+ // In these special cases the vendorID must be 0 (Unspecified)
110
+ VerifyOrReturnValue (productID != 0 || vendorID == VendorId::Unspecified, false );
137
111
138
112
return true ;
139
113
}
0 commit comments