2727#include < app/clusters/network-commissioning/WifiScanResponse.h>
2828#include < app/data-model/Nullable.h>
2929#include < app/reporting/reporting.h>
30+ #include < app/server/Server.h>
3031#include < app/server-cluster/AttributeListBuilder.h>
3132#include < app/server-cluster/DefaultServerCluster.h>
3233#include < clusters/NetworkCommissioning/AttributeIds.h>
3940#include < lib/core/CHIPError.h>
4041#include < lib/core/DataModelTypes.h>
4142#include < lib/support/AutoRelease.h>
43+ #include < lib/support/BytesToHex.h>
4244#include < lib/support/CodeUtils.h>
4345#include < lib/support/SafeInt.h>
4446#include < lib/support/SortUtils.h>
4850#include < platform/ConnectivityManager.h>
4951#include < platform/internal/DeviceNetworkInfo.h>
5052#include < protocols/interaction_model/StatusCode.h>
53+ #include < transport/SecureSession.h>
5154#include < tracing/macros.h>
5255
5356namespace chip {
@@ -61,6 +64,13 @@ using namespace chip::app::Clusters::NetworkCommissioning;
6164
6265namespace {
6366
67+ bool IsConnectNetworkRequestOverPASE (CommandHandler & handler)
68+ {
69+ Messaging::ExchangeContext * exchangeCtx = handler.GetExchangeContext ();
70+ return exchangeCtx && exchangeCtx->HasSessionHandle () && exchangeCtx->GetSessionHandle ()->IsSecureSession () &&
71+ exchangeCtx->GetSessionHandle ()->AsSecureSession ()->GetSecureSessionType () == Transport::SecureSession::Type::kPASE ;
72+ }
73+
6474// Note: CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE can be 0, this disables debug text
6575using DebugTextStorage = std::array<char , CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE>;
6676
@@ -640,18 +650,45 @@ NetworkCommissioningCluster::HandleConnectNetwork(CommandHandler & handler, cons
640650#else
641651 // In Non-concurrent mode postpone the final execution of ConnectNetwork until the operational
642652 // network has been fully brought up and kOperationalNetworkStarted is delivered.
643- // mConnectingNetworkIDLen and mConnectingNetworkID contain the received SSID
644- // As per spec, send the ConnectNetworkResponse(Success) prior to releasing the commissioning channel
645- SendNonConcurrentConnectNetworkResponse ();
653+ // mConnectingNetworkIDLen and mConnectingNetworkID contain the received SSID.
654+ //
655+ // For PASE/BLE requests, reply before tearing down the commissioning transport.
656+ // For CASE requests, keep the command open and reply from OnResult after attach finishes.
657+ if (IsConnectNetworkRequestOverPASE (handler))
658+ {
659+ SendNonConcurrentConnectNetworkResponse ();
660+ }
661+ else
662+ {
663+ HandleNonConcurrentConnectNetwork ();
664+ }
646665#endif
647666 return std::nullopt ;
648667}
649668
650669std::optional<ActionReturnStatus> NetworkCommissioningCluster::HandleNonConcurrentConnectNetwork ()
651670{
652671 ByteSpan nonConcurrentNetworkID = ByteSpan (mConnectingNetworkID , mConnectingNetworkIDLen );
653- ChipLogProgress (NetworkProvisioning, " Non-concurrent mode, Connect to Network SSID=%s" ,
654- NullTerminated (mConnectingNetworkID , mConnectingNetworkIDLen ).c_str ());
672+ if (mFeatureFlags .Has (Feature::kThreadNetworkInterface ))
673+ {
674+ constexpr size_t kThreadNetworkIdHexMax = (2 * kMaxNetworkIDLen ) + 1 ;
675+ char threadNetworkIdHex[kThreadNetworkIdHexMax ];
676+ if (Encoding::BytesToUppercaseHexString (nonConcurrentNetworkID.data (), nonConcurrentNetworkID.size (), threadNetworkIdHex,
677+ sizeof (threadNetworkIdHex)) == CHIP_NO_ERROR)
678+ {
679+ ChipLogProgress (NetworkProvisioning, " Non-concurrent mode, Connect to Thread Network ID=%s" , threadNetworkIdHex);
680+ }
681+ else
682+ {
683+ ChipLogProgress (NetworkProvisioning, " Non-concurrent mode, Connect to Thread Network ID (len=%u)" ,
684+ static_cast <unsigned >(nonConcurrentNetworkID.size ()));
685+ }
686+ }
687+ else
688+ {
689+ ChipLogProgress (NetworkProvisioning, " Non-concurrent mode, Connect to Wi-Fi SSID=%s" ,
690+ NullTerminated (mConnectingNetworkID , mConnectingNetworkIDLen ).c_str ());
691+ }
655692 mpWirelessDriver->ConnectNetwork (nonConcurrentNetworkID, this );
656693 return std::nullopt ;
657694}
0 commit comments