@@ -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,144 @@ 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) &&
445
+ (pPafSession->discriminator == UINT16_MAX))
446
+ eSlotId = i;
426
447
}
427
- }
428
-
429
- WiFiPAFSession * WiFiPAFLayer::GetPAFInfo (NodeId nodeId)
430
- {
431
- for (WiFiPAFSession & PafInfoElm : PafInfoVect)
448
+ // Add the session if available
449
+ if (eSlotId != INVALID_PAF_SESSION_ID)
432
450
{
433
- if (PafInfoElm.nodeId == nodeId)
451
+ pPafSession = &mPafInfoVect [eSlotId];
452
+ switch (accType)
434
453
{
435
- return &PafInfoElm;
436
- }
454
+ case PafInfoAccess::kAccNodeInfo :
455
+ pPafSession->nodeId = SessionInfo.nodeId ;
456
+ pPafSession->discriminator = SessionInfo.discriminator ;
457
+ ChipLogProgress (WiFiPAF, " WiFiPAF: Add session with nodeId: %lu, disc: %x, sessions" ,
458
+ SessionInfo.nodeId , SessionInfo.discriminator );
459
+ return CHIP_NO_ERROR;
460
+ case PafInfoAccess::kAccSessionId :
461
+ pPafSession->id = SessionInfo.id ;
462
+ ChipLogProgress (WiFiPAF, " WiFiPAF: Add session with id: %u" , SessionInfo.id );
463
+ return CHIP_NO_ERROR;
464
+ default :
465
+ return CHIP_ERROR_NOT_IMPLEMENTED;
466
+ };
437
467
}
438
- return nullptr ;
468
+ ChipLogError (WiFiPAF, " WiFiPAF: No available space for the new sessions" );
469
+ return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
439
470
}
440
471
441
- WiFiPAFSession * WiFiPAFLayer::GetPAFInfo ( uint32_t id )
472
+ CHIP_ERROR WiFiPAFLayer::RmPafSession (PafInfoAccess accType, WiFiPAFSession &SessionInfo )
442
473
{
443
- for (WiFiPAFSession & PafInfoElm : PafInfoVect)
474
+ uint8_t i;
475
+ WiFiPAFSession *pPafSession;
476
+
477
+ for (i=0 ; i<WIFIPAF_LAYER_NUM_PAF_ENDPOINTS ; i++)
444
478
{
445
- if (PafInfoElm.id == id)
479
+ pPafSession = &mPafInfoVect [i];
480
+ switch (accType)
446
481
{
447
- return &PafInfoElm;
448
- }
482
+ case PafInfoAccess::kAccSessionId :
483
+ if (pPafSession->id == SessionInfo.id )
484
+ {
485
+ ChipLogProgress (WiFiPAF, " Removing session with id: %u" , pPafSession->id );
486
+ // Clear the slot
487
+ cleanPafInfo (*pPafSession);
488
+ return CHIP_NO_ERROR;
489
+ }
490
+ break ;
491
+ default :
492
+ return CHIP_ERROR_NOT_IMPLEMENTED;
493
+ };
449
494
}
450
- return nullptr ;
495
+ ChipLogError (WiFiPAF, " No PAF session found" );
496
+ return CHIP_ERROR_NOT_FOUND;
451
497
}
452
498
453
- WiFiPAFSession * WiFiPAFLayer::GetPAFInfo (uint16_t discriminator )
499
+ WiFiPAFSession * WiFiPAFLayer::GetPAFInfo (PafInfoAccess accType, WiFiPAFSession &SessionInfo )
454
500
{
455
- for (WiFiPAFSession & PafInfoElm : PafInfoVect)
501
+ uint8_t i;
502
+ WiFiPAFSession *pPafSession = nullptr ;
503
+
504
+ for (i=0 ; i<WIFIPAF_LAYER_NUM_PAF_ENDPOINTS ; i++)
456
505
{
457
- if (PafInfoElm.discriminator == discriminator)
506
+ pPafSession = &mPafInfoVect [i];
507
+ switch (accType)
458
508
{
459
- // Available session
460
- return &PafInfoElm;
461
- }
509
+ case PafInfoAccess::kAccSessionId :
510
+ if (pPafSession->id == SessionInfo.id )
511
+ {
512
+ return pPafSession;
513
+ }
514
+ break ;
515
+ case PafInfoAccess::kAccNodeId :
516
+ if (pPafSession->nodeId == SessionInfo.nodeId )
517
+ {
518
+ return pPafSession;
519
+ }
520
+ break ;
521
+ case PafInfoAccess::kAccDisc :
522
+ if (pPafSession->discriminator == SessionInfo.discriminator )
523
+ {
524
+ return pPafSession;
525
+ }
526
+ break ;
527
+ default :
528
+ return nullptr ;
529
+ };
462
530
}
531
+
463
532
return nullptr ;
464
533
}
465
-
466
534
} /* namespace WiFiPAF */
467
535
} /* namespace chip */
0 commit comments