Skip to content

Commit 1467180

Browse files
bluebin14pull[bot]
authored andcommitted
chip-tool: allow any fabricId, up to a total of 17 (#17052)
* chip-tool: allow any fabricId, up to a total of 17 * chip-tool: fix compiler warning on Linux
1 parent 666b462 commit 1467180

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

examples/chip-tool/commands/common/CHIPCommand.cpp

+37-9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ constexpr chip::FabricId kIdentityNullFabricId = chip::kUndefinedFabricId;
3838
constexpr chip::FabricId kIdentityAlphaFabricId = 1;
3939
constexpr chip::FabricId kIdentityBetaFabricId = 2;
4040
constexpr chip::FabricId kIdentityGammaFabricId = 3;
41+
constexpr chip::FabricId kIdentityOtherFabricId = 4;
4142

4243
namespace {
4344
const chip::Credentials::AttestationTrustStore * GetTestFileAttestationTrustStore(const char * paaTrustStorePath)
@@ -113,6 +114,13 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()
113114
ReturnLogErrorOnFailure(InitializeCommissioner(kIdentityBeta, kIdentityBetaFabricId, trustStore));
114115
ReturnLogErrorOnFailure(InitializeCommissioner(kIdentityGamma, kIdentityGammaFabricId, trustStore));
115116

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+
116124
// Initialize Group Data, including IPK
117125
for (auto it = mCommissioners.begin(); it != mCommissioners.end(); it++)
118126
{
@@ -156,6 +164,13 @@ CHIP_ERROR CHIPCommand::MaybeTearDownStack()
156164
ReturnLogErrorOnFailure(ShutdownCommissioner(kIdentityBeta));
157165
ReturnLogErrorOnFailure(ShutdownCommissioner(kIdentityGamma));
158166

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+
159174
StopTracing();
160175

161176
return CHIP_NO_ERROR;
@@ -201,10 +216,10 @@ void CHIPCommand::SetIdentity(const char * identity)
201216
{
202217
std::string name = std::string(identity);
203218
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)
205220
{
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);
208223
chipDie();
209224
}
210225

@@ -217,9 +232,22 @@ std::string CHIPCommand::GetIdentity()
217232
if (name.compare(kIdentityAlpha) != 0 && name.compare(kIdentityBeta) != 0 && name.compare(kIdentityGamma) != 0 &&
218233
name.compare(kIdentityNull) != 0)
219234
{
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+
}
223251
}
224252

225253
return name;
@@ -246,10 +274,10 @@ chip::FabricId CHIPCommand::CurrentCommissionerId()
246274
{
247275
id = kIdentityNullFabricId;
248276
}
249-
else
277+
else if ((id = strtoull(name.c_str(), nullptr, 0)) < kIdentityOtherFabricId)
250278
{
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);
253281
}
254282

255283
return id;

examples/chip-tool/include/CHIPProjectAppConfig.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#ifndef CHIPPROJECTCONFIG_H
2424
#define CHIPPROJECTCONFIG_H
2525

26+
#define CHIP_CONFIG_MAX_FABRICS 17
27+
2628
#define CHIP_CONFIG_ENABLE_EPHEMERAL_UDP_PORT 1
2729

2830
#define CHIP_CONFIG_EVENT_LOGGING_NUM_EXTERNAL_CALLBACKS 2

0 commit comments

Comments
 (0)