@@ -33,12 +33,12 @@ namespace {
33
33
// Constants
34
34
constexpr uint32_t kSetupPinCode = 20202021 ;
35
35
constexpr uint16_t kRemoteBridgePort = 5540 ;
36
- constexpr uint16_t kDiscriminator = 3840 ;
37
36
constexpr uint16_t kWindowTimeout = 300 ;
38
37
constexpr uint16_t kIteration = 1000 ;
39
38
constexpr uint16_t kSubscribeMinInterval = 0 ;
40
39
constexpr uint16_t kSubscribeMaxInterval = 60 ;
41
40
constexpr uint16_t kAggragatorEndpointId = 1 ;
41
+ constexpr uint16_t kMaxDiscriminatorLength = 4095 ;
42
42
constexpr uint8_t kEnhancedCommissioningMethod = 1 ;
43
43
44
44
} // namespace
@@ -118,7 +118,7 @@ void DeviceManager::OpenDeviceCommissioningWindow(NodeId nodeId, uint32_t commis
118
118
uint32_t discriminator, const char * saltHex, const char * verifierHex)
119
119
{
120
120
// Open the commissioning window of a device within its own fabric.
121
- StringBuilder<512 > commandBuilder;
121
+ StringBuilder<kMaxCommandSize > commandBuilder;
122
122
123
123
commandBuilder.Add (" pairing open-commissioning-window " );
124
124
commandBuilder.AddFormat (" %lu %d %d %d %d %d --salt hex:%s --verifier hex:%s" , nodeId, kRootEndpointId ,
@@ -132,11 +132,16 @@ void DeviceManager::OpenRemoteDeviceCommissioningWindow(EndpointId remoteEndpoin
132
132
// Open the commissioning window of a device from another fabric via its fabric bridge.
133
133
// This method constructs and sends a command to open the commissioning window for a device
134
134
// that is part of a different fabric, accessed through a fabric bridge.
135
- StringBuilder<kMaxCommandSize > commandBuilder;
135
+ StringBuilder<512 > commandBuilder;
136
+
137
+ // Use random discriminator to have less chance of collission.
138
+ uint16_t discriminator =
139
+ Crypto::GetRandU16 () % (kMaxDiscriminatorLength + 1 ); // Include the upper limit kMaxDiscriminatorLength
136
140
137
141
commandBuilder.Add (" pairing open-commissioning-window " );
138
142
commandBuilder.AddFormat (" %lu %d %d %d %d %d" , mRemoteBridgeNodeId , remoteEndpointId, kEnhancedCommissioningMethod ,
139
- kWindowTimeout , kIteration , kDiscriminator );
143
+ kWindowTimeout , kIteration , discriminator);
144
+ commandBuilder.Add (" --setup-pin 20202021" );
140
145
141
146
PushCommand (commandBuilder.c_str ());
142
147
}
0 commit comments