diff --git a/src/lib/spinel/spinel.h b/src/lib/spinel/spinel.h index 310903c2d6e..f38958c7d2b 100644 --- a/src/lib/spinel/spinel.h +++ b/src/lib/spinel/spinel.h @@ -4753,6 +4753,16 @@ enum */ SPINEL_PROP_INFRA_IF_STATE = SPINEL_PROP_INFRA_IF__BEGIN + 1, + /// Received ICMPv6 packet on the infrastructure interface. + /** Format: `L6d` + * Type: Write-only + * + * `L`: The infrastructure interface index. + * `6`: The IP6 source address of the ICMPv6 packet. + * `d`: The data of the ICMPv6 packet. The host MUST ensure the hoplimit is 255. + */ + SPINEL_PROP_INFRA_IF_RECV_ICMP6 = SPINEL_PROP_INFRA_IF__BEGIN + 2, + SPINEL_PROP_INFRA_IF__END = 0x920, SPINEL_PROP_NEST__BEGIN = 0x3BC0, diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index 73ce071498e..53ce9736fe5 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -739,7 +739,7 @@ class NcpBase uint64_t mLogTimestampBase; // Timestamp base used for logging -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE +#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE otError InfraIfAddAddress(const otIp6Address &aAddress); bool InfraIfContainsAddress(const otIp6Address &aAddress); diff --git a/src/ncp/ncp_base_dispatcher.cpp b/src/ncp/ncp_base_dispatcher.cpp index 9fae8d1f7df..f6567e17a5e 100644 --- a/src/ncp/ncp_base_dispatcher.cpp +++ b/src/ncp/ncp_base_dispatcher.cpp @@ -515,8 +515,9 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey) #if OPENTHREAD_RADIO && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_MULTIPAN_ACTIVE_INTERFACE), #endif -#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE +#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_INFRA_IF_STATE), + OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_INFRA_IF_RECV_ICMP6), #endif #if OPENTHREAD_MTD || OPENTHREAD_FTD OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_UNSOL_UPDATE_FILTER), diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index b7fb9edce2f..6fa7a13c8ac 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -1403,7 +1403,7 @@ template <> otError NcpBase::HandlePropertySet otError NcpBase::HandlePropertySet(void) { otError error = OT_ERROR_NONE; @@ -1438,6 +1438,26 @@ template <> otError NcpBase::HandlePropertySet(void) return error; } +template <> otError NcpBase::HandlePropertySet(void) +{ + otError error = OT_ERROR_NONE; + uint32_t infraIfIndex; + const otIp6Address *address; + const uint8_t *icmp6Data = nullptr; + uint16_t len; + + SuccessOrExit(error = mDecoder.ReadUint32(infraIfIndex)); + VerifyOrExit(mInfraIfIndex == infraIfIndex, error = OT_ERROR_DROP); + SuccessOrExit(error = mDecoder.ReadIp6Address(address)); + SuccessOrExit(error = mDecoder.ReadData(icmp6Data, len)); + + // Currently the ICMP6 messages can only be ND messages. + otPlatInfraIfRecvIcmp6Nd(mInstance, infraIfIndex, address, icmp6Data, len); + +exit: + return error; +} + otError NcpBase::InfraIfAddAddress(const otIp6Address &aAddress) { otError error = OT_ERROR_NONE; @@ -1468,7 +1488,7 @@ bool NcpBase::InfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAdd return aInfraIfIndex == mInfraIfIndex && InfraIfContainsAddress(*aAddress); } -#endif // OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE +#endif // OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE } // namespace Ncp } // namespace ot diff --git a/src/ncp/platform/infra_if.cpp b/src/ncp/platform/infra_if.cpp index bc9048646e2..b6e70e78674 100644 --- a/src/ncp/platform/infra_if.cpp +++ b/src/ncp/platform/infra_if.cpp @@ -30,7 +30,7 @@ #include "ncp/ncp_base.hpp" -#if OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE +#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddress) { return ot::Ncp::NcpBase::GetNcpInstance()->InfraIfHasAddress(aInfraIfIndex, aAddress); @@ -56,4 +56,4 @@ otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex) return OT_ERROR_NOT_IMPLEMENTED; } -#endif // OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE +#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE