Skip to content

Commit

Permalink
[ncp] add border routing InfraIf recv ICMP6 ND (openthread#10755)
Browse files Browse the repository at this point in the history
In this commit, a new spinel property
`SPINEL_PROP_INFRA_IF_RECV_ICMP6_ND` is added for the host to pass the
ICMP6 ND messages to the NCP.
  • Loading branch information
Irving-cl authored Sep 30, 2024
1 parent 7cd179e commit a6d6073
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/lib/spinel/spinel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ncp/ncp_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/ncp/ncp_base_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
24 changes: 22 additions & 2 deletions src/ncp/ncp_base_ftd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_TIME_SYNC_XTAL_THRESH
}
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE

#if OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE
#if OPENTHREAD_CONFIG_NCP_INFRA_IF_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_INFRA_IF_STATE>(void)
{
otError error = OT_ERROR_NONE;
Expand Down Expand Up @@ -1438,6 +1438,26 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_INFRA_IF_STATE>(void)
return error;
}

template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_INFRA_IF_RECV_ICMP6>(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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ncp/platform/infra_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

0 comments on commit a6d6073

Please sign in to comment.