@@ -38,6 +38,7 @@ constexpr chip::FabricId kIdentityNullFabricId = chip::kUndefinedFabricId;
38
38
constexpr chip::FabricId kIdentityAlphaFabricId = 1 ;
39
39
constexpr chip::FabricId kIdentityBetaFabricId = 2 ;
40
40
constexpr chip::FabricId kIdentityGammaFabricId = 3 ;
41
+ constexpr chip::FabricId kIdentityOtherFabricId = 4 ;
41
42
42
43
namespace {
43
44
const chip::Credentials::AttestationTrustStore * GetTestFileAttestationTrustStore (const char * paaTrustStorePath)
@@ -113,6 +114,13 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()
113
114
ReturnLogErrorOnFailure (InitializeCommissioner (kIdentityBeta , kIdentityBetaFabricId , trustStore));
114
115
ReturnLogErrorOnFailure (InitializeCommissioner (kIdentityGamma , kIdentityGammaFabricId , trustStore));
115
116
117
+ std::string name = GetIdentity ();
118
+ chip::FabricId fabricId = strtoull (name.c_str (), nullptr , 0 );
119
+ if (fabricId >= kIdentityOtherFabricId )
120
+ {
121
+ ReturnLogErrorOnFailure (InitializeCommissioner (name.c_str (), fabricId, trustStore));
122
+ }
123
+
116
124
// Initialize Group Data, including IPK
117
125
for (auto it = mCommissioners .begin (); it != mCommissioners .end (); it++)
118
126
{
@@ -156,6 +164,13 @@ CHIP_ERROR CHIPCommand::MaybeTearDownStack()
156
164
ReturnLogErrorOnFailure (ShutdownCommissioner (kIdentityBeta ));
157
165
ReturnLogErrorOnFailure (ShutdownCommissioner (kIdentityGamma ));
158
166
167
+ std::string name = GetIdentity ();
168
+ chip::FabricId fabricId = strtoull (name.c_str (), nullptr , 0 );
169
+ if (fabricId >= kIdentityOtherFabricId )
170
+ {
171
+ ReturnLogErrorOnFailure (ShutdownCommissioner (name.c_str ()));
172
+ }
173
+
159
174
StopTracing ();
160
175
161
176
return CHIP_NO_ERROR;
@@ -201,10 +216,10 @@ void CHIPCommand::SetIdentity(const char * identity)
201
216
{
202
217
std::string name = std::string (identity);
203
218
if (name.compare (kIdentityAlpha ) != 0 && name.compare (kIdentityBeta ) != 0 && name.compare (kIdentityGamma ) != 0 &&
204
- name.compare (kIdentityNull ) != 0 )
219
+ name.compare (kIdentityNull ) != 0 && strtoull (name. c_str (), nullptr , 0 ) < kIdentityOtherFabricId )
205
220
{
206
- ChipLogError (chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s]" , name.c_str (), kIdentityAlpha ,
207
- kIdentityBeta , kIdentityGamma );
221
+ ChipLogError (chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s, 4, 5... ]" , name.c_str (),
222
+ kIdentityAlpha , kIdentityBeta , kIdentityGamma );
208
223
chipDie ();
209
224
}
210
225
@@ -217,9 +232,22 @@ std::string CHIPCommand::GetIdentity()
217
232
if (name.compare (kIdentityAlpha ) != 0 && name.compare (kIdentityBeta ) != 0 && name.compare (kIdentityGamma ) != 0 &&
218
233
name.compare (kIdentityNull ) != 0 )
219
234
{
220
- ChipLogError (chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s]" , name.c_str (), kIdentityAlpha ,
221
- kIdentityBeta , kIdentityGamma );
222
- chipDie ();
235
+ chip::FabricId fabricId = strtoull (name.c_str (), nullptr , 0 );
236
+ if (fabricId >= kIdentityOtherFabricId )
237
+ {
238
+ // normalize name since it is used in persistent storage
239
+
240
+ char s[24 ];
241
+ sprintf (s, " %" PRIu64, fabricId);
242
+
243
+ name = s;
244
+ }
245
+ else
246
+ {
247
+ ChipLogError (chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s, 4, 5...]" , name.c_str (),
248
+ kIdentityAlpha , kIdentityBeta , kIdentityGamma );
249
+ chipDie ();
250
+ }
223
251
}
224
252
225
253
return name;
@@ -246,10 +274,10 @@ chip::FabricId CHIPCommand::CurrentCommissionerId()
246
274
{
247
275
id = kIdentityNullFabricId ;
248
276
}
249
- else
277
+ else if ((id = strtoull (name. c_str (), nullptr , 0 )) < kIdentityOtherFabricId )
250
278
{
251
- VerifyOrDieWithMsg (false , chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s] " , name. c_str () ,
252
- kIdentityAlpha , kIdentityBeta , kIdentityGamma );
279
+ VerifyOrDieWithMsg (false , chipTool, " Unknown commissioner name: %s. Supported names are [%s, %s, %s, 4, 5...] " ,
280
+ name. c_str (), kIdentityAlpha , kIdentityBeta , kIdentityGamma );
253
281
}
254
282
255
283
return id;
0 commit comments