@@ -68,12 +68,14 @@ void CastingPlayer::VerifyOrEstablishConnection(ConnectionCallbacks connectionCa
68
68
// Set the callback for handling CommissionerDeclaration messages.
69
69
matter::casting::core::CommissionerDeclarationHandler::GetInstance ()->SetCommissionerDeclarationCallback (
70
70
connectionCallbacks.mCommissionerDeclarationCallback );
71
+ mClientProvidedCommissionerDeclarationCallback = true ;
71
72
}
72
73
else
73
74
{
74
75
ChipLogProgress (
75
76
AppServer,
76
77
" CastingPlayer::VerifyOrEstablishConnection() CommissionerDeclarationCallback not provided in ConnectionCallbacks" );
78
+ mClientProvidedCommissionerDeclarationCallback = false ;
77
79
}
78
80
79
81
ChipLogProgress (AppServer, " CastingPlayer::VerifyOrEstablishConnection() verifying User Directed Commissioning (UDC) state" );
@@ -107,6 +109,7 @@ void CastingPlayer::VerifyOrEstablishConnection(ConnectionCallbacks connectionCa
107
109
// found the CastingPlayer in cache
108
110
if (it != cachedCastingPlayers.end ())
109
111
{
112
+ ChipLogProgress (AppServer, " CastingPlayer::VerifyOrEstablishConnection() found this CastingPlayer in app cache" );
110
113
unsigned index = (unsigned int ) std::distance (cachedCastingPlayers.begin (), it);
111
114
if (ContainsDesiredTargetApp (&cachedCastingPlayers[index ], idOptions.getTargetAppInfoList ()))
112
115
{
@@ -225,16 +228,24 @@ CHIP_ERROR CastingPlayer::ContinueConnecting()
225
228
226
229
CHIP_ERROR CastingPlayer::StopConnecting ()
227
230
{
228
- ChipLogProgress (AppServer, " CastingPlayer::StopConnecting() called, while ChipDeviceEventHandler.sUdcInProgress: %s" ,
229
- support::ChipDeviceEventHandler::isUdcInProgress () ? " true" : " false" );
230
- VerifyOrReturnValue (mConnectionState == CASTING_PLAYER_CONNECTING, CHIP_ERROR_INCORRECT_STATE,
231
- ChipLogError (AppServer, " CastingPlayer::StopConnecting() called while not in connecting state" ););
232
231
VerifyOrReturnValue (
233
232
mIdOptions .mCommissionerPasscode , CHIP_ERROR_INCORRECT_STATE,
234
233
ChipLogError (AppServer,
235
234
" CastingPlayer::StopConnecting() mIdOptions.mCommissionerPasscode == false, ContinueConnecting() should only "
236
235
" be called when the CastingPlayer/Commissioner-Generated passcode commissioning flow is in progress." ););
236
+ // Calling the internal StopConnecting() API with the shouldSendIdentificationDeclarationMessage set to true to notify the
237
+ // CastingPlayer/Commissioner that the commissioning session was cancelled by the Casting Client/Commissionee user. This will
238
+ // result in the Casting Client/Commissionee sending a CancelPasscode IdentificationDeclaration message to the CastingPlayer.
239
+ // shouldSendIdentificationDeclarationMessage is true when StopConnecting() is called by the Client.
240
+ return this ->StopConnecting (true );
241
+ }
237
242
243
+ CHIP_ERROR CastingPlayer::StopConnecting (bool shouldSendIdentificationDeclarationMessage)
244
+ {
245
+ ChipLogProgress (AppServer, " CastingPlayer::StopConnecting() called, while ChipDeviceEventHandler.sUdcInProgress: %s" ,
246
+ support::ChipDeviceEventHandler::isUdcInProgress () ? " true" : " false" );
247
+ VerifyOrReturnValue (mConnectionState == CASTING_PLAYER_CONNECTING, CHIP_ERROR_INCORRECT_STATE,
248
+ ChipLogError (AppServer, " CastingPlayer::StopConnecting() called while not in connecting state" ););
238
249
CHIP_ERROR err = CHIP_NO_ERROR;
239
250
mIdOptions .resetState ();
240
251
mIdOptions .mCancelPasscode = true ;
@@ -243,6 +254,16 @@ CHIP_ERROR CastingPlayer::StopConnecting()
243
254
mTargetCastingPlayer .reset ();
244
255
CastingPlayerDiscovery::GetInstance ()->ClearCastingPlayersInternal ();
245
256
257
+ if (!shouldSendIdentificationDeclarationMessage)
258
+ {
259
+ ChipLogProgress (AppServer,
260
+ " CastingPlayer::StopConnecting() shouldSendIdentificationDeclarationMessage: %d, User Directed "
261
+ " Commissioning aborted by the CastingPlayer/Commissioner user." ,
262
+ shouldSendIdentificationDeclarationMessage);
263
+ resetState (CHIP_ERROR_CONNECTION_ABORTED);
264
+ return err;
265
+ }
266
+
246
267
// If a CastingPlayer::ContinueConnecting() error occurs, StopConnecting() can be called while sUdcInProgress == true.
247
268
// sUdcInProgress should be set to false before sending the CancelPasscode IdentificationDeclaration message to the
248
269
// CastingPlayer/Commissioner.
@@ -251,9 +272,9 @@ CHIP_ERROR CastingPlayer::StopConnecting()
251
272
support::ChipDeviceEventHandler::SetUdcStatus (false );
252
273
}
253
274
254
- ChipLogProgress (
255
- AppServer,
256
- " CastingPlayer::StopConnecting() calling SendUserDirectedCommissioningRequest() to indicate user canceled passcode entry" );
275
+ ChipLogProgress (AppServer,
276
+ " CastingPlayer::StopConnecting() calling SendUserDirectedCommissioningRequest() to indicate "
277
+ " Client/Commissionee user canceled passcode entry" );
257
278
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
258
279
err = SendUserDirectedCommissioningRequest ();
259
280
if (err != CHIP_NO_ERROR)
0 commit comments