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

[border-agent] use new otBorderAgent ephemeral key APIs #2674

Merged
merged 1 commit into from
Feb 4, 2025
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
33 changes: 20 additions & 13 deletions src/border_agent/border_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ void BorderAgent::SetEphemeralKeyEnabled(bool aIsEnabled)

if (!mIsEphemeralKeyEnabled)
{
// If the ePSKc feature is enabled, we call the clear function which
// If the ePSKc feature is enabled, we call the stop function which
// will wait for the session to close if it is in active use before
// removing ephemeral key and unpublishing the service.
otBorderAgentClearEphemeralKey(mHost.GetInstance());
otBorderAgentEphemeralKeyStop(mHost.GetInstance());
}

UpdateMeshCopService();
Expand Down Expand Up @@ -281,7 +281,7 @@ void BorderAgent::Start(void)
mServiceInstanceName = GetServiceInstanceNameWithExtAddr(mBaseServiceInstanceName);
UpdateMeshCopService();

otBorderAgentSetEphemeralKeyCallback(mHost.GetInstance(), BorderAgent::HandleEpskcStateChanged, this);
otBorderAgentEphemeralKeySetCallback(mHost.GetInstance(), BorderAgent::HandleEpskcStateChanged, this);
}

void BorderAgent::Stop(void)
Expand All @@ -292,18 +292,25 @@ void BorderAgent::Stop(void)

void BorderAgent::HandleEpskcStateChanged(void *aContext)
{
BorderAgent *borderAgent = static_cast<BorderAgent *>(aContext);
static_cast<BorderAgent *>(aContext)->HandleEpskcStateChanged();
}

if (otBorderAgentIsEphemeralKeyActive(borderAgent->mHost.GetInstance()))
{
borderAgent->PublishEpskcService();
}
else
void BorderAgent::HandleEpskcStateChanged(void)
{
switch (otBorderAgentEphemeralKeyGetState(mHost.GetInstance()))
{
borderAgent->UnpublishEpskcService();
case OT_BORDER_AGENT_STATE_STARTED:
case OT_BORDER_AGENT_STATE_CONNECTED:
case OT_BORDER_AGENT_STATE_ACCEPTED:
PublishEpskcService();
break;
case OT_BORDER_AGENT_STATE_DISABLED:
case OT_BORDER_AGENT_STATE_STOPPED:
UnpublishEpskcService();
break;
}

for (auto &ephemeralKeyCallback : borderAgent->mEphemeralKeyChangedCallbacks)
for (auto &ephemeralKeyCallback : mEphemeralKeyChangedCallbacks)
{
ephemeralKeyCallback();
}
Expand All @@ -312,7 +319,7 @@ void BorderAgent::HandleEpskcStateChanged(void *aContext)
void BorderAgent::PublishEpskcService()
{
otInstance *instance = mHost.GetInstance();
int port = otBorderAgentGetUdpPort(instance);
int port = otBorderAgentEphemeralKeyGetUdpPort(instance);

otbrLogInfo("Publish meshcop-e service %s.%s.local. port %d", mServiceInstanceName.c_str(),
kBorderAgentEpskcServiceType, port);
Expand Down Expand Up @@ -583,7 +590,7 @@ void BorderAgent::PublishMeshCopService(void)

AppendVendorTxtEntries(mMeshCopTxtUpdate, txtList);

if (otBorderAgentGetState(instance) != OT_BORDER_AGENT_STATE_STOPPED)
if (otBorderAgentIsActive(instance))
{
port = otBorderAgentGetUdpPort(instance);
}
Expand Down
1 change: 1 addition & 0 deletions src/border_agent/border_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class BorderAgent : public Mdns::StateObserver, private NonCopyable
std::string GetAlternativeServiceInstanceName() const;

static void HandleEpskcStateChanged(void *aContext);
void HandleEpskcStateChanged(void);
void PublishEpskcService(void);
void UnpublishEpskcService(void);

Expand Down
24 changes: 19 additions & 5 deletions src/dbus/server/dbus_thread_object_rcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,11 +2014,25 @@ void DBusThreadObjectRcp::DeactivateEphemeralKeyModeHandler(DBusRequest &aReques
VerifyOrExit(mBorderAgent.GetEphemeralKeyEnabled(), error = OT_ERROR_NOT_CAPABLE);

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

// Stop the ephemeral key use if
// - there is no active session, or
// - there is a connected session and we should not `retain_active_session`.

switch (otBorderAgentEphemeralKeyGetState(threadHelper->GetInstance()))
{
otBorderAgentDisconnect(threadHelper->GetInstance());
case OT_BORDER_AGENT_STATE_STARTED:
break;
case OT_BORDER_AGENT_STATE_CONNECTED:
case OT_BORDER_AGENT_STATE_ACCEPTED:
VerifyOrExit(!retain_active_session);
break;
case OT_BORDER_AGENT_STATE_DISABLED:
case OT_BORDER_AGENT_STATE_STOPPED:
ExitNow();
}
otBorderAgentClearEphemeralKey(threadHelper->GetInstance());

otBorderAgentEphemeralKeyStop(threadHelper->GetInstance());

exit:
aRequest.ReplyOtResult(error);
Expand All @@ -2040,8 +2054,8 @@ void DBusThreadObjectRcp::ActivateEphemeralKeyModeHandler(DBusRequest &aRequest)
SuccessOrExit(mBorderAgent.CreateEphemeralKey(ePskc), error = OT_ERROR_INVALID_ARGS);
otbrLogInfo("Created Ephemeral Key: %s", ePskc.c_str());

SuccessOrExit(error = otBorderAgentSetEphemeralKey(threadHelper->GetInstance(), ePskc.c_str(), lifetime,
OTBR_CONFIG_BORDER_AGENT_MESHCOP_E_UDP_PORT));
SuccessOrExit(error = otBorderAgentEphemeralKeyStart(threadHelper->GetInstance(), ePskc.c_str(), lifetime,
OTBR_CONFIG_BORDER_AGENT_MESHCOP_E_UDP_PORT));

exit:
if (error == OT_ERROR_NONE)
Expand Down
Loading