@@ -228,6 +228,11 @@ CHIP_ERROR PAFTransportCapabilitiesResponseMessage::Decode(const PacketBufferHan
228
228
* WiFiPAFLayer Implementation
229
229
*/
230
230
231
+ WiFiPAFLayer::WiFiPAFLayer ()
232
+ {
233
+ InitialPafInfo ();
234
+ }
235
+
231
236
CHIP_ERROR WiFiPAFLayer::Init (chip::System::Layer * systemLayer)
232
237
{
233
238
mSystemLayer = systemLayer;
@@ -238,23 +243,26 @@ CHIP_ERROR WiFiPAFLayer::Init(chip::System::Layer * systemLayer)
238
243
239
244
void WiFiPAFLayer::Shutdown (OnCancelDeviceHandle OnCancelDevice)
240
245
{
241
- ChipLogProgress (WiFiPAF, " WiFiPAF: Closing all WiFiPAF sessions (%lu)" , PafInfoVect.size ());
242
- for (WiFiPAFSession & PafInfoElm : PafInfoVect)
246
+ ChipLogProgress (WiFiPAF, " WiFiPAF: Closing all WiFiPAF sessions to shutdown" );
247
+ uint8_t i;
248
+ WiFiPAFSession * pPafSession;
249
+
250
+ for (i = 0 ; i < WIFIPAF_LAYER_NUM_PAF_ENDPOINTS; i++)
243
251
{
244
- if (PafInfoElm.id == UINT32_MAX)
252
+ pPafSession = &mPafInfoVect [i];
253
+ if (pPafSession->id == UINT32_MAX)
245
254
{
246
255
// Unused session
247
256
continue ;
248
257
}
249
- ChipLogProgress (WiFiPAF, " WiFiPAF: Canceling id: %u" , PafInfoElm. id );
250
- OnCancelDevice (PafInfoElm. id , PafInfoElm. role );
251
- WiFiPAFEndPoint * endPoint = sWiFiPAFEndPointPool .Find (reinterpret_cast <WIFIPAF_CONNECTION_OBJECT>(&PafInfoElm ));
258
+ ChipLogProgress (WiFiPAF, " WiFiPAF: Canceling id: %u" , pPafSession-> id );
259
+ OnCancelDevice (pPafSession-> id , pPafSession-> role );
260
+ WiFiPAFEndPoint * endPoint = sWiFiPAFEndPointPool .Find (reinterpret_cast <WIFIPAF_CONNECTION_OBJECT>(pPafSession ));
252
261
if (endPoint != nullptr )
253
262
{
254
263
endPoint->DoClose (kWiFiPAFCloseFlag_AbortTransmission , WIFIPAF_ERROR_APP_CLOSED_CONNECTION);
255
264
}
256
265
}
257
- PafInfoVect.clear ();
258
266
}
259
267
260
268
bool WiFiPAFLayer::OnWiFiPAFMessageReceived (WiFiPAFSession & RxInfo, System::PacketBufferHandle && msg)
@@ -384,84 +392,143 @@ WiFiPAFLayer::GetHighestSupportedProtocolVersion(const PAFTransportCapabilitiesR
384
392
return retVersion;
385
393
}
386
394
387
- void WiFiPAFLayer::AddPafSession (const NodeId nodeId, const uint16_t discriminator)
395
+ #define INVALID_PAF_SESSION_ID 0xff
396
+ void WiFiPAFLayer::InitialPafInfo ()
388
397
{
389
- for (auto PafInfoElm : PafInfoVect )
398
+ for (uint8_t i = 0 ; i < WIFIPAF_LAYER_NUM_PAF_ENDPOINTS; i++ )
390
399
{
391
- if (PafInfoElm.nodeId == nodeId)
392
- {
393
- assert (PafInfoElm.discriminator == discriminator);
394
- // Already exist
395
- return ;
396
- }
400
+ cleanPafInfo (mPafInfoVect [i]);
397
401
}
398
- PafInfoVect.push_back ({ .id = UINT32_MAX, .peer_id = UINT32_MAX, .nodeId = nodeId, .discriminator = discriminator });
399
- ChipLogProgress (WiFiPAF, " WiFiPAF: Add session with nodeId: %lu, disc: %x, total %lu sessions" , nodeId, discriminator,
400
- PafInfoVect.size ());
401
402
}
402
403
403
- void WiFiPAFLayer::AddPafSession ( uint32_t id )
404
+ void WiFiPAFLayer::cleanPafInfo (WiFiPAFSession & SessionInfo )
404
405
{
405
- for (auto PafInfoElm : PafInfoVect)
406
- {
407
- if (PafInfoElm.id == id)
408
- {
409
- // Already exist
410
- return ;
411
- }
412
- }
413
- PafInfoVect.push_back ({ .id = id });
414
- ChipLogProgress (WiFiPAF, " WiFiPAF: Add session with id: %u, total %lu sessions" , id, PafInfoVect.size ());
406
+ memset (&SessionInfo, 0 , sizeof (WiFiPAFSession));
407
+ SessionInfo.id = UINT32_MAX;
408
+ SessionInfo.peer_id = UINT32_MAX;
409
+ SessionInfo.nodeId = UINT32_MAX;
410
+ SessionInfo.discriminator = UINT16_MAX;
411
+ return ;
415
412
}
416
413
417
- void WiFiPAFLayer::RmPafSession ( uint32_t id )
414
+ CHIP_ERROR WiFiPAFLayer::AddPafSession (PafInfoAccess accType, WiFiPAFSession & SessionInfo )
418
415
{
419
- for (std::vector<WiFiPAFSession>::iterator it = PafInfoVect.begin (); it != PafInfoVect.end (); it++)
416
+ uint8_t i;
417
+ uint8_t eSlotId = INVALID_PAF_SESSION_ID;
418
+ WiFiPAFSession * pPafSession = nullptr ;
419
+
420
+ // Check if the session has existed
421
+ for (i = 0 ; i < WIFIPAF_LAYER_NUM_PAF_ENDPOINTS; i++)
420
422
{
421
- if (it->id == id)
423
+ pPafSession = &mPafInfoVect [i];
424
+ switch (accType)
422
425
{
423
- PafInfoVect.erase (it);
424
- return ;
425
- }
426
+ case PafInfoAccess::kAccNodeInfo :
427
+ if (pPafSession->nodeId == SessionInfo.nodeId )
428
+ {
429
+ assert (pPafSession->discriminator == SessionInfo.discriminator );
430
+ // Already exist
431
+ return CHIP_NO_ERROR;
432
+ }
433
+ break ;
434
+ case PafInfoAccess::kAccSessionId :
435
+ if (pPafSession->id == SessionInfo.id )
436
+ {
437
+ // Already exist
438
+ return CHIP_NO_ERROR;
439
+ }
440
+ break ;
441
+ default :
442
+ return CHIP_ERROR_NOT_IMPLEMENTED;
443
+ };
444
+ if ((pPafSession->id == UINT32_MAX) && (pPafSession->nodeId == UINT32_MAX) && (pPafSession->discriminator == UINT16_MAX))
445
+ eSlotId = i;
426
446
}
427
- }
428
-
429
- WiFiPAFSession * WiFiPAFLayer::GetPAFInfo (NodeId nodeId)
430
- {
431
- for (WiFiPAFSession & PafInfoElm : PafInfoVect)
447
+ // Add the session if available
448
+ if (eSlotId != INVALID_PAF_SESSION_ID)
432
449
{
433
- if (PafInfoElm.nodeId == nodeId)
450
+ pPafSession = &mPafInfoVect [eSlotId];
451
+ switch (accType)
434
452
{
435
- return &PafInfoElm;
436
- }
453
+ case PafInfoAccess::kAccNodeInfo :
454
+ pPafSession->nodeId = SessionInfo.nodeId ;
455
+ pPafSession->discriminator = SessionInfo.discriminator ;
456
+ ChipLogProgress (WiFiPAF, " WiFiPAF: Add session with nodeId: %lu, disc: %x, sessions" , SessionInfo.nodeId ,
457
+ SessionInfo.discriminator );
458
+ return CHIP_NO_ERROR;
459
+ case PafInfoAccess::kAccSessionId :
460
+ pPafSession->id = SessionInfo.id ;
461
+ ChipLogProgress (WiFiPAF, " WiFiPAF: Add session with id: %u" , SessionInfo.id );
462
+ return CHIP_NO_ERROR;
463
+ default :
464
+ return CHIP_ERROR_NOT_IMPLEMENTED;
465
+ };
437
466
}
438
- return nullptr ;
467
+ ChipLogError (WiFiPAF, " WiFiPAF: No available space for the new sessions" );
468
+ return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
439
469
}
440
470
441
- WiFiPAFSession * WiFiPAFLayer::GetPAFInfo ( uint32_t id )
471
+ CHIP_ERROR WiFiPAFLayer::RmPafSession (PafInfoAccess accType, WiFiPAFSession & SessionInfo )
442
472
{
443
- for (WiFiPAFSession & PafInfoElm : PafInfoVect)
473
+ uint8_t i;
474
+ WiFiPAFSession * pPafSession;
475
+
476
+ for (i = 0 ; i < WIFIPAF_LAYER_NUM_PAF_ENDPOINTS; i++)
444
477
{
445
- if (PafInfoElm.id == id)
478
+ pPafSession = &mPafInfoVect [i];
479
+ switch (accType)
446
480
{
447
- return &PafInfoElm;
448
- }
481
+ case PafInfoAccess::kAccSessionId :
482
+ if (pPafSession->id == SessionInfo.id )
483
+ {
484
+ ChipLogProgress (WiFiPAF, " Removing session with id: %u" , pPafSession->id );
485
+ // Clear the slot
486
+ cleanPafInfo (*pPafSession);
487
+ return CHIP_NO_ERROR;
488
+ }
489
+ break ;
490
+ default :
491
+ return CHIP_ERROR_NOT_IMPLEMENTED;
492
+ };
449
493
}
450
- return nullptr ;
494
+ ChipLogError (WiFiPAF, " No PAF session found" );
495
+ return CHIP_ERROR_NOT_FOUND;
451
496
}
452
497
453
- WiFiPAFSession * WiFiPAFLayer::GetPAFInfo (uint16_t discriminator )
498
+ WiFiPAFSession * WiFiPAFLayer::GetPAFInfo (PafInfoAccess accType, WiFiPAFSession & SessionInfo )
454
499
{
455
- for (WiFiPAFSession & PafInfoElm : PafInfoVect)
500
+ uint8_t i;
501
+ WiFiPAFSession * pPafSession = nullptr ;
502
+
503
+ for (i = 0 ; i < WIFIPAF_LAYER_NUM_PAF_ENDPOINTS; i++)
456
504
{
457
- if (PafInfoElm.discriminator == discriminator)
505
+ pPafSession = &mPafInfoVect [i];
506
+ switch (accType)
458
507
{
459
- // Available session
460
- return &PafInfoElm;
461
- }
508
+ case PafInfoAccess::kAccSessionId :
509
+ if (pPafSession->id == SessionInfo.id )
510
+ {
511
+ return pPafSession;
512
+ }
513
+ break ;
514
+ case PafInfoAccess::kAccNodeId :
515
+ if (pPafSession->nodeId == SessionInfo.nodeId )
516
+ {
517
+ return pPafSession;
518
+ }
519
+ break ;
520
+ case PafInfoAccess::kAccDisc :
521
+ if (pPafSession->discriminator == SessionInfo.discriminator )
522
+ {
523
+ return pPafSession;
524
+ }
525
+ break ;
526
+ default :
527
+ return nullptr ;
528
+ };
462
529
}
530
+
463
531
return nullptr ;
464
532
}
465
-
466
533
} /* namespace WiFiPAF */
467
534
} /* namespace chip */
0 commit comments