From 74cdd2608559606b1a3fd857d137c465e850e4fa Mon Sep 17 00:00:00 2001 From: Li Cao Date: Thu, 31 Oct 2024 04:10:30 +0800 Subject: [PATCH] [ncp] add empty implementation for dnssd platform APIs (#10877) This commit adds empty implementation for a NCP based version of otPlatDnssd APIs. Like NCP version of otPlatInfraIf APIs, this commit adds a control option to enable/disable the simulation platform version of otPlatDnssd APIs to avoid conflict. By default, the simulation version of implementation will still be turned on. --- etc/cmake/options.cmake | 1 + examples/platforms/simulation/CMakeLists.txt | 7 + examples/platforms/simulation/dnssd.c | 4 +- .../platforms/simulation/platform-config.h | 9 + src/ncp/CMakeLists.txt | 8 + src/ncp/ncp_config.h | 9 + src/ncp/platform/dnssd.cpp | 168 ++++++++++++++++++ 7 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 src/ncp/platform/dnssd.cpp diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index 2a2d4c598..06d8e31dc 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -235,6 +235,7 @@ ot_option(OT_OPERATIONAL_DATASET_AUTO_INIT OPENTHREAD_CONFIG_OPERATIONAL_DATASET ot_option(OT_OTNS OPENTHREAD_CONFIG_OTNS_ENABLE "OTNS") ot_option(OT_PING_SENDER OPENTHREAD_CONFIG_PING_SENDER_ENABLE "ping sender" ${OT_APP_CLI}) ot_option(OT_PLATFORM_BOOTLOADER_MODE OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE "platform bootloader mode") +ot_option(OT_PLATFORM_DNSSD OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE "platform dnssd") ot_option(OT_PLATFORM_KEY_REF OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE "platform key reference secure storage") ot_option(OT_PLATFORM_LOG_CRASH_DUMP OPENTHREAD_CONFIG_PLATFORM_LOG_CRASH_DUMP_ENABLE "platform log crash dump") ot_option(OT_PLATFORM_NETIF OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE "platform netif") diff --git a/examples/platforms/simulation/CMakeLists.txt b/examples/platforms/simulation/CMakeLists.txt index 3030de47a..6506c413a 100644 --- a/examples/platforms/simulation/CMakeLists.txt +++ b/examples/platforms/simulation/CMakeLists.txt @@ -52,6 +52,13 @@ else() target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_IMPLEMENT_INFRA_IF=0") endif() +option(OT_SIMULATION_DNSSD "enable simulation dnssd" ON) +if (OT_SIMULATION_DNSSD) + target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD=1") +else() + target_compile_definitions(ot-simulation-config INTERFACE "OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD=0") +endif() + if(NOT OT_PLATFORM_CONFIG) set(OT_PLATFORM_CONFIG "openthread-core-simulation-config.h" PARENT_SCOPE) endif() diff --git a/examples/platforms/simulation/dnssd.c b/examples/platforms/simulation/dnssd.c index 84fd8a6cf..ab5ae998e 100644 --- a/examples/platforms/simulation/dnssd.c +++ b/examples/platforms/simulation/dnssd.c @@ -30,7 +30,7 @@ #include -#if OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE +#if OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE && OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD otPlatDnssdState otPlatDnssdGetState(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); @@ -164,4 +164,4 @@ void otPlatDnssdStopIp4AddressResolver(otInstance *aInstance, const otPlatDnssdA OT_UNUSED_VARIABLE(aResolver); } -#endif // OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE +#endif // OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE && OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD diff --git a/examples/platforms/simulation/platform-config.h b/examples/platforms/simulation/platform-config.h index 645e7fb31..4ee27d9f2 100644 --- a/examples/platforms/simulation/platform-config.h +++ b/examples/platforms/simulation/platform-config.h @@ -116,3 +116,12 @@ #ifndef OPENTHREAD_SIMULATION_IMPLEMENT_INFRA_IF #define OPENTHREAD_SIMULATION_IMPLEMENT_INFRA_IF 1 #endif + +/** + * @def OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD + * + * Define as 1 for the simulation platform to provide implementation of `otPlatDnssd` APIs. + */ +#ifndef OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD +#define OPENTHREAD_SIMULATION_IMPLEMENT_DNSSD 1 +#endif diff --git a/src/ncp/CMakeLists.txt b/src/ncp/CMakeLists.txt index 7bcab9dd4..2f0a1f8e8 100644 --- a/src/ncp/CMakeLists.txt +++ b/src/ncp/CMakeLists.txt @@ -39,6 +39,7 @@ set(COMMON_SOURCES ncp_base_radio.cpp ncp_spi.cpp ncp_hdlc.cpp + platform/dnssd.cpp platform/infra_if.cpp ) @@ -55,6 +56,13 @@ else() target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE=0") endif() +option(OT_NCP_DNSSD "enable NCP DNSSD") +if (OT_NCP_DNSSD) + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_NCP_DNSSD_ENABLE=1") +else() + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_NCP_DNSSD_ENABLE=0") +endif() + set(COMMON_NCP_SOURCES ${COMMON_SOURCES} ncp_base_ftd.cpp diff --git a/src/ncp/ncp_config.h b/src/ncp/ncp_config.h index 66017604e..191858627 100644 --- a/src/ncp/ncp_config.h +++ b/src/ncp/ncp_config.h @@ -176,6 +176,15 @@ #define OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE 0 #endif +/** + * @def OPENTHREAD_CONFIG_NCP_DNSSD_ENABLE + * + * Define to 1 to enable NCP based implementation of platform DNS-SD APIs. + */ +#ifndef OPENTHREAD_CONFIG_NCP_DNSSD_ENABLE +#define OPENTHREAD_CONFIG_NCP_DNSSD_ENABLE 0 +#endif + /** * @def OPENTHREAD_ENABLE_NCP_VENDOR_HOOK * diff --git a/src/ncp/platform/dnssd.cpp b/src/ncp/platform/dnssd.cpp new file mode 100644 index 000000000..193e63375 --- /dev/null +++ b/src/ncp/platform/dnssd.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2024, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "ncp/ncp_base.hpp" + +#if OPENTHREAD_CONFIG_NCP_DNSSD_ENABLE && OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE +otPlatDnssdState otPlatDnssdGetState(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + + return OT_PLAT_DNSSD_STOPPED; +} + +void otPlatDnssdRegisterService(otInstance *aInstance, + const otPlatDnssdService *aService, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aService); + OT_UNUSED_VARIABLE(aRequestId); + OT_UNUSED_VARIABLE(aCallback); +} + +void otPlatDnssdUnregisterService(otInstance *aInstance, + const otPlatDnssdService *aService, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aService); + OT_UNUSED_VARIABLE(aRequestId); + OT_UNUSED_VARIABLE(aCallback); +} + +void otPlatDnssdRegisterHost(otInstance *aInstance, + const otPlatDnssdHost *aHost, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aHost); + OT_UNUSED_VARIABLE(aRequestId); + OT_UNUSED_VARIABLE(aCallback); +} + +void otPlatDnssdUnregisterHost(otInstance *aInstance, + const otPlatDnssdHost *aHost, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aHost); + OT_UNUSED_VARIABLE(aRequestId); + OT_UNUSED_VARIABLE(aCallback); +} + +void otPlatDnssdRegisterKey(otInstance *aInstance, + const otPlatDnssdKey *aKey, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aKey); + OT_UNUSED_VARIABLE(aRequestId); + OT_UNUSED_VARIABLE(aCallback); +} + +void otPlatDnssdUnregisterKey(otInstance *aInstance, + const otPlatDnssdKey *aKey, + otPlatDnssdRequestId aRequestId, + otPlatDnssdRegisterCallback aCallback) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aKey); + OT_UNUSED_VARIABLE(aRequestId); + OT_UNUSED_VARIABLE(aCallback); +} + +void otPlatDnssdStartBrowser(otInstance *aInstance, const otPlatDnssdBrowser *aBrowser) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aBrowser); +} + +void otPlatDnssdStopBrowser(otInstance *aInstance, const otPlatDnssdBrowser *aBrowser) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aBrowser); +} + +void otPlatDnssdStartSrvResolver(otInstance *aInstance, const otPlatDnssdSrvResolver *aResolver) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aResolver); +} + +void otPlatDnssdStopSrvResolver(otInstance *aInstance, const otPlatDnssdSrvResolver *aResolver) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aResolver); +} + +void otPlatDnssdStartTxtResolver(otInstance *aInstance, const otPlatDnssdTxtResolver *aResolver) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aResolver); +} + +void otPlatDnssdStopTxtResolver(otInstance *aInstance, const otPlatDnssdTxtResolver *aResolver) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aResolver); +} + +void otPlatDnssdStartIp6AddressResolver(otInstance *aInstance, const otPlatDnssdAddressResolver *aResolver) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aResolver); +} + +void otPlatDnssdStopIp6AddressResolver(otInstance *aInstance, const otPlatDnssdAddressResolver *aResolver) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aResolver); +} + +void otPlatDnssdStartIp4AddressResolver(otInstance *aInstance, const otPlatDnssdAddressResolver *aResolver) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aResolver); +} + +void otPlatDnssdStopIp4AddressResolver(otInstance *aInstance, const otPlatDnssdAddressResolver *aResolver) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aResolver); +} + +#endif // OPENTHREAD_CONFIG_NCP_DNSSD_ENABLE && OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE