Skip to content

Commit

Permalink
release from GSDK 4.4.0
Browse files Browse the repository at this point in the history
openthread version: 2.4.0.0_GitHub-7074a43e4
  • Loading branch information
lancersky committed Dec 21, 2023
1 parent 2ed96e7 commit 575c91e
Show file tree
Hide file tree
Showing 516 changed files with 22,602 additions and 11,623 deletions.
5 changes: 5 additions & 0 deletions etc/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@ if (OTBR_DHCP6_PD)
else()
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_DHCP6_PD=0)
endif()

option(OTBR_VENDOR_SERVER "Enable vendor server" OFF)
if (OTBR_VENDOR_SERVER)
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_VENDOR_SERVER=1)
endif()
4 changes: 4 additions & 0 deletions etc/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ARG RELEASE
ARG REST_API
ARG WEB_GUI
ARG MDNS
ARG FIREWALL

ENV INFRA_IF_NAME=${INFRA_IF_NAME:-eth0}
ENV BORDER_ROUTING=${BORDER_ROUTING:-1}
Expand All @@ -59,6 +60,7 @@ ENV NAT64_DYNAMIC_POOL=${NAT64_DYNAMIC_POOL:-192.168.255.0/24}
ENV DNS64=${DNS64:-0}
ENV WEB_GUI=${WEB_GUI:-1}
ENV REST_API=${REST_API:-1}
ENV FIREWALL=${FIREWALL:-1}
ENV DOCKER 1

RUN env
Expand Down Expand Up @@ -94,6 +96,7 @@ RUN apt-get update \

# Copy OTBR scripts
COPY ./ot-br-posix/script /app/script
COPY ./ot-br-posix/third_party/mDNSResponder /app/third_party/mDNSResponder
WORKDIR /app

