@@ -946,12 +946,12 @@ CHIP_ERROR CASESession::HandleSigma1_and_SendSigma2(System::PacketBufferHandle &
946
946
MATTER_TRACE_SCOPE (" HandleSigma1_and_SendSigma2" , " CASESession" );
947
947
948
948
CHIP_ERROR err = CHIP_NO_ERROR;
949
- Step nextStep = Step::kNone ;
950
949
951
950
// Parse and Validate Received Sigma1, and decide next step
952
- SuccessOrExit (err = HandleSigma1 (std::move (msg), nextStep));
951
+ NextStep nextStep = HandleSigma1 (std::move (msg));
952
+ VerifyOrExit (nextStep.Is <Step>(), err = nextStep.Get <CHIP_ERROR>());
953
953
954
- switch (nextStep)
954
+ switch (nextStep. Get <Step>() )
955
955
{
956
956
case Step::kSendSigma2 : {
957
957
@@ -982,15 +982,11 @@ CHIP_ERROR CASESession::HandleSigma1_and_SendSigma2(System::PacketBufferHandle &
982
982
mDelegate ->OnSessionEstablishmentStarted ();
983
983
break ;
984
984
}
985
- // TODO should I keep this?
986
- case Step::kSendStatusReport :
987
985
default :
988
- ExitNow ();
989
986
break ;
990
987
}
991
988
992
989
exit :
993
-
994
990
if (err == CHIP_ERROR_KEY_NOT_FOUND)
995
991
{
996
992
SendStatusReport (mExchangeCtxt , kProtocolCodeNoSharedRoot );
@@ -1082,23 +1078,23 @@ CHIP_ERROR CASESession::TryResumeSession(SessionResumptionStorage::ConstResumpti
1082
1078
1083
1079
return CHIP_NO_ERROR;
1084
1080
}
1085
- CHIP_ERROR CASESession::HandleSigma1 (System::PacketBufferHandle && msg, Step & nextStep )
1081
+ CASESession::NextStep CASESession::HandleSigma1 (System::PacketBufferHandle && msg)
1086
1082
{
1087
1083
MATTER_TRACE_SCOPE (" HandleSigma1" , " CASESession" );
1088
1084
ChipLogProgress (SecureChannel, " Received Sigma1 msg" );
1089
1085
MATTER_TRACE_COUNTER (" Sigma1" );
1090
1086
1091
- VerifyOrReturnError (mFabricsTable != nullptr , CHIP_ERROR_INCORRECT_STATE);
1087
+ VerifyOrReturnError (mFabricsTable != nullptr , NextStep::Create<CHIP_ERROR>( CHIP_ERROR_INCORRECT_STATE) );
1092
1088
1093
- ReturnErrorOnFailure ( mCommissioningHash .AddData (ByteSpan{ msg->Start (), msg->DataLength () }));
1089
+ ReturnErrorVariantOnFailure (NextStep, mCommissioningHash .AddData (ByteSpan{ msg->Start (), msg->DataLength () }));
1094
1090
1095
1091
System::PacketBufferTLVReader tlvReader;
1096
1092
tlvReader.Init (std::move (msg));
1097
1093
1098
1094
// Struct that will serve as output in ParseSigma1
1099
1095
ParsedSigma1 parsedSigma1;
1100
1096
1101
- ReturnErrorOnFailure ( ParseSigma1 (tlvReader, parsedSigma1));
1097
+ ReturnErrorVariantOnFailure (NextStep, ParseSigma1 (tlvReader, parsedSigma1));
1102
1098
1103
1099
ChipLogDetail (SecureChannel, " Peer assigned session key ID %d" , parsedSigma1.initiatorSessionId );
1104
1100
SetPeerSessionId (parsedSigma1.initiatorSessionId );
@@ -1119,12 +1115,9 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg, Step & n
1119
1115
std::copy (parsedSigma1.initiatorRandom .begin (), parsedSigma1.initiatorRandom .end (), mInitiatorRandom );
1120
1116
std::copy (parsedSigma1.resumptionId .begin (), parsedSigma1.resumptionId .end (), mResumeResumptionId .begin ());
1121
1117
1122
- // Next Step is to send Sigma2Resume message to the initiator
1123
- nextStep = Step::kSendSigma2Resume ;
1124
-
1125
1118
// Early returning here, since the next Step is known to be Sigma2Resume, and no further processing is needed for the
1126
1119
// Sigma1 message
1127
- return CHIP_NO_ERROR ;
1120
+ return NextStep::Create<Step>(Step:: kSendSigma2Resume ) ;
1128
1121
}
1129
1122
1130
1123
// ParseSigma1 ensures that:
@@ -1143,21 +1136,21 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg, Step & n
1143
1136
// Side-effect of FindLocalNodeFromDestinationId success was that mFabricIndex/mLocalNodeId are now
1144
1137
// set to the local fabric and associated NodeId that was targeted by the initiator.
1145
1138
1146
- nextStep = Step::kSendSigma2 ;
1139
+ return NextStep::Create< Step>(Step ::kSendSigma2 ) ;
1147
1140
}
1148
1141
else
1149
1142
{
1150
1143
ChipLogError (SecureChannel, " CASE failed to match destination ID with local fabrics" );
1151
1144
ChipLogByteSpan (SecureChannel, parsedSigma1.destinationId );
1152
1145
1153
- // FindLocalNodeFromDestinationId returns CHIP_ERROR_KEY_NOT_FOUND if validation of DestinationID fails, which will trigger
1154
- // status Report with ProtocolCode = NoSharedTrustRoots.
1155
- nextStep = Step::kSendStatusReport ;
1146
+ // FindLocalNodeFromDestinationId returns CHIP_ERROR_KEY_NOT_FOUND if Sigma1's DestinationId does not match any
1147
+ // candidateDestinationId, this will trigger a status Report with ProtocolCode = NoSharedTrustRoots.
1156
1148
1157
- return err;
1149
+ // Returning a CHIP_ERROR variant that will trigger a corresponding Status Report.
1150
+ return NextStep::Create<CHIP_ERROR>(err);
1158
1151
}
1159
1152
1160
- return CHIP_NO_ERROR;
1153
+ return NextStep::Create<CHIP_ERROR>( CHIP_NO_ERROR) ;
1161
1154
}
1162
1155
1163
1156
CHIP_ERROR CASESession::PrepareSigma2Resume (EncodeSigma2ResumeInputs & outSigma2ResData)
0 commit comments