From 89396ab5d361b7ccf5b24dac7d6170c36b8d50de Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 11 Mar 2019 14:59:43 -0700 Subject: [PATCH] [ncp] add SLAAC related spinel capability and property (#3667) This commit adds `SPINEL_CAP_SLAAC` which indicates to host whether SLAAC feature is supported. It also adds `SPINEL_PROP_SLAAC_ENABLED` spinel property to let host enable/disable SLAAC module at run-time. --- src/ncp/ncp_base.cpp | 4 ++++ src/ncp/ncp_base_dispatcher.cpp | 10 ++++++++++ src/ncp/ncp_base_mtd.cpp | 21 +++++++++++++++++++++ src/ncp/spinel.c | 8 ++++++++ src/ncp/spinel.h | 12 ++++++++++++ 5 files changed, 55 insertions(+) diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index d44e2525e..4675e5974 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -1787,6 +1787,10 @@ template <> otError NcpBase::HandlePropertyGet(void) SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_OOB_STEERING_DATA)); #endif +#if OPENTHREAD_CONFIG_ENABLE_SLAAC + SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_SLAAC)); +#endif + #if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_PEEK_POKE)); #endif diff --git a/src/ncp/ncp_base_dispatcher.cpp b/src/ncp/ncp_base_dispatcher.cpp index a9c0f7e23..41d1f5187 100644 --- a/src/ncp/ncp_base_dispatcher.cpp +++ b/src/ncp/ncp_base_dispatcher.cpp @@ -511,6 +511,11 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey) handler = &NcpBase::HandlePropertyGet; break; #endif +#if OPENTHREAD_CONFIG_ENABLE_SLAAC + case SPINEL_PROP_SLAAC_ENABLED: + handler = &NcpBase::HandlePropertyGet; + break; +#endif #endif // OPENTHREAD_MTD || OPENTHREAD_FTD // -------------------------------------------------------------------------- @@ -842,6 +847,11 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey) handler = &NcpBase::HandlePropertySet; break; #endif +#if OPENTHREAD_CONFIG_ENABLE_SLAAC + case SPINEL_PROP_SLAAC_ENABLED: + handler = &NcpBase::HandlePropertySet; + break; +#endif #endif // OPENTHREAD_MTD || OPENTHREAD_FTD // -------------------------------------------------------------------------- diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index 9d5b3515c..cc2549a1b 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -2833,6 +2833,27 @@ template <> otError NcpBase::HandlePropertyGet(void) #endif // OPENTHREAD_ENABLE_POSIX_APP +#if OPENTHREAD_CONFIG_ENABLE_SLAAC + +template <> otError NcpBase::HandlePropertyGet(void) +{ + return mEncoder.WriteBool(otIp6IsSlaacEnabled(mInstance)); +} + +template <> otError NcpBase::HandlePropertySet(void) +{ + otError error = OT_ERROR_NONE; + bool enabled; + + SuccessOrExit(error = mDecoder.ReadBool(enabled)); + otIp6SetSlaacEnabled(mInstance, enabled); + +exit: + return error; +} + +#endif // OPENTHREAD_CONFIG_ENABLE_SLAAC + #if OPENTHREAD_ENABLE_LEGACY void NcpBase::RegisterLegacyHandlers(const otNcpLegacyHandlers *aHandlers) diff --git a/src/ncp/spinel.c b/src/ncp/spinel.c index 080c8304c..8ac57dec1 100644 --- a/src/ncp/spinel.c +++ b/src/ncp/spinel.c @@ -1851,6 +1851,10 @@ const char *spinel_prop_key_to_cstr(spinel_prop_key_t prop_key) ret = "PARENT_RESPONSE_INFO"; break; + case SPINEL_PROP_SLAAC_ENABLED: + ret = "SLAAC_ENABLED"; + break; + case SPINEL_PROP_UART_BITRATE: ret = "UART_BITRATE"; break; @@ -2480,6 +2484,10 @@ const char *spinel_capability_to_cstr(unsigned int capability) ret = "POSIX_APP"; break; + case SPINEL_CAP_SLAAC: + ret = "SLAAC"; + break; + case SPINEL_CAP_ERROR_RATE_TRACKING: ret = "ERROR_RATE_TRACKING"; break; diff --git a/src/ncp/spinel.h b/src/ncp/spinel.h index 3c0404405..039de49c4 100644 --- a/src/ncp/spinel.h +++ b/src/ncp/spinel.h @@ -778,6 +778,7 @@ enum SPINEL_CAP_TIME_SYNC = (SPINEL_CAP_OPENTHREAD__BEGIN + 7), SPINEL_CAP_CHILD_SUPERVISION = (SPINEL_CAP_OPENTHREAD__BEGIN + 8), SPINEL_CAP_POSIX_APP = (SPINEL_CAP_OPENTHREAD__BEGIN + 9), + SPINEL_CAP_SLAAC = (SPINEL_CAP_OPENTHREAD__BEGIN + 10), SPINEL_CAP_OPENTHREAD__END = 640, SPINEL_CAP_THREAD__BEGIN = 1024, @@ -3025,6 +3026,17 @@ typedef enum */ SPINEL_PROP_PARENT_RESPONSE_INFO = SPINEL_PROP_OPENTHREAD__BEGIN + 13, + /// SLAAC enabled + /** Format `b` - Read-Write + * Required capability: `SPINEL_CAP_SLAAC` + * + * This property allows the host to enable/disable SLAAC module on NCP at run-time. When SLAAC module is enabled, + * SLAAC addresses (based on on-mesh prefixes in Network Data) are added to the interface. When SLAAC module is + * disabled any previously added SLAAC address is removed. + * + */ + SPINEL_PROP_SLAAC_ENABLED = SPINEL_PROP_OPENTHREAD__BEGIN + 14, + SPINEL_PROP_OPENTHREAD__END = 0x2000, SPINEL_PROP_INTERFACE__BEGIN = 0x100,