diff --git a/src/wifipaf/BUILD.gn b/src/wifipaf/BUILD.gn new file mode 100644 index 00000000000000..ab56001a92d2b8 --- /dev/null +++ b/src/wifipaf/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2024 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") +import("${chip_root}/src/platform/device.gni") + +if (chip_device_config_enable_wifipaf) { + static_library("wifipaf") { + output_name = "libWiFiPAFLayer" + + sources = [ + "WiFiPAFLayerDelegate.h", + "WiFiPAFLayer.cpp", + "WiFiPAFLayer.h" + ] + + cflags = [ "-Wconversion" ] + + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + ] + } +} else { + group("wifipaf") { + } +} diff --git a/src/wifipaf/WiFiPAFLayer.cpp b/src/wifipaf/WiFiPAFLayer.cpp new file mode 100644 index 00000000000000..d5bd6c992a7d63 --- /dev/null +++ b/src/wifipaf/WiFiPAFLayer.cpp @@ -0,0 +1,50 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file implements objects which provide an abstraction layer between + * a platform's WiFiPAF implementation and the CHIP + * stack. + * + */ + +#include "WiFiPAFLayer.h" +namespace chip { +namespace WiFiPAF { + +void WiFiPAFLayer::OnWiFiPAFMessageReceived(System::PacketBufferHandle && msg) +{ + if (mWiFiPAFTransport != nullptr) { + mWiFiPAFTransport->OnWiFiPAFMessageReceived(std::move(msg)); + } +} + +void WiFiPAFLayer::SetWiFiPAFState(State state) +{ + mAppState = state; + return; +} + +static WiFiPAFLayer sInstance; +WiFiPAFLayer* WiFiPAFLayer::GetWiFiPAFLayer() +{ + return &sInstance; +} + +} /* namespace WiFiPAF */ +} /* namespace chip */ diff --git a/src/wifipaf/WiFiPAFLayer.h b/src/wifipaf/WiFiPAFLayer.h new file mode 100644 index 00000000000000..41e0dd976f4d03 --- /dev/null +++ b/src/wifipaf/WiFiPAFLayer.h @@ -0,0 +1,53 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include "WiFiPAFLayerDelegate.h" + +namespace chip { +namespace WiFiPAF { +/** +* 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. */ +}; + +class DLL_EXPORT WiFiPAFLayer +{ +public: + State mAppState = State::kNotReady; + WiFiPAFLayerDelegate * mWiFiPAFTransport = nullptr; + + WiFiPAFLayer() = default; + static WiFiPAFLayer* GetWiFiPAFLayer(); + + void OnWiFiPAFMessageReceived(System::PacketBufferHandle && msg); + State GetWiFiPAFState() { return mAppState; }; + void SetWiFiPAFState(State state); +}; + +} /* namespace WiFiPAF */ +} /* namespace chip */ diff --git a/src/wifipaf/WiFiPAFLayerDelegate.h b/src/wifipaf/WiFiPAFLayerDelegate.h new file mode 100644 index 00000000000000..6b91704035e73a --- /dev/null +++ b/src/wifipaf/WiFiPAFLayerDelegate.h @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file defines the interface for downcalls from WiFiPAFLayer + * to a WiFiPAF transport. + */ + +#pragma once + +#include + +namespace chip { +namespace WiFiPAF { + +class WiFiPAFLayerDelegate +{ +public: + virtual ~WiFiPAFLayerDelegate() = default; + virtual void OnWiFiPAFMessageReceived(System::PacketBufferHandle && msg) = 0; +}; + +} // namespace WiFiPAF +} // namespace chip