Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to ask a CommandHandler for a fabric index. #12005

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ TLV::TLVWriter * CommandHandler::GetCommandDataIBTLVWriter()
}
}

FabricIndex CommandHandler::GetAccessingFabricIndex() const
{
return mpExchangeCtx->GetSessionHandle().GetFabricIndex();
}

CommandHandler * CommandHandler::Handle::Get()
{
return (mMagic == InteractionModelEngine::GetInstance()->GetMagicNumber()) ? mpHandler : nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/app/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class CommandHandler : public Command
CHIP_ERROR PrepareStatus(const CommandPathParams & aCommandPathParams);
CHIP_ERROR FinishStatus();
TLV::TLVWriter * GetCommandDataIBTLVWriter();
FabricIndex GetAccessingFabricIndex() const;

/**
* API for adding a data response. The template parameter T is generally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,9 @@ void fabricListChanged()
OperationalCredentials::Attributes::CommissionedFabrics::Id);
}

static FabricInfo * retrieveCurrentFabric()
static FabricInfo * retrieveCurrentFabric(CommandHandler * aCommandHandler)
{
if (emberAfCurrentCommand()->source == nullptr)
{
return nullptr;
}

FabricIndex index = emberAfCurrentCommand()->source->GetSessionHandle().GetFabricIndex();
FabricIndex index = aCommandHandler->GetAccessingFabricIndex();
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Finding fabric with fabricIndex %d", index);
return Server::GetInstance().GetFabricTable().FindFabricWithIndex(index);
}
Expand Down Expand Up @@ -278,7 +273,7 @@ bool emberAfOperationalCredentialsClusterRemoveFabricCallback(app::CommandHandle
if (err == CHIP_NO_ERROR)
{
chip::Messaging::ExchangeContext * ec = commandObj->GetExchangeContext();
FabricIndex currentFabricIndex = ec->GetSessionHandle().GetFabricIndex();
FabricIndex currentFabricIndex = commandObj->GetAccessingFabricIndex();
if (currentFabricIndex == fabricBeingRemoved)
{
// If the current fabric is being removed, expiring all the secure sessions causes crashes as
Expand Down Expand Up @@ -309,7 +304,7 @@ bool emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(app::CommandH
CHIP_ERROR err;

// Fetch current fabric
FabricInfo * fabric = retrieveCurrentFabric();
FabricInfo * fabric = retrieveCurrentFabric(commandObj);
VerifyOrExit(fabric != nullptr, status = EMBER_ZCL_STATUS_FAILURE);

// Set Label on fabric
Expand Down Expand Up @@ -442,7 +437,7 @@ bool emberAfOperationalCredentialsClusterUpdateNOCCallback(app::CommandHandler *
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: an administrator has updated the Op Cert");

// Fetch current fabric
FabricInfo * fabric = retrieveCurrentFabric();
FabricInfo * fabric = retrieveCurrentFabric(commandObj);
VerifyOrExit(fabric != nullptr, nocResponse = ConvertToNOCResponseStatus(CHIP_ERROR_INVALID_FABRIC_ID));

err = fabric->SetNOCCert(NOCValue);
Expand Down