Skip to content

Commit

Permalink
[darwin-framework-tool] Add GetCommissionerFabricId and use it to mak…
Browse files Browse the repository at this point in the history
…e the usage of fabridId more consistent
  • Loading branch information
vivien-apple authored and woody-apple committed Oct 25, 2024
1 parent 29dd97f commit ba82a78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
inline constexpr char kIdentityAlpha[] = "alpha";
inline constexpr char kIdentityBeta[] = "beta";
inline constexpr char kIdentityGamma[] = "gamma";
inline constexpr char kControllerIdPrefix[] = "8DCADB14-AF1F-45D0-B084-00000000000";

class CHIPCommandBridge : public Command {
public:
Expand Down Expand Up @@ -69,6 +70,8 @@ class CHIPCommandBridge : public Command {

static OTAProviderDelegate * mOTADelegate;

static NSNumber * GetCommissionerFabricId(const char * identity);

protected:
// Will be called in a setting in which it's safe to touch the CHIP
// stack. The rules for Run() are as follows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@
constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
std::string commissionerName = mCommissionerName.HasValue() ? mCommissionerName.Value() : kIdentityAlpha;
for (size_t i = 0; i < ArraySize(identities); ++i) {
__auto_type * uuidString = [NSString stringWithFormat:@"%@%@", @"8DCADB14-AF1F-45D0-B084-00000000000", @(i)];
__auto_type * fabricId = GetCommissionerFabricId(identities[i]);
__auto_type * uuidString = [NSString stringWithFormat:@"%@%@", @(kControllerIdPrefix), fabricId];
__auto_type * controllerId = [[NSUUID alloc] initWithUUIDString:uuidString];
__auto_type * vendorId = @(mCommissionerVendorId.ValueOr(chip::VendorId::TestVendor1));
__auto_type * fabricId = @(i + 1);
__auto_type * nodeId = @(chip::kTestControllerNodeId);

if (commissionerName.compare(identities[i]) == 0 && mCommissionerNodeId.HasValue()) {
Expand Down Expand Up @@ -214,7 +214,7 @@
constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma };
std::string commissionerName = mCommissionerName.HasValue() ? mCommissionerName.Value() : kIdentityAlpha;
for (size_t i = 0; i < ArraySize(identities); ++i) {
__auto_type * fabricId = @(i + 1);
__auto_type * fabricId = GetCommissionerFabricId(identities[i]);
__auto_type * params = [[MTRDeviceControllerStartupParams alloc] initWithIPK:certificateIssuer.ipk
fabricID:fabricId
nocSigner:certificateIssuer.signingKey];
Expand Down Expand Up @@ -260,14 +260,19 @@

NSNumber * CHIPCommandBridge::CurrentCommissionerFabricId()
{
if (mCurrentIdentity.compare(kIdentityAlpha) == 0) {
return GetCommissionerFabricId(mCurrentIdentity.c_str());
}

NSNumber * CHIPCommandBridge::GetCommissionerFabricId(const char * identity)
{
if (strcmp(identity, kIdentityAlpha) == 0) {
return @(1);
} else if (mCurrentIdentity.compare(kIdentityBeta) == 0) {
} else if (strcmp(identity, kIdentityBeta) == 0) {
return @(2);
} else if (mCurrentIdentity.compare(kIdentityGamma) == 0) {
} else if (strcmp(identity, kIdentityGamma) == 0) {
return @(3);
} else {
ChipLogError(chipTool, "Unknown commissioner name: %s. Supported names are [%s, %s, %s]", mCurrentIdentity.c_str(), kIdentityAlpha,
ChipLogError(chipTool, "Unknown commissioner name: %s. Supported names are [%s, %s, %s]", identity, kIdentityAlpha,
kIdentityBeta, kIdentityGamma);
chipDie();
}
Expand Down

0 comments on commit ba82a78

Please sign in to comment.