[tmf] add SecureAgent and simplify URI resource processing (#8260)

This commit adds a new class `Tmf::SecureAgent` as a sub-class of
`Coap::CoapSecure`. It also simplifies the handling of TMF URI
resources by secure agent (similar model as in `Tmf::Agent` added
in #8233.
This commit is contained in:
Abtin Keshavarzian
2022-10-10 12:40:26 -07:00
committed by Jonathan Hui
parent 09e06c6eff
commit 13311256f6
10 changed files with 219 additions and 194 deletions
+60
View File
@@ -228,5 +228,65 @@ exit:
return isTmf;
}
#if OPENTHREAD_CONFIG_DTLS_ENABLE
SecureAgent::SecureAgent(Instance &aInstance)
: Coap::CoapSecure(aInstance)
{
SetResourceHandler(&HandleResource);
}
bool SecureAgent::HandleResource(CoapBase & aCoapBase,
const char * aUriPath,
Message & aMessage,
const Ip6::MessageInfo &aMessageInfo)
{
return static_cast<SecureAgent &>(aCoapBase).HandleResource(aUriPath, aMessage, aMessageInfo);
}
bool SecureAgent::HandleResource(const char *aUriPath, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
OT_UNUSED_VARIABLE(aMessage);
OT_UNUSED_VARIABLE(aMessageInfo);
bool didHandle = true;
Uri uri = UriFromPath(aUriPath);
#define Case(kUri, Type) \
case kUri: \
Get<Type>().HandleTmf<kUri>(aMessage, aMessageInfo); \
break
switch (uri)
{
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
Case(kUriJoinerFinalize, MeshCoP::Commissioner);
#endif
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
Case(kUriCommissionerPetition, MeshCoP::BorderAgent);
Case(kUriCommissionerKeepAlive, MeshCoP::BorderAgent);
Case(kUriRelayTx, MeshCoP::BorderAgent);
Case(kUriCommissionerGet, MeshCoP::BorderAgent);
Case(kUriCommissionerSet, MeshCoP::BorderAgent);
Case(kUriActiveGet, MeshCoP::BorderAgent);
Case(kUriActiveSet, MeshCoP::BorderAgent);
Case(kUriPendingGet, MeshCoP::BorderAgent);
Case(kUriPendingSet, MeshCoP::BorderAgent);
Case(kUriProxyTx, MeshCoP::BorderAgent);
#endif
default:
didHandle = false;
break;
}
#undef Case
return didHandle;
}
#endif // OPENTHREAD_CONFIG_DTLS_ENABLE
} // namespace Tmf
} // namespace ot