Skip to content

Commit

Permalink
Fix a few issues with ESPKC flags and OTBR versions.
Browse files Browse the repository at this point in the history
* Throw a fatal error if OTBR_ESPKC flag is enabled for Thread versions < 1.4
* Wrap some ephemeral key API calls with `OTBR_ENABLE_EPSKC`
* Enable passing OTBR_EPSKC flag for Docker builds
* Fix a small nit in `ncp_spinel.cpp` related to a dummy va_list variable being uninitialized. It causes problems with certain architectures and compiler flags, and initializing it using va_start doesn't work since it's not in a variadic function.
  • Loading branch information
suveshpratapa committed Jul 22, 2024
1 parent 9f69fd0 commit bd336f6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion etc/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ if(OTBR_TREL)
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_TREL=1)
endif()

option(OTBR_EPSKC "Enable ephemeral PSKc" ON)
option(OTBR_EPSKC "Enable ephemeral PSKc" OFF)
if (OTBR_EPSKC)
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_EPSKC=1)
else()
Expand Down
2 changes: 2 additions & 0 deletions etc/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ARG INFRA_IF_NAME
ARG BORDER_ROUTING
ARG BACKBONE_ROUTER
ARG OT_BACKBONE_CI
ARG OTBR_EPSKC
ARG OTBR_OPTIONS
ARG DNS64
ARG NAT64
Expand All @@ -48,6 +49,7 @@ ENV INFRA_IF_NAME=${INFRA_IF_NAME:-eth0}
ENV BORDER_ROUTING=${BORDER_ROUTING:-1}
ENV BACKBONE_ROUTER=${BACKBONE_ROUTER:-1}
ENV OT_BACKBONE_CI=${OT_BACKBONE_CI:-0}
ENV OTBR_EPSKC=${OTBR_EPSKC:-0}
ENV OTBR_MDNS=${MDNS:-mDNSResponder}
ENV OTBR_OPTIONS=${OTBR_OPTIONS}
ENV DEBIAN_FRONTEND noninteractive
Expand Down
13 changes: 13 additions & 0 deletions script/_otbr
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ readonly OTBR_OPTIONS
REFERENCE_DEVICE="${REFERENCE_DEVICE:-0}"
readonly REFERENCE_DEVICE

OTBR_EPSKC="${OTBR_EPSKC:-0}"
readonly OTBR_EPSKC

