diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index ed228b51b2cb32..ca38d6427007ce 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -94,7 +94,13 @@ source_set("chip-all-clusters-common") { "${chip_root}/src/app/tests/suites/credentials:dac_provider", "${chip_root}/src/lib", "${chip_root}/third_party/jsoncpp", + "${chip_root}/src/wifipaf:wifipaf", ] + if (chip_device_config_enable_wifipaf) { + deps += [ + "${chip_root}/src/wifipaf:wifipaf", + ] + } include_dirs = [ "${chip_root}/examples/all-clusters-app/all-clusters-common/include", diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index 94e1eebbde7508..35b82786c6a987 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -135,6 +135,11 @@ executable("chip-tool") { ":chip-tool-utils", "${chip_root}/src/platform/logging:stdio", ] + if (chip_device_config_enable_wifipaf) { + deps += [ + "${chip_root}/src/wifipaf:wifipaf", + ] + } output_dir = root_out_dir } diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 22cd274ba87e39..4521b712654843 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -221,7 +221,7 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF , - Transport::WiFiPAFListenParameters(DeviceLayer::ConnectivityMgr().GetWiFiPAF()) + Transport::WiFiPAFListenParameters(static_cast(DeviceLayer::ConnectivityMgr().GetWiFiPAF()->mWiFiPAFTransport)) #endif ); diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 955e36bfb0d8a2..057fbcacd79834 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -469,13 +469,6 @@ DeviceCommissioner::DeviceCommissioner() : mDeviceNOCChainCallback(OnDeviceNOCChainGeneration, this), mSetUpCodePairer(this) {} -DeviceCommissioner::~DeviceCommissioner() -{ -#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - DeviceLayer::ConnectivityMgr().WiFiPAFCancelConnect(); -#endif -} - CHIP_ERROR DeviceCommissioner::Init(CommissionerInitParams params) { VerifyOrReturnError(params.operationalCredentialsDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -571,6 +564,9 @@ void DeviceCommissioner::Shutdown() mUdcServer = nullptr; } #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF + DeviceLayer::ConnectivityMgr().WiFiPAFCancelConnect(); +#endif // Release everything from the commissionee device pool here. // Make sure to use ReleaseCommissioneeDevice so we don't keep dangling @@ -743,6 +739,7 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF else if (params.GetPeerAddress().GetTransportType() == Transport::Type::kWiFiPAF) { + ConnectWiFiPAFTransportToSelf(); peerAddress = Transport::PeerAddress::WiFiPAF(remoteDeviceId); } #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF @@ -824,16 +821,16 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF if (params.GetPeerAddress().GetTransportType() == Transport::Type::kWiFiPAF) { - if (DeviceLayer::ConnectivityMgr().GetWiFiPAF()->GetWiFiPAFState() != Transport::WiFiPAFBase::State::kConnected) + if (DeviceLayer::ConnectivityMgr().GetWiFiPAF()->GetWiFiPAFState() != WiFiPAF::State::kConnected) { - ChipLogProgress(Controller, "WiFi-PAF: Subscribing the NAN-USD devices"); + ChipLogProgress(Controller, "WiFi-PAF: Subscribing to the NAN-USD devices"); if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted()) { - ChipLogError(Controller, "Wi-Fi Management should have be started now."); + ChipLogError(Controller, "Wi-Fi Management should have been started now."); ExitNow(CHIP_ERROR_INTERNAL); } mRendezvousParametersForDeviceDiscoveredOverWiFiPAF = params; - DeviceLayer::ConnectivityMgr().WiFiPAFConnect(params.GetSetupDiscriminator().value(), (void *) this, + DeviceLayer::ConnectivityMgr().WiFiPAFConnect(params.GetSetupDiscriminator().value(), reinterpret_cast(this), OnWiFiPAFSubscribeComplete, OnWiFiPAFSubscribeError); ExitNow(CHIP_NO_ERROR); } @@ -909,7 +906,7 @@ void DeviceCommissioner::OnDiscoveredDeviceOverBleError(void * appState, CHIP_ER #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF void DeviceCommissioner::OnWiFiPAFSubscribeComplete(void * appState) { - auto self = (DeviceCommissioner *) appState; + auto self = reinterpret_cast(appState); auto device = self->mDeviceInPASEEstablishment; if (nullptr != device && device->GetDeviceTransportType() == Transport::Type::kWiFiPAF) @@ -1823,6 +1820,17 @@ void DeviceCommissioner::CloseBleConnection() } #endif +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF +void DeviceCommissioner::ConnectWiFiPAFTransportToSelf() +{ + Transport::WiFiPAFBase & transport = std::get>(mSystemState->TransportMgr()->GetTransport().GetTransports()); + if (!transport.IsWiFiPAFLayerTransportSetToSelf()) + { + transport.SetWiFiPAFLayerTransportToSelf(); + } +} +#endif + CHIP_ERROR DeviceCommissioner::DiscoverCommissionableNodes(Dnssd::DiscoveryFilter filter) { ReturnErrorOnFailure(SetUpNodeDiscovery()); diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h index 4b876156199735..cf3900e5551e1c 100644 --- a/src/controller/CHIPDeviceController.h +++ b/src/controller/CHIPDeviceController.h @@ -468,7 +468,7 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, { public: DeviceCommissioner(); - ~DeviceCommissioner() override; + ~DeviceCommissioner() override {} #if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY // make this commissioner discoverable /** @@ -720,6 +720,10 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController, */ void CloseBleConnection(); #endif +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF + void ConnectWiFiPAFTransportToSelf(); +#endif + /** * @brief * Discover all devices advertising as commissionable. diff --git a/src/controller/CHIPDeviceControllerFactory.h b/src/controller/CHIPDeviceControllerFactory.h index 16e2ad487126b9..300b0508420cdf 100644 --- a/src/controller/CHIPDeviceControllerFactory.h +++ b/src/controller/CHIPDeviceControllerFactory.h @@ -146,7 +146,7 @@ struct FactoryInitParams Ble::BleLayer * bleLayer = nullptr; #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - Transport::WiFiPAFLayer * wifipaf_layer = nullptr; + WiFiPAF::WiFiPAFLayer * wifipaf_layer = nullptr; #endif // diff --git a/src/controller/CHIPDeviceControllerSystemState.h b/src/controller/CHIPDeviceControllerSystemState.h index e040ad14616431..27c8cc09eb8ae1 100644 --- a/src/controller/CHIPDeviceControllerSystemState.h +++ b/src/controller/CHIPDeviceControllerSystemState.h @@ -105,7 +105,7 @@ struct DeviceControllerSystemStateParams Ble::BleLayer * bleLayer = nullptr; #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - Transport::WiFiPAFLayer * wifipaf_layer = nullptr; + WiFiPAF::WiFiPAFLayer * wifipaf_layer = nullptr; #endif Credentials::GroupDataProvider * groupDataProvider = nullptr; Crypto::SessionKeystore * sessionKeystore = nullptr; diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index 99e991dfe8c114..94fa9b02ad4db1 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -60,13 +60,6 @@ CHIP_ERROR GetPayload(const char * setUpCode, SetupPayload & payload) } } // namespace -SetUpCodePairer::~SetUpCodePairer() -{ -#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - DeviceLayer::ConnectivityMgr().WiFiPAFCancelConnect(); -#endif -} - CHIP_ERROR SetUpCodePairer::PairDevice(NodeId remoteId, const char * setUpCode, SetupCodePairerBehaviour commission, DiscoveryType discoveryType, Optional resolutionData) { @@ -282,6 +275,9 @@ CHIP_ERROR SetUpCodePairer::StartDiscoverOverWiFiPAF(SetupPayload & payload) CHIP_ERROR SetUpCodePairer::StopConnectOverWiFiPAF() { mWaitingForDiscovery[kWiFiPAFTransport] = false; +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF + DeviceLayer::ConnectivityMgr().WiFiPAFCancelIncompleteConnect(); +#endif return CHIP_NO_ERROR; } @@ -397,13 +393,13 @@ void SetUpCodePairer::OnWifiPAFDiscoveryError(CHIP_ERROR err) void SetUpCodePairer::OnWiFiPAFSubscribeComplete(void * appState) { - auto self = (SetUpCodePairer *) appState; + auto self = reinterpret_cast(appState); self->OnDiscoveredDeviceOverWifiPAF(); } void SetUpCodePairer::OnWiFiPAFSubscribeError(void * appState, CHIP_ERROR err) { - auto self = (SetUpCodePairer *) appState; + auto self = reinterpret_cast(appState); self->OnWifiPAFDiscoveryError(err); } #endif diff --git a/src/controller/SetUpCodePairer.h b/src/controller/SetUpCodePairer.h index 3414341a2cdd51..fe679e5ea04b42 100644 --- a/src/controller/SetUpCodePairer.h +++ b/src/controller/SetUpCodePairer.h @@ -77,7 +77,7 @@ class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate { public: SetUpCodePairer(DeviceCommissioner * commissioner) : mCommissioner(commissioner) {} - ~SetUpCodePairer(); + virtual ~SetUpCodePairer() {} CHIP_ERROR PairDevice(chip::NodeId remoteId, const char * setUpCode, SetupCodePairerBehaviour connectionType = SetupCodePairerBehaviour::kCommission, diff --git a/src/include/platform/ConnectivityManager.h b/src/include/platform/ConnectivityManager.h index 209d7484b92bda..897c7907b56191 100644 --- a/src/include/platform/ConnectivityManager.h +++ b/src/include/platform/ConnectivityManager.h @@ -36,7 +36,7 @@ #include #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF -#include +#include #endif namespace chip { @@ -183,9 +183,9 @@ class ConnectivityManager CHIP_ERROR WiFiPAFConnect(const SetupDiscriminator & connDiscriminator, void * appState, OnConnectionCompleteFunct onSuccess, OnConnectionErrorFunct onError); CHIP_ERROR WiFiPAFCancelConnect(); + CHIP_ERROR WiFiPAFCancelIncompleteConnect(); CHIP_ERROR WiFiPAFSend(System::PacketBufferHandle && msgBuf); - Transport::WiFiPAFBase * GetWiFiPAF(); - void SetWiFiPAF(Transport::WiFiPAFBase * pmWiFiPAF); + WiFiPAF::WiFiPAFLayer * GetWiFiPAF(); #endif // WiFi AP methods @@ -450,6 +450,11 @@ inline CHIP_ERROR ConnectivityManager::WiFiPAFCancelConnect() return static_cast(this)->_WiFiPAFCancelConnect(); } +inline CHIP_ERROR ConnectivityManager::WiFiPAFCancelIncompleteConnect() +{ + return static_cast(this)->_WiFiPAFCancelIncompleteConnect(); +} + inline CHIP_ERROR ConnectivityManager::WiFiPAFSend(chip::System::PacketBufferHandle && msgBuf) { return static_cast(this)->_WiFiPAFSend(std::move(msgBuf)); @@ -501,15 +506,10 @@ inline void ConnectivityManager::ResetThreadNetworkDiagnosticsCounts() } #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF -inline Transport::WiFiPAFBase * ConnectivityManager::GetWiFiPAF() +inline WiFiPAF::WiFiPAFLayer * ConnectivityManager::GetWiFiPAF() { return static_cast(this)->_GetWiFiPAF(); } - -inline void ConnectivityManager::SetWiFiPAF(Transport::WiFiPAFBase * pWiFiPAF) -{ - return static_cast(this)->_SetWiFiPAF(pWiFiPAF); -} #endif inline Ble::BleLayer * ConnectivityManager::GetBleLayer() diff --git a/src/platform/Linux/BUILD.gn b/src/platform/Linux/BUILD.gn index 35b5047c9f4c00..ae0fd78735a762 100644 --- a/src/platform/Linux/BUILD.gn +++ b/src/platform/Linux/BUILD.gn @@ -154,6 +154,10 @@ static_library("Linux") { if (chip_enable_ble) { public_deps += [ "dbus/bluez" ] } + + if (chip_device_config_enable_wifipaf) { + public_deps += [ "${chip_root}/src/wifipaf:wifipaf" ] + } } source_set("logging") { diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp index 0ba16f90d874a9..92ef1a2fd72acf 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.cpp +++ b/src/platform/Linux/ConnectivityManagerImpl.cpp @@ -65,9 +65,6 @@ #include #include #include -#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF -#include -#endif #endif using namespace ::chip; @@ -146,6 +143,9 @@ CHIP_ERROR ConnectivityManagerImpl::_Init() ChipLogError(DeviceLayer, "Failed to reset WiFi statistic counts"); } #endif +#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF + pmWiFiPAF = WiFiPAF::WiFiPAFLayer::GetWiFiPAFLayer(); +#endif return CHIP_NO_ERROR; } @@ -912,16 +912,10 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiPAFAdvertisingEnabled(WiFiPAFAdverti } } -Transport::WiFiPAFBase * ConnectivityManagerImpl::_GetWiFiPAF() +WiFiPAF::WiFiPAFLayer * ConnectivityManagerImpl::_GetWiFiPAF() { return pmWiFiPAF; } - -void ConnectivityManagerImpl::_SetWiFiPAF(Transport::WiFiPAFBase * pWiFiPAF) -{ - pmWiFiPAF = pWiFiPAF; - return; -} #endif void ConnectivityManagerImpl::StartNonConcurrentWiFiManagement() @@ -1385,7 +1379,7 @@ void ConnectivityManagerImpl::OnDiscoveryResult(gboolean success, GVariant * dis ChipLogProgress(DeviceLayer, "WiFi-PAF: peer_addr: [%02x:%02x:%02x:%02x:%02x:%02x]", mpaf_info.peer_addr[0], mpaf_info.peer_addr[1], mpaf_info.peer_addr[2], mpaf_info.peer_addr[3], mpaf_info.peer_addr[4], mpaf_info.peer_addr[5]); - GetWiFiPAF()->SetWiFiPAFState(Transport::WiFiPAFBase::State::kConnected); + GetWiFiPAF()->SetWiFiPAFState(WiFiPAF::State::kConnected); // Read the ssi GAutoPtr ssiValue(g_variant_lookup_value(discov_info, "ssi", G_VARIANT_TYPE_BYTESTRING)); @@ -1398,7 +1392,7 @@ void ConnectivityManagerImpl::OnDiscoveryResult(gboolean success, GVariant * dis } else { - GetWiFiPAF()->SetWiFiPAFState(Transport::WiFiPAFBase::State::kInitialized); + GetWiFiPAF()->SetWiFiPAFState(WiFiPAF::State::kInitialized); if (mOnPafSubscribeError != nullptr) { mOnPafSubscribeError(mAppState, CHIP_ERROR_TIMEOUT); @@ -1526,6 +1520,15 @@ CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFCancelConnect() snprintf(args, sizeof(args), "subscribe_id=%d", mpresubscribe_id); wpa_fi_w1_wpa_supplicant1_interface_call_nancancel_subscribe_sync(mWpaSupplicant.iface, args, nullptr, &err.GetReceiver()); + mOnPafSubscribeComplete = nullptr; + mOnPafSubscribeError = nullptr; + return CHIP_NO_ERROR; +} + +CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFCancelIncompleteConnect() +{ + mOnPafSubscribeComplete = nullptr; + mOnPafSubscribeError = nullptr; return CHIP_NO_ERROR; } diff --git a/src/platform/Linux/ConnectivityManagerImpl.h b/src/platform/Linux/ConnectivityManagerImpl.h index 2025f228532961..bfd7fa11ff6f68 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.h +++ b/src/platform/Linux/ConnectivityManagerImpl.h @@ -49,7 +49,7 @@ #include #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF -#include +#include #endif #endif @@ -144,12 +144,12 @@ class ConnectivityManagerImpl final : public ConnectivityManager, CHIP_ERROR _WiFiPAFConnect(const SetupDiscriminator & connDiscriminator, void * appState, OnConnectionCompleteFunct onSuccess, OnConnectionErrorFunct onError); CHIP_ERROR _WiFiPAFCancelConnect(); + CHIP_ERROR _WiFiPAFCancelIncompleteConnect(); void OnDiscoveryResult(gboolean success, GVariant * obj); void OnNanReceive(GVariant * obj); void OnNanSubscribeTerminated(gint term_subscribe_id, gint reason); CHIP_ERROR _WiFiPAFSend(chip::System::PacketBufferHandle && msgBuf); - Transport::WiFiPAFBase * _GetWiFiPAF(); - void _SetWiFiPAF(Transport::WiFiPAFBase * pWiFiPAF); + WiFiPAF::WiFiPAFLayer * _GetWiFiPAF(); #endif void PostNetworkConnect(); @@ -250,7 +250,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager, OnConnectionCompleteFunct mOnPafSubscribeComplete; OnConnectionErrorFunct mOnPafSubscribeError; - Transport::WiFiPAFBase * pmWiFiPAF; + WiFiPAF::WiFiPAFLayer * pmWiFiPAF; void * mAppState; CHIP_ERROR _SetWiFiPAFAdvertisingEnabled(WiFiPAFAdvertiseParam & args); CHIP_ERROR _WiFiPAFPublish(WiFiPAFAdvertiseParam & args); diff --git a/src/platform/device.gni b/src/platform/device.gni index 87e2eb12e8d0d2..c969a9f76b5781 100644 --- a/src/platform/device.gni +++ b/src/platform/device.gni @@ -25,7 +25,7 @@ declare_args() { chip_fake_platform = false # Include wifi-paf to commission the device or not - chip_device_config_enable_wifipaf = false + chip_device_config_enable_wifipaf = current_os == "linux" } if (chip_device_platform == "auto") { diff --git a/src/transport/raw/WiFiPAF.cpp b/src/transport/raw/WiFiPAF.cpp index 97b465dd261e9b..751114769c4892 100644 --- a/src/transport/raw/WiFiPAF.cpp +++ b/src/transport/raw/WiFiPAF.cpp @@ -33,23 +33,12 @@ using namespace chip::System; namespace chip { namespace Transport { - -WiFiPAFBase::~WiFiPAFBase() -{ - ClearState(); -} - -void WiFiPAFBase::ClearState() -{ - mState = State::kNotReady; -} - CHIP_ERROR WiFiPAFBase::Init(const WiFiPAFListenParameters & param) { ChipLogDetail(Inet, "WiFiPAFBase::Init - setting/overriding transport"); - VerifyOrReturnError(mState == State::kNotReady, CHIP_ERROR_INCORRECT_STATE); - DeviceLayer::ConnectivityMgr().SetWiFiPAF(this); - mState = State::kInitialized; + mWiFiPAFLayer = DeviceLayer::ConnectivityMgr().GetWiFiPAF(); + SetWiFiPAFLayerTransportToSelf(); + mWiFiPAFLayer->SetWiFiPAFState(chip::WiFiPAF::State::kInitialized); if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted()) { @@ -80,12 +69,22 @@ CHIP_ERROR WiFiPAFBase::Init(const WiFiPAFListenParameters & param) CHIP_ERROR WiFiPAFBase::SendMessage(const Transport::PeerAddress & address, System::PacketBufferHandle && msgBuf) { ReturnErrorCodeIf(address.GetTransportType() != Type::kWiFiPAF, CHIP_ERROR_INVALID_ARGUMENT); - ReturnErrorCodeIf(mState == State::kNotReady, CHIP_ERROR_INCORRECT_STATE); + ReturnErrorCodeIf(mWiFiPAFLayer->GetWiFiPAFState() == chip::WiFiPAF::State::kNotReady, CHIP_ERROR_INCORRECT_STATE); DeviceLayer::ConnectivityMgr().WiFiPAFSend(std::move(msgBuf)); return CHIP_NO_ERROR; } +bool WiFiPAFBase::CanSendToPeer(const Transport::PeerAddress & address) +{ + if (mWiFiPAFLayer != nullptr) { + return (mWiFiPAFLayer->GetWiFiPAFState() != chip::WiFiPAF::State::kNotReady) && (address.GetTransportType() == Type::kWiFiPAF); + } else { + return false; + } +} + + void WiFiPAFBase::OnWiFiPAFMessageReceived(System::PacketBufferHandle && buffer) { HandleMessageReceived(Transport::PeerAddress(Transport::Type::kWiFiPAF), std::move(buffer)); diff --git a/src/transport/raw/WiFiPAF.h b/src/transport/raw/WiFiPAF.h index bd54d22cc3e26f..c3d03119ab2141 100644 --- a/src/transport/raw/WiFiPAF.h +++ b/src/transport/raw/WiFiPAF.h @@ -29,38 +29,23 @@ #include #include #include +#include "wifipaf/WiFiPAFLayer.h" namespace chip { namespace Transport { - -class WiFiPAFLayer -{ -public: - WiFiPAFLayer() = default; -}; class WiFiPAFListenParameters; /** * Implements a transport using Wi-Fi-PAF */ -class DLL_EXPORT WiFiPAFBase : public Base +class DLL_EXPORT WiFiPAFBase : public Base, public WiFiPAF::WiFiPAFLayerDelegate { public: - /** - * The State of the Wi-Fi-PAF connection - * - */ - enum class State - { - kNotReady = 0, /**< State before initialization. */ - kInitialized = 1, /**< State after class is connected and ready. */ - kConnected = 2, /**< Endpoint connected. */ - }; WiFiPAFBase() = default; WiFiPAFBase(System::PacketBufferHandle * packetBuffers, size_t packetBuffersSize) : mPendingPackets(packetBuffers), mPendingPacketsSize(packetBuffersSize) {} - ~WiFiPAFBase() override; + ~WiFiPAFBase() override {} /** * Initialize a Wi-Fi-PAF transport @@ -69,22 +54,20 @@ class DLL_EXPORT WiFiPAFBase : public Base */ CHIP_ERROR Init(const WiFiPAFListenParameters & param); CHIP_ERROR SendMessage(const Transport::PeerAddress & address, System::PacketBufferHandle && msgBuf) override; - bool CanSendToPeer(const Transport::PeerAddress & address) override - { - return (mState != State::kNotReady) && (address.GetTransportType() == Type::kWiFiPAF); - } + bool CanSendToPeer(const Transport::PeerAddress & address) override; void OnWiFiPAFMessageReceived(System::PacketBufferHandle && buffer); - void SetWiFiPAFState(State state) { mState = state; }; - State GetWiFiPAFState() { return mState; }; + void SetWiFiPAFLayerTransportToSelf() { mWiFiPAFLayer->mWiFiPAFTransport = this; } + bool IsWiFiPAFLayerTransportSetToSelf() { return mWiFiPAFLayer->mWiFiPAFTransport == this; } private: - void ClearState(); /** * Sends the specified message once a connection has been established. * @param msg - what buffer to send once a connection has been established. */ CHIP_ERROR SendAfterConnect(System::PacketBufferHandle && msg); - State mState = State::kNotReady; + + WiFiPAF::WiFiPAFLayer * mWiFiPAFLayer = nullptr; ///< Associated wifipaf layer + //WiFiPAF::WiFiPAFLayer::State mState = WiFiPAF::WiFiPAFLayer::State::kNotReady; System::PacketBufferHandle * mPendingPackets; size_t mPendingPacketsSize;