Skip to content

Commit

Permalink
Add a way to ask a CommandHandler for a fabric index. (#12005)
Browse files Browse the repository at this point in the history
This returns the accessing fabric index.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jun 24, 2023
1 parent b4b78e7 commit 3654861
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
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

0 comments on commit 3654861

Please sign in to comment.