# Run OTBR bootstrap
Expand All @@ -119,6 +122,7 @@ RUN ([ "${DNS64}" = "0" ] || chmod 644 /etc/bind/named.conf.options) \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $OTBR_BUILD_DEPS \
&& ([ "${RELEASE}" = 1 ] || apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false "$OTBR_NORELEASE_DEPS";) \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/* \
))

ENTRYPOINT ["/app/etc/docker/docker_entrypoint.sh"]
Expand Down
4 changes: 3 additions & 1 deletion etc/openwrt/openthread-br/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ CMAKE_OPTIONS+= \
-DOTBR_SRP_ADVERTISING_PROXY=ON \
-DOT_FIREWALL=ON \
-DOT_POSIX_SETTINGS_PATH=\"/etc/openthread\" \
-DOT_READLINE=OFF
-DOT_READLINE=OFF \
-DOTBR_NAT64=ON \
-DNAT64_SERVICE=\"openthread\"

TARGET_CFLAGS += -DOPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME=\\\"/var/run/openthread-%s\\\"

Expand Down
10 changes: 10 additions & 0 deletions script/_firewall
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ FIREWALL_SERVICE=/etc/init.d/otbr-firewall

sudo modprobe ip6table_filter || true

FIREWALL="${FIREWALL:-1}"

firewall_uninstall()
{
with FIREWALL || return 0

firewall_stop
if have systemctl; then
sudo systemctl disable otbr-firewall || true
Expand All @@ -46,6 +50,8 @@ firewall_uninstall()

firewall_install()
{
with FIREWALL || return 0

sudo cp script/otbr-firewall $FIREWALL_SERVICE
sudo chmod a+x $FIREWALL_SERVICE
if have systemctl; then
Expand All @@ -56,6 +62,8 @@ firewall_install()

firewall_start()
{
with FIREWALL || return 0

if with DOCKER; then
service otbr-firewall start || die 'Failed to start firewall service'
elif have systemctl; then
Expand All @@ -65,6 +73,8 @@ firewall_start()

firewall_stop()
{
with FIREWALL || return 0

if with DOCKER; then
service otbr-firewall stop || true
elif have systemctl; then
Expand Down
10 changes: 10 additions & 0 deletions script/_otbr
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ otbr_install()
)
fi

if with FIREWALL; then
otbr_options+=(
"-DOT_FIREWALL=ON"
)
else
otbr_options+=(
"-DOT_FIREWALL=OFF"
)
fi

(./script/cmake-build "${otbr_options[@]}" \
&& cd "${OTBR_TOP_BUILDDIR}" \
&& ninja \
Expand Down
18 changes: 12 additions & 6 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

NAT64_SERVICE="${NAT64_SERVICE:-openthread}"

FIREWALL="${FIREWALL:-1}"

install_packages_apt()
{
sudo apt-get update
Expand All @@ -56,16 +58,20 @@ install_packages_apt()

# mDNS
sudo apt-get install --no-install-recommends -y libavahi-client3 libavahi-common-dev libavahi-client-dev avahi-daemon
(MDNS_RESPONDER_SOURCE_NAME=mDNSResponder-1310.80.1 \
(MDNS_RESPONDER_SOURCE_NAME=mDNSResponder-1790.80.10 \
&& MDNS_RESPONDER_PATCH_PATH=$(realpath "$(dirname "$0")"/../third_party/mDNSResponder) \
&& cd /tmp \
&& wget --no-check-certificate https://github.com/apple-oss-distributions/mDNSResponder/archive/refs/tags/$MDNS_RESPONDER_SOURCE_NAME.tar.gz \
&& mkdir -p $MDNS_RESPONDER_SOURCE_NAME \
&& tar xvf $MDNS_RESPONDER_SOURCE_NAME.tar.gz -C $MDNS_RESPONDER_SOURCE_NAME --strip-components=1 \
&& cd /tmp/$MDNS_RESPONDER_SOURCE_NAME/Clients \
&& sed -i '/#include <ctype.h>/a #include <stdarg.h>' dns-sd.c \
&& sed -i '/#include <ctype.h>/a #include <sys/param.h>' dns-sd.c \
&& cd /tmp/$MDNS_RESPONDER_SOURCE_NAME/mDNSPosix \
&& make os=linux && sudo make install os=linux)
&& cd /tmp/"$MDNS_RESPONDER_SOURCE_NAME" \
&& (
for patch in "$MDNS_RESPONDER_PATCH_PATH"/*.patch; do
patch -p1 <"$patch"
done
) \
&& cd mDNSPosix \
&& make os=linux tls=no && sudo make install os=linux tls=no)

# Boost
sudo apt-get install --no-install-recommends -y libboost-dev libboost-filesystem-dev libboost-system-dev
Expand Down
4 changes: 2 additions & 2 deletions src/agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ set(OTBR_AGENT_USER "root" CACHE STRING "set the username running otbr-agent ser
set(OTBR_AGENT_GROUP "root" CACHE STRING "set the group using otbr-agent client")

if(OTBR_MDNS STREQUAL "mDNSResponder")
set(EXEC_START_PRE "ExecStartPre=service mdns start\n")
set(EXEC_START_PRE "ExecStartPre=/usr/sbin/service mdns start\n")
elseif(OTBR_MDNS STREQUAL "avahi")
set(EXEC_START_PRE "ExecStartPre=service avahi-daemon start\n")
set(EXEC_START_PRE "ExecStartPre=/usr/sbin/service avahi-daemon start\n")
else()
message(WARNING "OTBR_MDNS=\"${OTBR_MDNS}\" is not supported")
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/agent/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Application::Application(const std::string &aInterfaceName,
, mDBusAgent(mNcp, mBorderAgent.GetPublisher())
#endif
#if OTBR_ENABLE_VENDOR_SERVER
, mVendorServer(mNcp)
, mVendorServer(vendor::VendorServer::newInstance(*this))
#endif
{
OTBR_UNUSED_VARIABLE(aRestListenAddress);
Expand All @@ -104,7 +104,7 @@ void Application::Init(void)
mDBusAgent.Init();
#endif
#if OTBR_ENABLE_VENDOR_SERVER
mVendorServer.Init();
mVendorServer->Init();
#endif
}

Expand Down
77 changes: 76 additions & 1 deletion src/agent/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@

namespace otbr {

#if OTBR_ENABLE_VENDOR_SERVER
namespace vendor {

class VendorServer;

}
#endif

/**
* @addtogroup border-router-agent
*
Expand Down Expand Up @@ -119,6 +127,73 @@ class Application : private NonCopyable
*/
otbrError Run(void);

/**
* Get the OpenThread controller object the application is using.
*
* @returns The OpenThread controller object.
*/
Ncp::ControllerOpenThread &GetNcp(void) { return mNcp; }

#if OTBR_ENABLE_BORDER_AGENT
/**
* Get the border agent the application is using.
*
* @returns The border agent.
*/
BorderAgent &GetBorderAgent(void)
{
return mBorderAgent;
}
#endif

#if OTBR_ENABLE_BACKBONE_ROUTER
/**
* Get the backbone agent the application is using.
*
* @returns The backbone agent.
*/
BackboneRouter::BackboneAgent &GetBackboneAgent(void)
{
return mBackboneAgent;
}
#endif

#if OTBR_ENABLE_OPENWRT
/**
* Get the UBus agent the application is using.
*
* @returns The UBus agent.
*/
ubus::UBusAgent &GetUBusAgent(void)
{
return mUbusAgent;
}
#endif

#if OTBR_ENABLE_REST_SERVER
/**
* Get the rest web server the application is using.
*
* @returns The rest web server.
*/
rest::RestWebServer &GetRestWebServer(void)
{
return mRestWebServer;
}
#endif

#if OTBR_ENABLE_DBUS_SERVER
/**
* Get the DBus agent the application is using.
*
* @returns The DBus agent.
*/
DBus::DBusAgent &GetDBusAgent(void)
{
return mDBusAgent;
}
#endif

