Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2025 Project CHIP Authors
4 : * All rights reserved.
5 : *
6 : * Licensed under the Apache License, Version 2.0 (the "License");
7 : * you may not use this file except in compliance with the License.
8 : * You may obtain a copy of the License at
9 : *
10 : * http://www.apache.org/licenses/LICENSE-2.0
11 : *
12 : * Unless required by applicable law or agreed to in writing, software
13 : * distributed under the License is distributed on an "AS IS" BASIS,
14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : * See the License for the specific language governing permissions and
16 : * limitations under the License.
17 : */
18 :
19 : /**
20 : * @file
21 : * This file defines the Matter Connection object that maintains a Wi-Fi PAF connection.
22 : *
23 : */
24 :
25 : #pragma once
26 :
27 : #include <lib/core/CHIPCore.h>
28 : #include <lib/support/DLLUtil.h>
29 : #include <system/SystemPacketBuffer.h>
30 : #include <transport/raw/Base.h>
31 : #include <utility>
32 : #include <wifipaf/WiFiPAFLayer.h>
33 :
34 : namespace chip {
35 : namespace Transport {
36 : class WiFiPAFListenParameters;
37 :
38 : /**
39 : * Implements a transport using Wi-Fi-PAF
40 : */
41 : class DLL_EXPORT WiFiPAFBase : public Base, public WiFiPAF::WiFiPAFLayerDelegate
42 : {
43 : public:
44 6 : WiFiPAFBase() = default;
45 0 : WiFiPAFBase(System::PacketBufferHandle * packetBuffers, size_t packetBuffersSize) :
46 0 : mPendingPackets(packetBuffers), mPendingPacketsSize(packetBuffersSize)
47 0 : {}
48 6 : ~WiFiPAFBase() override {}
49 :
50 : /**
51 : * Initialize a Wi-Fi-PAF transport
52 : *
53 : * @param param Wi-Fi-PAF configuration parameters for this transport
54 : */
55 : CHIP_ERROR Init(const WiFiPAFListenParameters & param);
56 : bool CanSendToPeer(const Transport::PeerAddress & address) override;
57 1 : void SetWiFiPAFLayerTransportToSelf() { mWiFiPAFLayer->mWiFiPAFTransport = this; }
58 : bool IsWiFiPAFLayerTransportSetToSelf() { return mWiFiPAFLayer->mWiFiPAFTransport == this; }
59 : /**
60 : * Interface of Base
61 : */
62 : CHIP_ERROR SendMessage(const Transport::PeerAddress & address, System::PacketBufferHandle && msgBuf) override;
63 : /**
64 : * Interfaces of WiFiPAFLayerDelegate
65 : */
66 : CHIP_ERROR WiFiPAFMessageReceived(WiFiPAF::WiFiPAFSession & RxInfo, System::PacketBufferHandle && buffer) override;
67 : CHIP_ERROR WiFiPAFMessageSend(WiFiPAF::WiFiPAFSession & TxInfo, System::PacketBufferHandle && msg) override;
68 : CHIP_ERROR WiFiPAFCloseSession(WiFiPAF::WiFiPAFSession & SessionInfo) override;
69 : bool WiFiPAFResourceAvailable(void) override;
70 :
71 : private:
72 : /**
73 : * Sends the specified message once a connection has been established.
74 : * @param msg - what buffer to send once a connection has been established.
75 : */
76 : CHIP_ERROR SendAfterConnect(System::PacketBufferHandle && msg);
77 :
78 : WiFiPAF::WiFiPAFLayer * mWiFiPAFLayer = nullptr; ///< Associated wifipaf layer
79 :
80 : System::PacketBufferHandle * mPendingPackets;
81 : size_t mPendingPacketsSize;
82 : };
83 :
84 : template <size_t kPendingPacketSize>
85 : class WiFiPAF : public WiFiPAFBase
86 : {
87 : public:
88 0 : WiFiPAF() : WiFiPAFBase(mPendingPackets, kPendingPacketSize) {}
89 :
90 : private:
91 : System::PacketBufferHandle mPendingPackets[kPendingPacketSize];
92 : };
93 :
94 : /** Defines parameters for setting up the Wi-Fi PAF transport */
95 : class WiFiPAFListenParameters
96 : {
97 : public:
98 : WiFiPAFListenParameters() = default;
99 1 : explicit WiFiPAFListenParameters(WiFiPAFBase * layer) : mWiFiPAF(layer) {}
100 : WiFiPAFBase * GetWiFiPAFTransport() const { return mWiFiPAF; }
101 :
102 : private:
103 : WiFiPAFBase * mWiFiPAF;
104 : };
105 :
106 : } // namespace Transport
107 : } // namespace chip
|