otbr_uninstall()
{
if have systemctl; then
Expand Down Expand Up @@ -106,6 +109,16 @@ otbr_install()
fi
fi

if [[ ${OTBR_EPSKC} == "1" ]]; then
otbr_options+=(
"-DOTBR_EPSKC=ON"
)
else
otbr_options+=(
"-DOTBR_EPSKC=OFF"
)
fi

if [[ ${REFERENCE_DEVICE} == "1" ]]; then
otbr_options+=(
"-DOTBR_NO_AUTO_ATTACH=1"
Expand Down
12 changes: 9 additions & 3 deletions src/border_agent/border_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@

namespace otbr {

static const char kBorderAgentServiceType[] = "_meshcop._udp"; ///< Border agent service type of mDNS
static const char kBorderAgentEpskcServiceType[] = "_meshcop-e._udp"; ///< Border agent ePSKc service
static constexpr int kBorderAgentServiceDummyPort = 49152;
static const char kBorderAgentServiceType[] = "_meshcop._udp"; ///< Border agent service type of mDNS
#if OTBR_ENABLE_EPSKC
static const char kBorderAgentEpskcServiceType[] = "_meshcop-e._udp"; ///< Border agent ePSKc service
#endif
static constexpr int kBorderAgentServiceDummyPort = 49152;

/**
* Locators
Expand Down Expand Up @@ -226,7 +228,9 @@ void BorderAgent::Start(void)
mServiceInstanceName = GetServiceInstanceNameWithExtAddr(mBaseServiceInstanceName);
UpdateMeshCopService();

#if OTBR_ENABLE_EPSKC
otBorderAgentSetEphemeralKeyCallback(mHost.GetInstance(), BorderAgent::HandleEpskcStateChanged, this);
#endif
}

void BorderAgent::Stop(void)
Expand All @@ -235,6 +239,7 @@ void BorderAgent::Stop(void)
UnpublishMeshCopService();
}

#if OTBR_ENABLE_EPSKC
void BorderAgent::HandleEpskcStateChanged(void *aContext)
{
BorderAgent *borderAgent = static_cast<BorderAgent *>(aContext);
Expand Down Expand Up @@ -295,6 +300,7 @@ void BorderAgent::UnpublishEpskcService()
kBorderAgentEpskcServiceType);
});
}
#endif

void BorderAgent::HandleMdnsState(Mdns::Publisher::State aState)
{
Expand Down
2 changes: 2 additions & 0 deletions src/border_agent/border_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ class BorderAgent : private NonCopyable
std::string GetServiceInstanceNameWithExtAddr(const std::string &aServiceInstanceName) const;
std::string GetAlternativeServiceInstanceName() const;

#if OTBR_ENABLE_EPSKC
static void HandleEpskcStateChanged(void *aContext);
void PublishEpskcService(void);
void UnpublishEpskcService(void);
#endif

otbr::Ncp::RcpHost &mHost;
Mdns::Publisher &mPublisher;
Expand Down
3 changes: 2 additions & 1 deletion src/ncp/ncp_spinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ void NcpSpinel::GetDeviceRole(GetDeviceRoleHandler aHandler)
{
otError error = OT_ERROR_NONE;
spinel_tid_t tid = GetNextTid();
va_list args;
va_list args = {};

error = mSpinelDriver->SendCommand(SPINEL_CMD_PROP_VALUE_GET, SPINEL_PROP_NET_ROLE, tid, nullptr, args);

if (error != OT_ERROR_NONE)
{
FreeTid(tid);
Expand Down
6 changes: 5 additions & 1 deletion third_party/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set(OT_ANYCAST_LOCATOR ON CACHE STRING "enable anycast locator" FORCE)
set(OT_BACKBONE_ROUTER ${OTBR_BACKBONE_ROUTER} CACHE STRING "Enable Backbone Router feature in OpenThread" FORCE)
set(OT_BACKBONE_ROUTER_DUA_NDPROXYING ${OTBR_DUA_ROUTING} CACHE STRING "Configure DUA ND Proxy feature in OpenThread" FORCE)
set(OT_BORDER_AGENT ON CACHE STRING "enable border agent" FORCE)
set(OT_BORDER_AGENT_EPSKC ON CACHE STRING "enable border agent ephemeral PSKc" FORCE)
set(OT_BORDER_AGENT_EPSKC ${OTBR_EPSKC} CACHE STRING "enable border agent ephemeral PSKc" FORCE)
set(OT_BORDER_AGENT_ID ON CACHE STRING "enable border agent ID" FORCE)
set(OT_BORDER_ROUTER ON CACHE STRING "enable border router feature" FORCE)
set(OT_BORDER_ROUTING ${OTBR_BORDER_ROUTING} CACHE STRING "enable border routing feature" FORCE)
Expand Down Expand Up @@ -85,6 +85,10 @@ if (NOT OT_THREAD_VERSION STREQUAL "1.1")
set(OT_LINK_METRICS_SUBJECT ON CACHE STRING "enable link metrics subject" FORCE)
endif()

if ((OT_BORDER_AGENT_EPSKC) AND (NOT OT_THREAD_VERSION STREQUAL "1.4"))
message(FATAL_ERROR "ePSKc requires Thread protocol version >= 1.4")
endif()

if (NOT OT_LOG_LEVEL)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(OT_LOG_LEVEL "DEBG" CACHE STRING "set OpenThread log level to DEBG" FORCE)
Expand Down

0 comments on commit bd336f6

Please sign in to comment.