[ncp] add property to instruct NCP to leave gracefully (#10337)

This commit adds a new property SPINEL_PROP_NET_LEAVE_GRACEFULLY. The
host can trigger otThreadDetachGracefully by setting this spinel
property. Hence a SetProperty handler is implemented for this
property. A GetProperty handler is also added for this property for a
property response.
This commit is contained in:
Li Cao
2024-06-07 14:03:45 -07:00
committed by GitHub
parent 9cc1cd9e58
commit 22ee728ac7
6 changed files with 34 additions and 0 deletions
+1
View File
@@ -1287,6 +1287,7 @@ const char *spinel_prop_key_to_cstr(spinel_prop_key_t prop_key)
{SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING, "NET_REQUIRE_JOIN_EXISTING"},
{SPINEL_PROP_NET_KEY_SWITCH_GUARDTIME, "NET_KEY_SWITCH_GUARDTIME"},
{SPINEL_PROP_NET_PSKC, "NET_PSKC"},
{SPINEL_PROP_NET_LEAVE_GRACEFULLY, "NET_LEAVE_GRACEFULLY"},
{SPINEL_PROP_THREAD_LEADER_ADDR, "THREAD_LEADER_ADDR"},
{SPINEL_PROP_THREAD_PARENT, "THREAD_PARENT"},
{SPINEL_PROP_THREAD_CHILD_TABLE, "THREAD_CHILD_TABLE"},
+6
View File
@@ -2370,6 +2370,12 @@ enum
*/
SPINEL_PROP_NET_PSKC = SPINEL_PROP_NET__BEGIN + 11,
/// Instruct NCP to leave the current network gracefully
/** Format Empty - Write only
*
*/
SPINEL_PROP_NET_LEAVE_GRACEFULLY = SPINEL_PROP_NET__BEGIN + 12,
SPINEL_PROP_NET__END = 0x50,
SPINEL_PROP_NET_EXT__BEGIN = 0x1400,
+1
View File
@@ -77,6 +77,7 @@ const ChangedPropsSet::Entry ChangedPropsSet::mSupportedProps[] = {
{SPINEL_PROP_NET_XPANID, SPINEL_STATUS_OK, true},
{SPINEL_PROP_NET_NETWORK_KEY, SPINEL_STATUS_OK, true},
{SPINEL_PROP_NET_PSKC, SPINEL_STATUS_OK, true},
{SPINEL_PROP_NET_LEAVE_GRACEFULLY, SPINEL_STATUS_OK, false},
{SPINEL_PROP_PHY_CHAN_SUPPORTED, SPINEL_STATUS_OK, true},
#if OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE
{SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL, SPINEL_STATUS_OK, true},
+4
View File
@@ -615,6 +615,10 @@ protected:
#endif // OPENTHREAD_ENABLE_NCP_VENDOR_HOOK
static void ThreadDetachGracefullyHandler(void *aContext);
void ThreadDetachGracefullyHandler(void);
protected:
static NcpBase *sNcpInstance;
static spinel_status_t ThreadErrorToSpinelStatus(otError aError);
+4
View File
@@ -100,6 +100,7 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey)
#if OPENTHREAD_FTD
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_NET_PSKC),
#endif
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_NET_LEAVE_GRACEFULLY),
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_LEADER_ADDR),
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_PARENT),
#if OPENTHREAD_FTD
@@ -452,6 +453,9 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey)
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_NET_KEY_SWITCH_GUARDTIME),
#if OPENTHREAD_FTD
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_NET_PSKC),
#endif
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_NET_LEAVE_GRACEFULLY),
#if OPENTHREAD_FTD
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_LOCAL_LEADER_WEIGHT),
#endif
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_ASSISTING_PORTS),
+18
View File
@@ -4552,6 +4552,24 @@ exit:
return error;
}
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_NET_LEAVE_GRACEFULLY>(void) { return OT_ERROR_NONE; }
template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_LEAVE_GRACEFULLY>(void)
{
return otThreadDetachGracefully(mInstance, ThreadDetachGracefullyHandler, this);
}
void NcpBase::ThreadDetachGracefullyHandler(void *aContext)
{
static_cast<NcpBase *>(aContext)->ThreadDetachGracefullyHandler();
}
void NcpBase::ThreadDetachGracefullyHandler(void)
{
mChangedPropsSet.AddProperty(SPINEL_PROP_NET_LEAVE_GRACEFULLY);
mUpdateChangedPropsTask.Post();
}
// ----------------------------------------------------------------------------
// MARK: Property/Status Changed
// ----------------------------------------------------------------------------