mirror of
https://github.com/espressif/openthread.git
synced 2026-09-10 03:00:09 +00:00
[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:
@@ -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"},
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user