@@ -49,8 +49,10 @@ void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter
49
49
if (commissionersCount == 0 )
50
50
{
51
51
ChipLogProgress (AppServer, " Select discovered Casting Player (start index = 0) to request commissioning" );
52
+ ChipLogProgress (AppServer, " Include the cgp flag to attempt the Commissioner-Generated Passcode commissioning flow" );
52
53
53
- ChipLogProgress (AppServer, " Example: cast request 0" );
54
+ ChipLogProgress (AppServer, " Example1 Commissionee Passcode: cast request 0" );
55
+ ChipLogProgress (AppServer, " Example2 Commissioner Passcode: cast request 0 cgp" );
54
56
}
55
57
ChipLogProgress (AppServer, " Discovered CastingPlayer #%d" , commissionersCount);
56
58
++commissionersCount;
@@ -170,10 +172,12 @@ void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * ca
170
172
{
171
173
VerifyOrReturn (err == CHIP_NO_ERROR,
172
174
ChipLogProgress (AppServer,
173
- " ConnectionHandler: Failed to connect to CastingPlayer(ID: %s) with err %" CHIP_ERROR_FORMAT,
175
+ " ConnectionHandler() : Failed to connect to CastingPlayer(ID: %s) with err %" CHIP_ERROR_FORMAT,
174
176
castingPlayer->GetId (), err.Format ()));
175
177
176
- ChipLogProgress (AppServer, " ConnectionHandler: Successfully connected to CastingPlayer(ID: %s)" , castingPlayer->GetId ());
178
+ ChipLogProgress (AppServer, " ConnectionHandler(): Successfully connected to CastingPlayer(ID: %s)" , castingPlayer->GetId ());
179
+ ChipLogProgress (AppServer, " ConnectionHandler(): Triggering demo interactions with CastingPlayer(ID: %s)" ,
180
+ castingPlayer->GetId ());
177
181
178
182
std::vector<matter::casting::memory::Strong<matter::casting::core::Endpoint>> endpoints = castingPlayer->GetEndpoints ();
179
183
// Find the desired Endpoint and auto-trigger some Matter Casting demo interactions
@@ -219,18 +223,18 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
219
223
}
220
224
if (strcmp (argv[0 ], " discover" ) == 0 )
221
225
{
222
- ChipLogProgress (AppServer, " discover" );
226
+ ChipLogProgress (AppServer, " CommandHandler() discover" );
223
227
224
228
return matter::casting::core::CastingPlayerDiscovery::GetInstance ()->StartDiscovery (kTargetPlayerDeviceType );
225
229
}
226
230
if (strcmp (argv[0 ], " stop-discovery" ) == 0 )
227
231
{
228
- ChipLogProgress (AppServer, " stop-discovery" );
232
+ ChipLogProgress (AppServer, " CommandHandler() stop-discovery" );
229
233
return matter::casting::core::CastingPlayerDiscovery::GetInstance ()->StopDiscovery ();
230
234
}
231
235
if (strcmp (argv[0 ], " request" ) == 0 )
232
236
{
233
- ChipLogProgress (AppServer, " request" );
237
+ ChipLogProgress (AppServer, " CommandHandler() request" );
234
238
if (argc < 2 )
235
239
{
236
240
return PrintAllCommands ();
@@ -243,10 +247,40 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
243
247
ChipLogError (AppServer, " Invalid casting player index provided: %lu" , index ));
244
248
std::shared_ptr<matter::casting::core::CastingPlayer> targetCastingPlayer = castingPlayers.at (index );
245
249
246
- matter::casting::core::EndpointFilter desiredEndpointFilter;
247
- desiredEndpointFilter.vendorId = kDesiredEndpointVendorId ;
250
+ matter::casting::core::IdentificationDeclarationOptions idOptions;
251
+ if (argc == 3 )
252
+ {
253
+ if (strcmp (argv[2 ], " cgp" ) == 0 )
254
+ {
255
+ // Attempt Commissioner-Generated Passcode (cgp) commissioning flow only if the CastingPlayer indicates support for
256
+ // it.
257
+ if (targetCastingPlayer->GetSupportsCommissionerGeneratedPasscode ())
258
+ {
259
+ ChipLogProgress (
260
+ AppServer,
261
+ " CommandHandler() request %lu cgp. Attempting the Commissioner-Generated Passcode commissioning flow" ,
262
+ index );
263
+ idOptions.mCommissionerPasscode = true ;
264
+ }
265
+ else
266
+ {
267
+ ChipLogError (AppServer,
268
+ " CommandHandler() request %lu cgp. Selected CastingPLayer does not support the "
269
+ " Commissioner-Generated Passcode commissioning flow" ,
270
+ index );
271
+ }
272
+ }
273
+ }
274
+ chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
275
+ targetAppInfo.vendorId = kDesiredEndpointVendorId ;
276
+ CHIP_ERROR result = idOptions.addTargetAppInfo (targetAppInfo);
277
+ if (result != CHIP_NO_ERROR)
278
+ {
279
+ ChipLogError (AppServer, " CommandHandler() request, failed to add targetAppInfo: %" CHIP_ERROR_FORMAT, result.Format ());
280
+ }
281
+
248
282
targetCastingPlayer->VerifyOrEstablishConnection (ConnectionHandler, matter::casting::core::kCommissioningWindowTimeoutSec ,
249
- desiredEndpointFilter );
283
+ idOptions );
250
284
return CHIP_NO_ERROR;
251
285
}
252
286
if (strcmp (argv[0 ], " print-bindings" ) == 0 )
@@ -280,8 +314,12 @@ CHIP_ERROR PrintAllCommands()
280
314
" delete-fabric <index> Delete a fabric from the casting client's fabric store. Usage: cast delete-fabric 1\r\n " );
281
315
streamer_printf (sout, " discover Discover Casting Players. Usage: cast discover\r\n " );
282
316
streamer_printf (sout, " stop-discovery Stop Discovery of Casting Players. Usage: cast stop-discovery\r\n " );
283
- streamer_printf (
284
- sout, " request <index> Request connecting to discovered Casting Player with [index]. Usage: cast request 0\r\n " );
317
+ streamer_printf (sout,
318
+ " request <index> Request connecting to discovered Casting Player with [index] using the "
319
+ " Commissionee-Generated Passcode commissioning flow. Usage: cast request 0\r\n " );
320
+ streamer_printf (sout,
321
+ " request <index> cgp Request connecting to discovered Casting Player with [index] using the "
322
+ " Commissioner-Generated Passcode commissioning flow. Usage: cast request 0 cgp\r\n " );
285
323
streamer_printf (sout, " \r\n " );
286
324
287
325
return CHIP_NO_ERROR;
0 commit comments