mirror of
https://github.com/espressif/openthread.git
synced 2026-08-08 03:37:46 +00:00
[ncp] add spinel properties for border agent (#11271)
This commit adds spinel properties for border agent MeshCoP service to work under NCP. * `SPINEL_PROP_BORDER_AGENT_MESHCOP_SERIVCE_STATE`: this simply conveys the MeshCoP service state, including `IsActive`, udp port and the encoded Txt values. * `SPINEL_PROP_BORDER_AGENT_MESHCOP_SERIVCE_STATE_SUBSCRIPTION`: this notifies the NCP side to register the state change callback. Because we hope that the host side can have initial values. But if we register the state change callback in NCP's initialization, the callback will be invoked at a very early stage and send the values while the host isn't ready to receive the MeshCoP service values. So this property enables the host to decide when to receive the initial values.
This commit is contained in:
@@ -1418,6 +1418,7 @@ const char *spinel_prop_key_to_cstr(spinel_prop_key_t prop_key)
|
||||
{SPINEL_PROP_DNSSD_HOST, "DNSSD_HOST"},
|
||||
{SPINEL_PROP_DNSSD_SERVICE, "DNSSD_SERVICE"},
|
||||
{SPINEL_PROP_DNSSD_KEY_RECORD, "DNSSD_KEY_RECORD"},
|
||||
{SPINEL_PROP_BORDER_AGENT_MESHCOP_SERVICE_STATE, "BORDER_AGENT_MESHCOP_SERVICE_STATE"},
|
||||
{SPINEL_PROP_PARENT_RESPONSE_INFO, "PARENT_RESPONSE_INFO"},
|
||||
{SPINEL_PROP_SLAAC_ENABLED, "SLAAC_ENABLED"},
|
||||
{SPINEL_PROP_SUPPORTED_RADIO_LINKS, "SUPPORTED_RADIO_LINKS"},
|
||||
|
||||
@@ -4884,6 +4884,20 @@ enum
|
||||
|
||||
SPINEL_PROP_DNSSD__END = 0x950,
|
||||
|
||||
SPINEL_PROP_BORDER_AGENT__BEGIN = 0x950,
|
||||
|
||||
/// Border Agent MeshCoP service state.
|
||||
/**
|
||||
* Format: `bSD`: Get and Unsolicited notifications.
|
||||
*
|
||||
* `b`: Whether the border agent is running or not.
|
||||
* `S`: The UDP port that is being used by the border agent. If the state is 'Stopped', the port MUST be 0.
|
||||
* `D`: The encoded MeshCoP service TXT data (from Thread side).
|
||||
*/
|
||||
SPINEL_PROP_BORDER_AGENT_MESHCOP_SERVICE_STATE = SPINEL_PROP_BORDER_AGENT__BEGIN + 1,
|
||||
|
||||
SPINEL_PROP_BORDER_AGENT__END = 0x970,
|
||||
|
||||
SPINEL_PROP_NEST__BEGIN = 0x3BC0,
|
||||
|
||||
SPINEL_PROP_NEST_STREAM_MFG = SPINEL_PROP_NEST__BEGIN + 0,
|
||||
|
||||
@@ -93,6 +93,9 @@ const ChangedPropsSet::Entry ChangedPropsSet::mSupportedProps[] = {
|
||||
#endif
|
||||
{SPINEL_PROP_PARENT_RESPONSE_INFO, SPINEL_STATUS_OK, true},
|
||||
{SPINEL_PROP_THREAD_MGMT_SET_PENDING_DATASET_TLVS, SPINEL_STATUS_OK, false},
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
{SPINEL_PROP_BORDER_AGENT_MESHCOP_SERVICE_STATE, SPINEL_STATUS_OK, false}
|
||||
#endif
|
||||
};
|
||||
|
||||
uint8_t ChangedPropsSet::GetNumEntries(void) const
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openthread/border_agent.h>
|
||||
#include <openthread/diag.h>
|
||||
#include <openthread/icmp6.h>
|
||||
#include <openthread/link.h>
|
||||
@@ -367,6 +368,9 @@ NcpBase::NcpBase(Instance *aInstance)
|
||||
#if OPENTHREAD_CONFIG_MLE_PARENT_RESPONSE_CALLBACK_API_ENABLE
|
||||
otThreadRegisterParentResponseCallback(mInstance, &NcpBase::HandleParentResponseInfo, static_cast<void *>(this));
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
otBorderAgentSetMeshCoPServiceChangedCallback(mInstance, HandleBorderAgentMeshCoPServiceChanged, this);
|
||||
#endif
|
||||
#endif // OPENTHREAD_FTD
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE
|
||||
otSrpClientSetCallback(mInstance, HandleSrpClientCallback, this);
|
||||
|
||||
@@ -457,6 +457,12 @@ protected:
|
||||
static void HandleParentResponseInfo(otThreadParentResponseInfo *aInfo, void *aContext);
|
||||
void HandleParentResponseInfo(const otThreadParentResponseInfo &aInfo);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
static void HandleBorderAgentMeshCoPServiceChanged(void *aContext);
|
||||
void HandleBorderAgentMeshCoPServiceChanged(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
static void HandleDatagramFromStack(otMessage *aMessage, void *aContext);
|
||||
|
||||
@@ -227,6 +227,9 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey)
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_SRP_SERVER_AUTO_ENABLE_MODE),
|
||||
#endif
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_BORDER_AGENT_MESHCOP_SERVICE_STATE),
|
||||
#endif
|
||||
#endif
|
||||
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_UNSOL_UPDATE_FILTER),
|
||||
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_UNSOL_UPDATE_LIST),
|
||||
|
||||
@@ -117,7 +117,7 @@ void NcpBase::HandleParentResponseInfo(const otThreadParentResponseInfo &aInfo)
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#endif // OPENTHREAD_CONFIG_MLE_PARENT_RESPONSE_CALLBACK_API_ENABLE
|
||||
|
||||
void NcpBase::HandleNeighborTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntry)
|
||||
{
|
||||
@@ -190,6 +190,21 @@ exit:
|
||||
}
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
|
||||
void NcpBase::HandleBorderAgentMeshCoPServiceChanged(void *aContext)
|
||||
{
|
||||
static_cast<NcpBase *>(aContext)->HandleBorderAgentMeshCoPServiceChanged();
|
||||
}
|
||||
|
||||
void NcpBase::HandleBorderAgentMeshCoPServiceChanged(void)
|
||||
{
|
||||
mChangedPropsSet.AddProperty(SPINEL_PROP_BORDER_AGENT_MESHCOP_SERVICE_STATE);
|
||||
mUpdateChangedPropsTask.Post();
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MARK: Individual Property Handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -1633,6 +1648,24 @@ exit:
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_NCP_DNSSD_ENABLE && OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
|
||||
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_BORDER_AGENT_MESHCOP_SERVICE_STATE>(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otBorderAgentMeshCoPServiceTxtData txtData;
|
||||
|
||||
SuccessOrExit(error = otBorderAgentGetMeshCoPServiceTxtData(mInstance, &txtData));
|
||||
SuccessOrExit(error = mEncoder.WriteBool(otBorderAgentIsActive(mInstance)));
|
||||
SuccessOrExit(error = mEncoder.WriteUint16(otBorderAgentGetUdpPort(mInstance)));
|
||||
SuccessOrExit(error = mEncoder.WriteData(txtData.mData, txtData.mLength));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
|
||||
} // namespace Ncp
|
||||
} // namespace ot
|
||||
|
||||
|
||||
Reference in New Issue
Block a user