ot::MeshCoP::BorderAgent::SetEphemeralKey() method
Sets the ephemeral key for a given timeout duration. The ephemeral key can be set when the Border Agent is already running and is not currently connected to any external commissioner (i.e., it is in `kStateStarted` state). To terminate active commissioner sessions, use the `Disconnect()` function. The given @p aKeyString is directly used as the ephemeral PSK (excluding the trailing null `\0` character). Its length must be between `kMinEphemeralKeyLength` and `kMaxEphemeralKeyLength`, inclusive. Setting the ephemeral key again before a previously set one is timed out will replace the previous one and will reset the timeout. During the timeout interval, the ephemeral key can be used only once by an external commissioner to establish a connection. After the commissioner disconnects, the ephemeral key is cleared, and the Border Agent reverts to using PSKc. If the timeout expires while a commissioner is still connected, the session will be terminated, and the Border Agent will cease using the ephemeral key and revert to PSKc.
Arguments
aKeyString
The ephemeral key.
aTimeout
The timeout duration in milliseconds to use the ephemeral key. If zero, the default `kDefaultEphemeralKeyTimeout` value will be used. If the timeout value is larger than `kMaxEphemeralKeyTimeout`, the max value will be used instead.
aUdpPort
The UDP port to use with ephemeral key. If UDP port is zero, an ephemeral port will be used. `GetUdpPort()` will return the current UDP port being used.
Return value
kErrorNone Successfully set the ephemeral key. kErrorInvalidState Agent is not running or connected to external commissioner. kErrorInvalidArgs The given @p aKeyString is not valid. kErrorFailed Failed to set the key (e.g., could not bind to UDP port).