private:
// Default poll timeout.
static const struct timeval kPollTimeout;
Expand Down Expand Up @@ -147,7 +222,7 @@ class Application : private NonCopyable
DBus::DBusAgent mDBusAgent;
#endif
#if OTBR_ENABLE_VENDOR_SERVER
vendor::VendorServer mVendorServer;
std::shared_ptr<vendor::VendorServer> mVendorServer;
#endif

static std::atomic_bool sShouldTerminate;
Expand Down
3 changes: 1 addition & 2 deletions src/agent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
#include "common/types.hpp"
#include "ncp/ncp_openthread.hpp"

static const char kSyslogIdent[] = "otbr-agent";
static const char kDefaultInterfaceName[] = "wpan0";

// Port number used by Rest server.
Expand Down Expand Up @@ -268,7 +267,7 @@ static int realmain(int argc, char *argv[])
}
}

otbrLogInit(kSyslogIdent, logLevel, verbose);
otbrLogInit(argv[0], logLevel, verbose);
otbrLogNotice("Running %s", OTBR_PACKAGE_VERSION);
otbrLogNotice("Thread version: %s", otbr::Ncp::ControllerOpenThread::GetThreadVersion());
otbrLogNotice("Thread interface: %s", interfaceName);
Expand Down
26 changes: 20 additions & 6 deletions src/agent/vendor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,42 @@

#include "openthread-br/config.h"

#include "ncp/ncp_openthread.hpp"
#include "agent/application.hpp"

namespace otbr {

class Application;

namespace vendor {

/**
* An interface for customized behavior depending on OpenThread API and state.
*/
class VendorServer
{
public:
virtual ~VendorServer(void) = default;

/**
* The constructor of vendor server.
* Creates a new instance of VendorServer.
*
* Custom vendor servers should implement this method to return an object of the derived class.
*
* @param[in] aNcp A reference to the NCP controller.
* @param[in] aApplication The OTBR application.
*
* @returns New derived VendorServer instance.
*/
VendorServer(otbr::Ncp::ControllerOpenThread &aNcp);
static std::shared_ptr<VendorServer> newInstance(Application &aApplication);

/**
* This method initializes the vendor server.
* Initializes the vendor server.
*
* This will be called by `Application::Init()` after OpenThread instance and other built-in
* servers have been created and initialized.
*/
void Init(void);
virtual void Init(void) = 0;
};

} // namespace vendor
} // namespace otbr
#endif // OTBR_AGENT_VENDOR_HPP_
16 changes: 12 additions & 4 deletions src/border_agent/border_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,11 @@ void AppendVendorTxtEntries(const std::map<std::string, std::vector<uint8_t>> &a

for (auto &addedEntry : aTxtList)
{
if (addedEntry.mName == key)
if (addedEntry.mKey == key)
{
addedEntry.mValue = value;
found = true;
addedEntry.mValue = value;
addedEntry.mIsBooleanAttribute = false;
found = true;
break;
}
}
Expand All @@ -367,7 +368,11 @@ void BorderAgent::PublishMeshCopService(void)
const otExtAddress *extAddr = otLinkGetExtendedAddress(instance);
const char *networkName = otThreadGetNetworkName(instance);
Mdns::Publisher::TxtList txtList{{"rv", "1"}};
Mdns::Publisher::TxtData txtData;
int port;
otbrError error;

OTBR_UNUSED_VARIABLE(error);

otbrLogInfo("Publish meshcop service %s.%s.local.", mServiceInstanceName.c_str(), kBorderAgentServiceType);

Expand Down Expand Up @@ -433,8 +438,11 @@ void BorderAgent::PublishMeshCopService(void)
port = kBorderAgentServiceDummyPort;
}

error = Mdns::Publisher::EncodeTxtData(txtList, txtData);
assert(error == OTBR_ERROR_NONE);

mPublisher->PublishService(/* aHostName */ "", mServiceInstanceName, kBorderAgentServiceType,
Mdns::Publisher::SubTypeList{}, port, txtList, [this](otbrError aError) {
Mdns::Publisher::SubTypeList{}, port, txtData, [this](otbrError aError) {
if (aError == OTBR_ERROR_ABORTED)
{
// OTBR_ERROR_ABORTED is thrown when an ongoing service registration is
Expand Down
3 changes: 3 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
add_library(otbr-common
api_strings.cpp
byteswap.hpp
code_utils.cpp
code_utils.hpp
dns_utils.cpp
logging.cpp
Expand All @@ -49,4 +50,6 @@ target_link_libraries(otbr-common
PUBLIC otbr-config
openthread-ftd
openthread-posix
$<$<BOOL:${OTBR_FEATURE_FLAGS}>:otbr-proto>
$<$<BOOL:${OTBR_TELEMETRY_DATA_API}>:otbr-proto>
)
Loading

0 comments on commit 575c91e

Please sign in to comment.