From 4ea20944bed86f83307e0203211f1b084c785cba Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Mon, 24 Jun 2024 19:03:45 +0800 Subject: [PATCH 1/3] Post SecureSessionEstablished event when secure session is established --- src/include/platform/CHIPDeviceEvent.h | 13 +++++++++++++ src/protocols/secure_channel/PairingSession.cpp | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index 67809adda04c73..9f6b5a8e332d83 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -250,6 +250,11 @@ enum PublicEventTypes * Signals that BLE is deinitialized. */ kBLEDeinitialized, + + /** + * Signals that secure session is established. + */ + kSecureSessionEstablished, }; /** @@ -533,6 +538,14 @@ struct ChipDeviceEvent final { OtaState newState; } OtaStateChanged; + + struct + { + uint64_t PeerNodeId; + uint8_t FabricIndex; + uint8_t SecureSessionType; + uint8_t TransportType; + } SecureSessionEstablished; }; bool IsPublic() const { return DeviceEventType::IsPublic(Type); } diff --git a/src/protocols/secure_channel/PairingSession.cpp b/src/protocols/secure_channel/PairingSession.cpp index ae4ca272858a78..0f350b3db69fc8 100644 --- a/src/protocols/secure_channel/PairingSession.cpp +++ b/src/protocols/secure_channel/PairingSession.cpp @@ -22,6 +22,9 @@ #include #include #include +#include +#include +#include #include namespace chip { @@ -78,6 +81,20 @@ void PairingSession::Finish() if (err == CHIP_NO_ERROR) { VerifyOrDie(mSecureSessionHolder); + DeviceLayer::ChipDeviceEvent event; + event.Type = DeviceLayer::DeviceEventType::kSecureSessionEstablished; + event.SecureSessionEstablished.TransportType = to_underlying(address.GetTransportType()); + event.SecureSessionEstablished.SecureSessionType = + to_underlying(mSecureSessionHolder->AsSecureSession()->GetSecureSessionType()); + if (mSecureSessionHolder->AsSecureSession()->GetSecureSessionType() == Transport::SecureSession::Type::kCASE) + { + event.SecureSessionEstablished.PeerNodeId = mSecureSessionHolder->GetPeer().GetNodeId(); + event.SecureSessionEstablished.FabricIndex = mSecureSessionHolder->GetPeer().GetFabricIndex(); + } + if (DeviceLayer::PlatformMgr().PostEvent(&event) != CHIP_NO_ERROR) + { + ChipLogError(SecureChannel, "Failed to post Secure Session established event"); + } // Make sure to null out mDelegate so we don't send it any other // notifications. auto * delegate = mDelegate; From f1ee04f956d435d51c46e2e614f5d14845f8d547 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Tue, 25 Jun 2024 12:24:28 +0800 Subject: [PATCH 2/3] initialized the node id and fabric index of event data for PASE session --- src/protocols/secure_channel/PairingSession.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/protocols/secure_channel/PairingSession.cpp b/src/protocols/secure_channel/PairingSession.cpp index 0f350b3db69fc8..695d7f60cee3c9 100644 --- a/src/protocols/secure_channel/PairingSession.cpp +++ b/src/protocols/secure_channel/PairingSession.cpp @@ -86,11 +86,8 @@ void PairingSession::Finish() event.SecureSessionEstablished.TransportType = to_underlying(address.GetTransportType()); event.SecureSessionEstablished.SecureSessionType = to_underlying(mSecureSessionHolder->AsSecureSession()->GetSecureSessionType()); - if (mSecureSessionHolder->AsSecureSession()->GetSecureSessionType() == Transport::SecureSession::Type::kCASE) - { - event.SecureSessionEstablished.PeerNodeId = mSecureSessionHolder->GetPeer().GetNodeId(); - event.SecureSessionEstablished.FabricIndex = mSecureSessionHolder->GetPeer().GetFabricIndex(); - } + event.SecureSessionEstablished.PeerNodeId = mSecureSessionHolder->GetPeer().GetNodeId(); + event.SecureSessionEstablished.FabricIndex = mSecureSessionHolder->GetPeer().GetFabricIndex(); if (DeviceLayer::PlatformMgr().PostEvent(&event) != CHIP_NO_ERROR) { ChipLogError(SecureChannel, "Failed to post Secure Session established event"); From 125ef8cd45ac79b1cdcbade4743a4b419c7d799e Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Thu, 27 Jun 2024 11:53:33 +0800 Subject: [PATCH 3/3] add local session id to the event data --- src/include/platform/CHIPDeviceEvent.h | 1 + src/protocols/secure_channel/PairingSession.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index 9f6b5a8e332d83..437b20e670284f 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -545,6 +545,7 @@ struct ChipDeviceEvent final uint8_t FabricIndex; uint8_t SecureSessionType; uint8_t TransportType; + uint16_t LocalSessionId; } SecureSessionEstablished; }; diff --git a/src/protocols/secure_channel/PairingSession.cpp b/src/protocols/secure_channel/PairingSession.cpp index 695d7f60cee3c9..6176d097c5118a 100644 --- a/src/protocols/secure_channel/PairingSession.cpp +++ b/src/protocols/secure_channel/PairingSession.cpp @@ -86,8 +86,9 @@ void PairingSession::Finish() event.SecureSessionEstablished.TransportType = to_underlying(address.GetTransportType()); event.SecureSessionEstablished.SecureSessionType = to_underlying(mSecureSessionHolder->AsSecureSession()->GetSecureSessionType()); - event.SecureSessionEstablished.PeerNodeId = mSecureSessionHolder->GetPeer().GetNodeId(); - event.SecureSessionEstablished.FabricIndex = mSecureSessionHolder->GetPeer().GetFabricIndex(); + event.SecureSessionEstablished.LocalSessionId = mSecureSessionHolder->AsSecureSession()->GetLocalSessionId(); + event.SecureSessionEstablished.PeerNodeId = mSecureSessionHolder->GetPeer().GetNodeId(); + event.SecureSessionEstablished.FabricIndex = mSecureSessionHolder->GetPeer().GetFabricIndex(); if (DeviceLayer::PlatformMgr().PostEvent(&event) != CHIP_NO_ERROR) { ChipLogError(SecureChannel, "Failed to post Secure Session established event");