Skip to content

Commit

Permalink
Merge branch 'openthread:main' into pd_daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsong-cnyn authored Dec 18, 2024
2 parents e5095fa + d38b598 commit 649fbd7
Show file tree
Hide file tree
Showing 32 changed files with 1,594 additions and 79 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ jobs:
submodules: true
- name: Bootstrap
run: |
rm -f /usr/local/bin/2to3*
rm -f /usr/local/bin/idle3*
rm -f /usr/local/bin/pydoc3*
rm -f /usr/local/bin/python3*
brew update
brew unlink pkg-config
brew reinstall boost cmake dbus jsoncpp ninja protobuf@21 pkg-config
brew reinstall boost jsoncpp ninja protobuf@21
- name: Build
run: |
OTBR_OPTIONS="-DOTBR_BORDER_AGENT=OFF \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ncp_mode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
OTBR_MDNS: ${{ matrix.mdns }}
OTBR_COVERAGE: 1
OTBR_VERBOSE: 1
OTBR_OPTIONS: "-DCMAKE_BUILD_TYPE=Debug -DOT_THREAD_VERSION=1.4 -DOTBR_COVERAGE=ON -DOTBR_DBUS=ON -DOTBR_FEATURE_FLAGS=ON -DOTBR_TELEMETRY_DATA_API=ON -DOTBR_UNSECURE_JOIN=ON -DOTBR_TREL=ON -DBUILD_TESTING=OFF"
OTBR_OPTIONS: "-DCMAKE_BUILD_TYPE=Debug -DOT_THREAD_VERSION=1.4 -DOTBR_COVERAGE=ON -DOTBR_DBUS=ON -DOTBR_FEATURE_FLAGS=ON -DOTBR_TELEMETRY_DATA_API=ON -DOTBR_UNSECURE_JOIN=ON -DOTBR_TREL=ON -DOTBR_SRP_ADVERTISING_PROXY=ON -DBUILD_TESTING=OFF"
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -76,6 +76,6 @@ jobs:
--build-arg OTBR_OPTIONS="${OTBR_OPTIONS}"
- name: Run
run: |
top_builddir="./build/temp" tests/scripts/ncp_mode build_ot_sim expect
top_builddir="./build/temp" tests/scripts/ncp_mode build_ot_sim expect
- name: Codecov
uses: codecov/codecov-action@v5
2 changes: 1 addition & 1 deletion examples/platforms/debian/default
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
NAT64=0
DNS64=0
DHCPV6_PD=0
DHCPV6_PD_REF=1
DHCPV6_PD_REF=0
NETWORK_MANAGER=0
BACKBONE_ROUTER=1
BORDER_ROUTING=1
Expand Down
2 changes: 1 addition & 1 deletion examples/platforms/raspbian/default
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
NAT64=1
DNS64=0
DHCPV6_PD=0
DHCPV6_PD_REF=1
DHCPV6_PD_REF=0
NETWORK_MANAGER=0
BACKBONE_ROUTER=1
BORDER_ROUTING=1
Expand Down
10 changes: 9 additions & 1 deletion src/agent/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,22 @@ void Application::DeinitRcpMode(void)

void Application::InitNcpMode(void)
{
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
otbr::Ncp::NcpHost &ncpHost = static_cast<otbr::Ncp::NcpHost &>(mHost);
ncpHost.SetMdnsPublisher(mPublisher.get());
mMdnsStateSubject.AddObserver(ncpHost);
mPublisher->Start();
#endif
#if OTBR_ENABLE_DBUS_SERVER
mDBusAgent->Init(*mBorderAgent);
#endif
}

void Application::DeinitNcpMode(void)
{
/* empty */
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
mPublisher->Stop();
#endif
}

} // namespace otbr
1 change: 1 addition & 0 deletions src/agent/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#if OTBR_ENABLE_BORDER_AGENT
#include "border_agent/border_agent.hpp"
#endif
#include "ncp/ncp_host.hpp"
#include "ncp/rcp_host.hpp"
#if OTBR_ENABLE_BACKBONE_ROUTER
#include "backbone_router/backbone_agent.hpp"
Expand Down
12 changes: 9 additions & 3 deletions src/agent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "ncp/thread_host.hpp"

#ifdef OTBR_ENABLE_PLATFORM_ANDROID
#include <log/log.h>
#ifndef __ANDROID__
#error "OTBR_ENABLE_PLATFORM_ANDROID can be enabled for only Android devices"
#endif
Expand Down Expand Up @@ -177,16 +178,21 @@ static void OnAllocateFailed(void)

