Skip to content

Commit

Permalink
[border-agent] check ba state to return deactivate errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhyang committed Sep 19, 2024
1 parent 87bcb81 commit 9f69c73
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/dbus/server/dbus_thread_object_rcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,23 @@ void DBusThreadObjectRcp::DeactivateEphemeralKeyModeHandler(DBusRequest &aReques
otError error = OT_ERROR_NONE;
auto threadHelper = mHost.GetThreadHelper();

if (!mBorderAgent.GetEphemeralKeyEnabled())
{
error = OT_ERROR_INVALID_STATE;
aRequest.ReplyOtResult(error);
otbrLogInfo("Failed to deactivate Ephemeral Key due to feature is not enabled");
return;
}

if (otBorderAgentGetState(threadHelper->GetInstance()) != OT_BORDER_AGENT_STATE_STARTED)
{
error = OT_ERROR_INVALID_STATE;
aRequest.ReplyOtResult(error);
otbrLogInfo("Failed to deactivate Ephemeral Key. Border Agent State: %s",
otBorderAgentGetState(threadHelper->GetInstance()) ? "active" : "stopped");
return;
}

otBorderAgentClearEphemeralKey(threadHelper->GetInstance());
aRequest.ReplyOtResult(error);
}
Expand All @@ -2022,6 +2039,14 @@ void DBusThreadObjectRcp::ActivateEphemeralKeyModeHandler(DBusRequest &aRequest)
auto args = std::tie(lifetime);
std::string ePskc;

if (!mBorderAgent.GetEphemeralKeyEnabled())
{
error = OT_ERROR_INVALID_STATE;
aRequest.ReplyOtResult(error);
otbrLogInfo("Failed to activate Ephemeral Key due to feature is not enabled");
return;
}

SuccessOrExit(DBusMessageToTuple(*aRequest.GetMessage(), args), error = OT_ERROR_INVALID_ARGS);

SuccessOrExit(mBorderAgent.CreateEphemeralKey(ePskc), error = OT_ERROR_INVALID_ARGS);
Expand Down

0 comments on commit 9f69c73

Please sign in to comment.