Skip to content

Commit

Permalink
Add to close PAF session while closing EndPoint module
Browse files Browse the repository at this point in the history
  • Loading branch information
crlonxp committed Feb 3, 2025
1 parent 8dc69c7 commit 4b80e86
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
30 changes: 19 additions & 11 deletions src/transport/raw/WiFiPAF.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,6 +30,7 @@
#include <transport/raw/WiFiPAF.h>

using namespace chip::System;
using namespace chip::WiFiPAF;

namespace chip {
namespace Transport {
Expand All @@ -38,7 +39,7 @@ CHIP_ERROR WiFiPAFBase::Init(const WiFiPAFListenParameters & param)
ChipLogDetail(Inet, "WiFiPAFBase::Init - setting/overriding transport");
mWiFiPAFLayer = DeviceLayer::ConnectivityMgr().GetWiFiPAF();
SetWiFiPAFLayerTransportToSelf();
mWiFiPAFLayer->SetWiFiPAFState(chip::WiFiPAF::State::kInitialized);
mWiFiPAFLayer->SetWiFiPAFState(State::kInitialized);

if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
{
Expand All @@ -65,12 +66,12 @@ CHIP_ERROR WiFiPAFBase::Init(const WiFiPAFListenParameters & param)
return CHIP_NO_ERROR;
}

CHIP_ERROR WiFiPAFBase::SendMessage(const Transport::PeerAddress & address, System::PacketBufferHandle && msgBuf)
CHIP_ERROR WiFiPAFBase::SendMessage(const Transport::PeerAddress & address, PacketBufferHandle && msgBuf)
{
VerifyOrReturnError(address.GetTransportType() == Type::kWiFiPAF, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(mWiFiPAFLayer->GetWiFiPAFState() != chip::WiFiPAF::State::kNotReady, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mWiFiPAFLayer->GetWiFiPAFState() != State::kNotReady, CHIP_ERROR_INCORRECT_STATE);

chip::WiFiPAF::WiFiPAFSession * pTxInfo = mWiFiPAFLayer->GetPAFInfo(address.GetRemoteId());
WiFiPAFSession * pTxInfo = mWiFiPAFLayer->GetPAFInfo(address.GetRemoteId());
if (pTxInfo == nullptr)
{
/*
Expand All @@ -88,13 +89,12 @@ bool WiFiPAFBase::CanSendToPeer(const Transport::PeerAddress & address)
{
if (mWiFiPAFLayer != nullptr)
{
return (mWiFiPAFLayer->GetWiFiPAFState() != chip::WiFiPAF::State::kNotReady) &&
(address.GetTransportType() == Type::kWiFiPAF);
return (mWiFiPAFLayer->GetWiFiPAFState() != State::kNotReady) && (address.GetTransportType() == Type::kWiFiPAF);
}
return false;
}

void WiFiPAFBase::OnWiFiPAFMessageReceived(chip::WiFiPAF::WiFiPAFSession & RxInfo, System::PacketBufferHandle && buffer)
void WiFiPAFBase::OnWiFiPAFMessageReceived(WiFiPAFSession & RxInfo, PacketBufferHandle && buffer)
{
auto pPafInfo = mWiFiPAFLayer->GetPAFInfo(RxInfo.id);
if (pPafInfo == nullptr)
Expand Down Expand Up @@ -124,15 +124,23 @@ void WiFiPAFBase::OnWiFiPAFMessageReceived(chip::WiFiPAF::WiFiPAFSession & RxInf
HandleMessageReceived(Transport::PeerAddress(Transport::Type::kWiFiPAF, pPafInfo->nodeId), std::move(buffer));
}

CHIP_ERROR WiFiPAFBase::WiFiPAFMessageSend(chip::WiFiPAF::WiFiPAFSession & TxInfo, System::PacketBufferHandle && msgBuf)
CHIP_ERROR WiFiPAFBase::WiFiPAFMessageSend(WiFiPAFSession & TxInfo, PacketBufferHandle && msgBuf)
{
VerifyOrReturnError(mWiFiPAFLayer->GetWiFiPAFState() != chip::WiFiPAF::State::kNotReady, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mWiFiPAFLayer->GetWiFiPAFState() != State::kNotReady, CHIP_ERROR_INCORRECT_STATE);
DeviceLayer::ConnectivityMgr().WiFiPAFSend(TxInfo, std::move(msgBuf));

return CHIP_NO_ERROR;
}

CHIP_ERROR WiFiPAFBase::SendAfterConnect(System::PacketBufferHandle && msg)
CHIP_ERROR WiFiPAFBase::WiFiPAFCloseSession(WiFiPAFSession & SessionInfo)
{
VerifyOrReturnError(mWiFiPAFLayer->GetWiFiPAFState() != State::kNotReady, CHIP_ERROR_INCORRECT_STATE);
DeviceLayer::ConnectivityMgr().WiFiPAFShutdown(SessionInfo.id, SessionInfo.role);

return CHIP_NO_ERROR;
}

CHIP_ERROR WiFiPAFBase::SendAfterConnect(PacketBufferHandle && msg)
{
CHIP_ERROR err = CHIP_ERROR_NO_MEMORY;

Expand Down
3 changes: 2 additions & 1 deletion src/transport/raw/WiFiPAF.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* Copyright (c) 2025 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -65,6 +65,7 @@ class DLL_EXPORT WiFiPAFBase : public Base, public WiFiPAF::WiFiPAFLayerDelegate
*/
void OnWiFiPAFMessageReceived(WiFiPAF::WiFiPAFSession & RxInfo, System::PacketBufferHandle && buffer) override;
CHIP_ERROR WiFiPAFMessageSend(WiFiPAF::WiFiPAFSession & TxInfo, System::PacketBufferHandle && msg) override;
CHIP_ERROR WiFiPAFCloseSession(WiFiPAF::WiFiPAFSession & SessionInfo) override;

private:
/**
Expand Down
5 changes: 5 additions & 0 deletions src/wifipaf/WiFiPAFEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ void WiFiPAFEndPoint::FinalizeClose(uint8_t oldState, uint8_t flags, CHIP_ERROR
// Ensure transmit queue is empty and set to NULL.
mSendQueue = nullptr;

// Clear the session information
ChipLogProgress(WiFiPAF, "Shutdown PAF session (%u, %u)", mSessionInfo.id, mSessionInfo.role);
mWiFiPafLayer->mWiFiPAFTransport->WiFiPAFCloseSession(mSessionInfo);
memset(&mSessionInfo, 0, sizeof(mSessionInfo));

// Fire application's close callback if we haven't already, and it's not suppressed.
if (oldState != kState_Closing && (flags & kWiFiPAFCloseFlag_SuppressCallback) == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/wifipaf/WiFiPAFLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ bool WiFiPAFLayer::OnWiFiPAFMessageReceived(WiFiPAFSession & RxInfo, System::Pac
{
WiFiPAFEndPoint * endPoint = sWiFiPAFEndPointPool.Find(reinterpret_cast<WIFIPAF_CONNECTION_OBJECT>(&RxInfo));
VerifyOrReturnError(endPoint != nullptr, false, ChipLogDetail(WiFiPAF, "No endpoint for received indication"));

RxInfo.role = endPoint->mSessionInfo.role;
CHIP_ERROR err = endPoint->Receive(std::move(msg));
VerifyOrReturnError(err == CHIP_NO_ERROR, false,
ChipLogError(WiFiPAF, "Receive failed, err = %" CHIP_ERROR_FORMAT, err.Format()));
Expand Down
1 change: 1 addition & 0 deletions src/wifipaf/WiFiPAFLayerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class WiFiPAFLayerDelegate
virtual ~WiFiPAFLayerDelegate() = default;
virtual void OnWiFiPAFMessageReceived(WiFiPAFSession & RxInfo, System::PacketBufferHandle && msg) = 0;
virtual CHIP_ERROR WiFiPAFMessageSend(WiFiPAFSession & TxInfo, System::PacketBufferHandle && msg) = 0;
virtual CHIP_ERROR WiFiPAFCloseSession(WiFiPAFSession & SessionInfo) = 0;
};

} // namespace WiFiPAF
Expand Down

0 comments on commit 4b80e86

Please sign in to comment.