Skip to content

Commit

Permalink
[DO NOT REVIEW][epskc] prototype of publishing _meshcop-e._udp
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtdkp committed Apr 13, 2024
1 parent 2533f31 commit 9b65d7f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
8 changes: 4 additions & 4 deletions script/setup
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ main()
dhcpv6_pd_uninstall
nat64_uninstall
dns64_uninstall
rt_tables_uninstall
#rt_tables_uninstall
ipforward_uninstall
firewall_uninstall
# firewall_uninstall

firewall_install
#firewall_install
ipforward_install
rt_tables_install
#rt_tables_install
nat64_install
dns64_install
network_manager_install
Expand Down
56 changes: 56 additions & 0 deletions src/border_agent/border_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
namespace otbr {

static const char kBorderAgentServiceType[] = "_meshcop._udp"; ///< Border agent service type of mDNS
static const char kEpskcServiceType[] = "_meshcop-e._udp";
static constexpr int kBorderAgentServiceDummyPort = 49152;

/**
Expand Down Expand Up @@ -202,6 +203,61 @@ void BorderAgent::Start(void)

mServiceInstanceName = GetServiceInstanceNameWithExtAddr(mBaseServiceInstanceName);
UpdateMeshCopService();

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

void BorderAgent::HandleEpskcStateChanged(void *aContext)
{
BorderAgent* borderAgent = static_cast<BorderAgent*>(aContext);
if (otBorderAgentIsEphemeralKeyActive(borderAgent->mNcp.GetInstance())) {
borderAgent->PublishEpskcService();
} else {
borderAgent->UnpublishEpskcService();
}
}

void BorderAgent::PublishEpskcService() {
otInstance *instance = mNcp.GetInstance();
int port = otBorderAgentGetUdpPort(instance);
Mdns::Publisher::TxtData txtData;

otbrLogInfo("Publish meshcop-e service %s.%s.local.", mServiceInstanceName.c_str(), kEpskcServiceType);

mPublisher.PublishService(/* aHostName */ "", mServiceInstanceName, kEpskcServiceType,
Mdns::Publisher::SubTypeList{}, port, txtData, [this](otbrError aError) {
if (aError == OTBR_ERROR_ABORTED)
{
// OTBR_ERROR_ABORTED is thrown when an ongoing service registration is
// cancelled. This can happen when the meshcop service is being updated
// frequently. To avoid false alarms, it should not be logged like a real error.
otbrLogInfo("Cancelled previous publishing meshcop service %s.%s.local",
mServiceInstanceName.c_str(), kEpskcServiceType);
}
else
{
otbrLogResult(aError, "Result of publish meshcop service %s.%s.local",
mServiceInstanceName.c_str(), kEpskcServiceType);
}
if (aError == OTBR_ERROR_DUPLICATED)
{
// Try to unpublish current service in case we are trying to register
// multiple new services simultaneously when the original service name
// is conflicted.
UnpublishEpskcService();
mServiceInstanceName = GetAlternativeServiceInstanceName();
PublishEpskcService();
}
});
}

void BorderAgent::UnpublishEpskcService() {
otbrLogInfo("Unpublish meshcop-e service %s.%s.local", mServiceInstanceName.c_str(), kEpskcServiceType);

mPublisher.UnpublishService(mServiceInstanceName, kEpskcServiceType, [this](otbrError aError) {
otbrLogResult(aError, "Result of unpublish meshcop service %s.%s.local", mServiceInstanceName.c_str(),
kEpskcServiceType);
});
}

void BorderAgent::Stop(void)
Expand Down
4 changes: 4 additions & 0 deletions src/border_agent/border_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class BorderAgent : private NonCopyable

void HandleThreadStateChanged(otChangedFlags aFlags);

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

bool IsThreadStarted(void) const;
std::string GetServiceInstanceNameWithExtAddr(const std::string &aServiceInstanceName) const;
std::string GetAlternativeServiceInstanceName() const;
Expand Down
4 changes: 4 additions & 0 deletions third_party/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ if (NOT OT_THREAD_VERSION STREQUAL "1.1")
"-DOPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE=1"
)
endif()

target_compile_definitions(ot-config INTERFACE
"-DOPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE=1"
)

0 comments on commit 9b65d7f

Please sign in to comment.