Skip to content

Commit

Permalink
[dtls] notify kDisconnectedLocalClosed when disconnect locally (ope…
Browse files Browse the repository at this point in the history
  • Loading branch information
sunytt authored Aug 31, 2024
1 parent f9349c1 commit d60aaab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/core/meshcop/secure_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ int SecureTransport::SetApplicationSecureKeys(void)

void SecureTransport::Close(void)
{
Disconnect();
Disconnect(kDisconnectedLocalClosed);

SetState(kStateClosed);
mTimerSet = false;
Expand All @@ -494,12 +494,15 @@ void SecureTransport::Close(void)
mTimer.Stop();
}

void SecureTransport::Disconnect(void)
void SecureTransport::Disconnect(void) { Disconnect(kDisconnectedLocalClosed); }

void SecureTransport::Disconnect(ConnectEvent aEvent)
{
VerifyOrExit(IsStateConnectingOrConnected());

mbedtls_ssl_close_notify(&mSsl);
SetState(kStateCloseNotify);
mConnectEvent = aEvent;
mTimer.Start(kGuardTimeNewConnectionMilli);

mMessageInfo.Clear();
Expand Down Expand Up @@ -1057,9 +1060,10 @@ void SecureTransport::HandleTimer(void)

void SecureTransport::Process(void)
{
uint8_t buf[OPENTHREAD_CONFIG_DTLS_MAX_CONTENT_LEN];
bool shouldDisconnect = false;
int rval;
uint8_t buf[OPENTHREAD_CONFIG_DTLS_MAX_CONTENT_LEN];
bool shouldDisconnect = false;
int rval;
ConnectEvent event;

while (IsStateConnectingOrConnected())
{
Expand Down Expand Up @@ -1093,7 +1097,7 @@ void SecureTransport::Process(void)
{
case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
mbedtls_ssl_close_notify(&mSsl);
mConnectEvent = kDisconnectedPeerClosed;
event = kDisconnectedPeerClosed;
ExitNow(shouldDisconnect = true);
OT_UNREACHABLE_CODE(break);

Expand All @@ -1102,7 +1106,7 @@ void SecureTransport::Process(void)

case MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE:
mbedtls_ssl_close_notify(&mSsl);
mConnectEvent = kDisconnectedError;
event = kDisconnectedError;
ExitNow(shouldDisconnect = true);
OT_UNREACHABLE_CODE(break);

Expand All @@ -1111,7 +1115,7 @@ void SecureTransport::Process(void)
{
mbedtls_ssl_send_alert_message(&mSsl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC);
mConnectEvent = kDisconnectedError;
event = kDisconnectedError;
ExitNow(shouldDisconnect = true);
}

Expand All @@ -1122,7 +1126,7 @@ void SecureTransport::Process(void)
{
mbedtls_ssl_send_alert_message(&mSsl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE);
mConnectEvent = kDisconnectedError;
event = kDisconnectedError;
ExitNow(shouldDisconnect = true);
}

Expand All @@ -1142,7 +1146,7 @@ void SecureTransport::Process(void)

if (shouldDisconnect)
{
Disconnect();
Disconnect(event);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/core/meshcop/secure_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ class SecureTransport : public InstanceLocator
Error HandleSecureTransportSend(const uint8_t *aBuf, uint16_t aLength, Message::SubType aMessageSubType);

void Process(void);
void Disconnect(ConnectEvent aEvent);

#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
static const char *StateToString(State aState);
Expand Down

0 comments on commit d60aaab

Please sign in to comment.