static otbrLogLevel GetDefaultLogLevel(void)
{
otbrLogLevel level = OTBR_LOG_INFO;

#if OTBR_ENABLE_PLATFORM_ANDROID
char value[PROPERTY_VALUE_MAX];
// The log level is set to DEBUG by default, the final output log will be filtered by Android log system.
otbrLogLevel level = OTBR_LOG_DEBUG;
char value[PROPERTY_VALUE_MAX];

// Set the Android log level to INFO by default.
__android_log_set_minimum_priority(ANDROID_LOG_INFO);

property_get("ro.build.type", value, "user");
if (!strcmp(value, "user"))
{
level = OTBR_LOG_WARNING;
}
#else
otbrLogLevel level = OTBR_LOG_INFO;
#endif

return level;
Expand Down
20 changes: 20 additions & 0 deletions src/common/api_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,23 @@ std::string GetDhcp6PdStateName(otBorderRoutingDhcp6PdState aState)
return stateName;
}
#endif // OTBR_ENABLE_DHCP6_PD

std::string GetCommissionerStateName(otCommissionerState aState)
{
std::string stateName;

switch (aState)
{
case OT_COMMISSIONER_STATE_DISABLED:
stateName = OTBR_COMMISSIONER_STATE_NAME_DISABLED;
break;
case OT_COMMISSIONER_STATE_PETITION:
stateName = OTBR_COMMISSIONER_STATE_NAME_PETITION;
break;
case OT_COMMISSIONER_STATE_ACTIVE:
stateName = OTBR_COMMISSIONER_STATE_NAME_ACTIVE;
break;
}

return stateName;
}
6 changes: 6 additions & 0 deletions src/common/api_strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@
#define OTBR_DHCP6_PD_STATE_NAME_IDLE "idle"
#endif

#define OTBR_COMMISSIONER_STATE_NAME_DISABLED "disabled"
#define OTBR_COMMISSIONER_STATE_NAME_PETITION "petitioning"
#define OTBR_COMMISSIONER_STATE_NAME_ACTIVE "active"

std::string GetDeviceRoleName(otDeviceRole aRole);

#if OTBR_ENABLE_DHCP6_PD
std::string GetDhcp6PdStateName(otBorderRoutingDhcp6PdState aDhcp6PdState);
#endif // OTBR_ENABLE_DHCP6_PD

std::string GetCommissionerStateName(otCommissionerState aState);

#endif // OTBR_COMMON_API_STRINGS_HPP_
64 changes: 57 additions & 7 deletions src/common/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include <sys/time.h>
#include <syslog.h>

#if OTBR_ENABLE_PLATFORM_ANDROID
#include <log/log.h>
#endif

#include <sstream>

#include "common/code_utils.hpp"
Expand Down Expand Up @@ -87,20 +91,25 @@ void otbrLogSyslogSetEnabled(bool aEnabled)
/** Initialize logging */
void otbrLogInit(const char *aProgramName, otbrLogLevel aLevel, bool aPrintStderr, bool aSyslogDisable)
{
const char *ident;

assert(aProgramName != nullptr);
assert(aLevel >= OTBR_LOG_EMERG && aLevel <= OTBR_LOG_DEBUG);

ident = strrchr(aProgramName, '/');
ident = (ident != nullptr) ? ident + 1 : aProgramName;

otbrLogSyslogSetEnabled(!aSyslogDisable);

#if OTBR_ENABLE_PLATFORM_ANDROID
OTBR_UNUSED_VARIABLE(aProgramName);
#else
assert(aProgramName != nullptr);

if (!sSyslogDisabled)
{
const char *ident;

ident = strrchr(aProgramName, '/');
ident = (ident != nullptr) ? ident + 1 : aProgramName;

openlog(ident, (LOG_CONS | LOG_PID) | (aPrintStderr ? LOG_PERROR : 0), OTBR_SYSLOG_FACILITY_ID);
}
#endif

sLevel = aLevel;
sDefaultLevel = sLevel;
}
Expand Down Expand Up @@ -130,6 +139,38 @@ static const char *GetPrefix(const char *aLogTag)
return prefix;
}

#if OTBR_ENABLE_PLATFORM_ANDROID
static android_LogPriority ConvertToAndroidLogPriority(otbrLogLevel aLevel)
{
android_LogPriority priority;

switch (aLevel)
{
case OTBR_LOG_EMERG:
case OTBR_LOG_ALERT:
case OTBR_LOG_CRIT:
priority = ANDROID_LOG_FATAL;
break;
case OTBR_LOG_ERR:
priority = ANDROID_LOG_ERROR;
break;
case OTBR_LOG_WARNING:
priority = ANDROID_LOG_WARN;
break;
case OTBR_LOG_NOTICE:
case OTBR_LOG_INFO:
priority = ANDROID_LOG_INFO;
break;
case OTBR_LOG_DEBUG:
default:
priority = ANDROID_LOG_DEBUG;
break;
}

return priority;
}
#endif

