[border-agent] add api to disconnect from secure sessions (#10754)

This commit is contained in:
Yang Sun
2024-10-08 09:18:05 -07:00
committed by GitHub
parent a8bf8e7095
commit be74a3c035
8 changed files with 63 additions and 1 deletions
+13
View File
@@ -282,6 +282,19 @@ void otBorderAgentSetEphemeralKeyCallback(otInstance *aIns
otBorderAgentEphemeralKeyCallback aCallback,
void *aContext);
/**
* Disconnects the Border Agent from any active secure sessions.
*
* If Border Agent is connected to a commissioner candidate with ephemeral key, calling this API
* will cause the ephemeral key to be cleared after the session is disconnected.
*
* The Border Agent state may not change immediately upon calling this method. The state will be
* updated when the connection update is notified with a delay.
*
* @param[in] aInstance The OpenThread instance.
*/
void otBorderAgentDisconnect(otInstance *aInstance);
/**
* @}
*/
+1 -1
View File
@@ -52,7 +52,7 @@ extern "C" {
*
* @note This number versions both OpenThread platform and user APIs.
*/
#define OPENTHREAD_API_VERSION (452)
#define OPENTHREAD_API_VERSION (453)
/**
* @addtogroup api-instance
+9
View File
@@ -373,6 +373,15 @@ Started
Done
```
### ba disconnect
Disconnects border agent from any active secure sessions.
```bash
> ba disconnect
Done
```
### ba ephemeralkey
Indicates if an ephemeral key is active.
+14
View File
@@ -411,6 +411,20 @@ template <> otError Interpreter::Process<Cmd("ba")>(Arg aArgs[])
OutputLine("%s", Stringify(otBorderAgentGetState(GetInstancePtr()), kStateStrings));
}
/**
* @cli ba disconnect
* @code
* ba disconnect
* Done
* @endcode
* @par
* Disconnects the Border Agent from any active secure sessions
* @sa otBorderAgentDisconnect
*/
else if (aArgs[0] == "disconnect")
{
otBorderAgentDisconnect(GetInstancePtr());
}
#if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE
/**
* @cli ba id (get,set)
+2
View File
@@ -115,4 +115,6 @@ const otBorderAgentCounters *otBorderAgentGetCounters(otInstance *aInstance)
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().GetCounters();
}
void otBorderAgentDisconnect(otInstance *aInstance) { AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().Disconnect(); }
#endif // OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
+10
View File
@@ -775,6 +775,16 @@ exit:
return;
}
void BorderAgent::Disconnect(void)
{
VerifyOrExit(mState == kStateConnected || mState == kStateAccepted);
Get<Tmf::SecureAgent>().Disconnect();
exit:
return;
}
#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE
Error BorderAgent::SetEphemeralKey(const char *aKeyString, uint32_t aTimeout, uint16_t aUdpPort)
+11
View File
@@ -157,6 +157,17 @@ public:
*/
State GetState(void) const { return mState; }
/**
* Disconnects the Border Agent from any active secure sessions.
*
* If Border Agent is connected to a commissioner candidate with ephemeral key, calling this API
* will cause the ephemeral key to be cleared after the session is disconnected.
*
* The Border Agent state may not change immediately upon calling this method, the state will be
* updated when the connection update is notified by `HandleConnected()`.
*/
void Disconnect(void);
#if OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE
/**
* Sets the ephemeral key for a given timeout duration.
+3
View File
@@ -184,6 +184,9 @@ expect "Done"
send "ba state\n"
expect "Done"
send "ba disconnect\n"
expect "Done"
send "prefix meshlocal fd00:dead:beef:cafe::/96\n"
expect_line "Error 7: InvalidArgs"
send "prefix meshlocal fd00:dead:beef:cafe::/64\n"