/** log to the syslog or standard out */
void otbrLog(otbrLogLevel aLevel, const char *aLogTag, const char *aFormat, ...)
{
Expand All @@ -147,7 +188,12 @@ void otbrLog(otbrLogLevel aLevel, const char *aLogTag, const char *aFormat, ...)
}
else
{
#if OTBR_ENABLE_PLATFORM_ANDROID
__android_log_print(ConvertToAndroidLogPriority(aLevel), LOG_TAG, "%s%s: %s", sLevelString[aLevel],
GetPrefix(aLogTag), buffer);
#else
syslog(static_cast<int>(aLevel), "%s%s: %s", sLevelString[aLevel], GetPrefix(aLogTag), buffer);
#endif
}
}

Expand Down Expand Up @@ -177,7 +223,11 @@ void otbrLogvNoFilter(otbrLogLevel aLevel, const char *aFormat, va_list aArgList
}
else
{
#if OTBR_ENABLE_PLATFORM_ANDROID
__android_log_vprint(ConvertToAndroidLogPriority(aLevel), LOG_TAG, aFormat, aArgList);
#else
vsyslog(static_cast<int>(aLevel), aFormat, aArgList);
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dbus/server/dbus_thread_object_ncp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void DBusThreadObjectNcp::JoinHandler(DBusRequest &aRequest)

void DBusThreadObjectNcp::LeaveHandler(DBusRequest &aRequest)
{
mHost.Leave([aRequest](otError aError, const std::string &aErrorInfo) mutable {
mHost.Leave(true /* aEraseDataset */, [aRequest](otError aError, const std::string &aErrorInfo) mutable {
OT_UNUSED_VARIABLE(aErrorInfo);
aRequest.ReplyOtResult(aError);
});
Expand Down
42 changes: 39 additions & 3 deletions src/ncp/ncp_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <openthread/openthread-system.h>

#include "lib/spinel/spinel_driver.hpp"

#include "ncp/async_task.hpp"

namespace otbr {
Expand Down Expand Up @@ -134,6 +133,16 @@ void NcpHost::Init(void)
{
mInfraIf.SetInfraIf(mConfig.mBackboneInterfaceName);
}

#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
#if OTBR_ENABLE_SRP_SERVER_AUTO_ENABLE_MODE
// Let SRP server use auto-enable mode. The auto-enable mode delegates the control of SRP server to the Border
// Routing Manager. SRP server automatically starts when bi-directional connectivity is ready.
mNcpSpinel.SrpServerSetAutoEnableMode(/* aEnabled */ true);
#else
mNcpSpinel.SrpServerSetEnabled(/* aEnabled */ true);
#endif
#endif
}

void NcpHost::Deinit(void)
Expand All @@ -157,14 +166,23 @@ void NcpHost::Join(const otOperationalDatasetTlvs &aActiveOpDatasetTlvs, const A
task->Run();
}

void NcpHost::Leave(const AsyncResultReceiver &aReceiver)
void NcpHost::Leave(bool aEraseDataset, const AsyncResultReceiver &aReceiver)
{
AsyncTaskPtr task;
auto errorHandler = [aReceiver](otError aError, const std::string &aErrorInfo) { aReceiver(aError, aErrorInfo); };

task = std::make_shared<AsyncTask>(errorHandler);
task->First([this](AsyncTaskPtr aNext) { mNcpSpinel.ThreadDetachGracefully(std::move(aNext)); })
->Then([this](AsyncTaskPtr aNext) { mNcpSpinel.ThreadErasePersistentInfo(std::move(aNext)); });
->Then([this, aEraseDataset](AsyncTaskPtr aNext) {
if (aEraseDataset)
{
mNcpSpinel.ThreadErasePersistentInfo(std::move(aNext));
}
else
{
aNext->SetResult(OT_ERROR_NONE, "");
}
});
task->Run();
}

Expand Down Expand Up @@ -229,6 +247,12 @@ void NcpHost::AddThreadStateChangedCallback(ThreadStateChangedCallback aCallback
OT_UNUSED_VARIABLE(aCallback);
}

void NcpHost::AddThreadEnabledStateChangedCallback(ThreadEnabledStateCallback aCallback)
{
// TODO: Implement AddThreadEnabledStateChangedCallback under NCP mode.
OT_UNUSED_VARIABLE(aCallback);
}

void NcpHost::Process(const MainloopContext &aMainloop)
{
mSpinelDriver.Process(&aMainloop);
Expand All @@ -249,5 +273,17 @@ void NcpHost::Update(MainloopContext &aMainloop)
mNetif.UpdateFdSet(&aMainloop);
}

#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
void NcpHost::SetMdnsPublisher(Mdns::Publisher *aPublisher)
{
mNcpSpinel.SetMdnsPublisher(aPublisher);
}

void NcpHost::HandleMdnsState(Mdns::Publisher::State aState)
{
mNcpSpinel.DnssdSetState(aState);
}
#endif

} // namespace Ncp
} // namespace otbr
Loading

0 comments on commit 649fbd7

Please sign in to comment.