Matter SDK Coverage Report
Current view: top level - wifipaf - WiFiPAFLayer.h (source / functions) Coverage Total Hit
Test: SHA:86e1daf06eb16a317f3cae3ccfe0d408f1f26696 Lines: 0.0 % 1 0
Test Date: 2025-04-03 07:08:25 Functions: 0.0 % 1 0

            Line data    Source code
       1              : /*
       2              :  *
       3              :  *    Copyright (c) 2025 Project CHIP Authors
       4              :  *
       5              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6              :  *    you may not use this file except in compliance with the License.
       7              :  *    You may obtain a copy of the License at
       8              :  *
       9              :  *        http://www.apache.org/licenses/LICENSE-2.0
      10              :  *
      11              :  *    Unless required by applicable law or agreed to in writing, software
      12              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14              :  *    See the License for the specific language governing permissions and
      15              :  *    limitations under the License.
      16              :  */
      17              : 
      18              : #pragma once
      19              : 
      20              : #include "WiFiPAFConfig.h"
      21              : #include "WiFiPAFEndPoint.h"
      22              : #include "WiFiPAFLayerDelegate.h"
      23              : #include "WiFiPAFRole.h"
      24              : #include <lib/core/CHIPError.h>
      25              : #include <lib/support/DLLUtil.h>
      26              : #include <system/SystemLayer.h>
      27              : #include <system/SystemPacketBuffer.h>
      28              : 
      29              : namespace chip {
      30              : namespace WiFiPAF {
      31              : 
      32              : /**
      33              :  *  @def NUM_PAFTP_SUPPORTED_PROTOCOL_VERSIONS
      34              :  *
      35              :  *  Number of unsigned 4-bit representations of supported transport protocol
      36              :  *  versions encapsulated in a BleTransportCapabilitiesRequest. Defined by CHIP
      37              :  *  over PAFTP protocol specification.
      38              :  */
      39              : #define NUM_PAFTP_SUPPORTED_PROTOCOL_VERSIONS 8
      40              : 
      41              : // Version(s) of the CHIP PAF Transport Protocol that this stack supports.
      42              : #define CHIP_PAF_TRANSPORT_PROTOCOL_MIN_SUPPORTED_VERSION kWiFiPAFTransportProtocolVersion_V1
      43              : #define CHIP_PAF_TRANSPORT_PROTOCOL_MAX_SUPPORTED_VERSION kWiFiPAFTransportProtocolVersion_V1
      44              : 
      45              : /// Enum defining versions of CHIP over PAF transport protocol.
      46              : typedef enum
      47              : {
      48              :     kWiFiPAFTransportProtocolVersion_None = 0,
      49              :     kWiFiPAFTransportProtocolVersion_V1   = 4 // PAFTP as defined by CHIP v1.5
      50              : } WiFiPAFTransportProtocolVersion;
      51              : 
      52              : inline constexpr size_t kCapabilitiesRequestMagicnumLength          = 2;
      53              : inline constexpr size_t kCapabilitiesRequestL2capMtuLength          = 2;
      54              : inline constexpr size_t kCapabilitiesRequestSupportedVersionsLength = 4;
      55              : inline constexpr size_t kCapabilitiesRequestWindowSizeLength        = 1;
      56              : constexpr size_t kCapabilitiesRequestLength = (kCapabilitiesRequestMagicnumLength + kCapabilitiesRequestL2capMtuLength +
      57              :                                                kCapabilitiesRequestSupportedVersionsLength + kCapabilitiesRequestWindowSizeLength);
      58              : 
      59              : inline constexpr size_t kCapabilitiesResponseMagicnumLength                = 2;
      60              : inline constexpr size_t kCapabilitiesResponseL2capMtuLength                = 2;
      61              : inline constexpr size_t kCapabilitiesResponseSelectedProtocolVersionLength = 1;
      62              : inline constexpr size_t kCapabilitiesResponseWindowSizeLength              = 1;
      63              : constexpr size_t kCapabilitiesResponseLength(kCapabilitiesResponseMagicnumLength + kCapabilitiesResponseL2capMtuLength +
      64              :                                              kCapabilitiesResponseSelectedProtocolVersionLength +
      65              :                                              kCapabilitiesResponseWindowSizeLength);
      66              : 
      67              : class PAFTransportCapabilitiesRequestMessage
      68              : {
      69              : public:
      70              :     /**
      71              :      * An array of size NUM_PAFTP_SUPPORTED_PROTOCOL_VERSIONS listing versions of the
      72              :      * PAF transport protocol that this node supports. Each protocol version is
      73              :      * specified as a 4-bit unsigned integer. A zero-value represents unused
      74              :      * array elements. Counting up from the zero-index, the first zero-value
      75              :      * specifies the end of the list of supported protocol versions.
      76              :      */
      77              :     uint8_t mSupportedProtocolVersions[(NUM_PAFTP_SUPPORTED_PROTOCOL_VERSIONS / 2) + (NUM_PAFTP_SUPPORTED_PROTOCOL_VERSIONS % 2)];
      78              : 
      79              :     /**
      80              :      *  The MTU that has been negotiated for this PAF connection. Specified in
      81              :      *  the PAFTransportCapabilitiesRequestMessage because the remote node may
      82              :      *  be unable to glean this info from its own PAF hardware/software stack
      83              :      *
      84              :      *  A value of 0 means that the central could not determine the negotiated
      85              :      *  PAF connection MTU.
      86              :      */
      87              :     uint16_t mMtu;
      88              : 
      89              :     /**
      90              :      *  The initial and maximum receive window size offered by the central
      91              :      */
      92              :     uint8_t mWindowSize;
      93              : 
      94              :     /**
      95              :      *  Set supported version value at given index in
      96              :      *  SupportedProtocolVersions. uint8_t version argument is truncated to 4
      97              :      *  least-significant bits. Index shall be 0 through number of
      98              :      *  SupportedProtocolVersions elements - 1.
      99              :      */
     100              :     void SetSupportedProtocolVersion(uint8_t index, uint8_t version);
     101              : 
     102              :     /// Must be able to reserve 20 byte data length in msgBuf.
     103              :     CHIP_ERROR Encode(const System::PacketBufferHandle & msgBuf) const;
     104              : 
     105              :     static CHIP_ERROR Decode(const System::PacketBufferHandle & msgBuf, PAFTransportCapabilitiesRequestMessage & msg);
     106              : };
     107              : 
     108              : class PAFTransportCapabilitiesResponseMessage
     109              : {
     110              : public:
     111              :     /**
     112              :      *  The lower 4 bits specify the PAF transport protocol version that the PAF
     113              :      *  peripheral has selected for this connection.
     114              :      *
     115              :      *  A value of kWiFiPAFTransportProtocolVersion_None means that no supported
     116              :      *  protocol version was found in the central's capabilities request. The
     117              :      *  central should unsubscribe after such a response has been sent to free
     118              :      *  up the peripheral for connections from devices with supported protocol
     119              :      *  versions.
     120              :      */
     121              :     uint8_t mSelectedProtocolVersion;
     122              : 
     123              :     /**
     124              :      *  PAF transport fragment size selected by peripheral in response to MTU
     125              :      *  value in PAFTransportCapabilitiesRequestMessage and its local
     126              :      *  observation of the PAF connection MTU.
     127              :      */
     128              :     uint16_t mFragmentSize;
     129              : 
     130              :     /**
     131              :      *  The initial and maximum receive window size offered by the peripheral
     132              :      */
     133              :     uint8_t mWindowSize;
     134              : 
     135              :     /// Must be able to reserve 20 byte data length in msgBuf.
     136              :     CHIP_ERROR Encode(const System::PacketBufferHandle & msgBuf) const;
     137              : 
     138              :     static CHIP_ERROR Decode(const System::PacketBufferHandle & msgBuf, PAFTransportCapabilitiesResponseMessage & msg);
     139              : };
     140              : 
     141              : /**
     142              :  *  The State of the Wi-Fi-PAF connection
     143              :  *
     144              :  */
     145              : enum class State
     146              : {
     147              :     kNotReady    = 0, /**< State before initialization. */
     148              :     kInitialized = 1, /**< State after class is connected and ready. */
     149              :     kConnected   = 2, /**< Endpoint connected. */
     150              : };
     151              : 
     152              : enum class PafInfoAccess
     153              : {
     154              :     kAccNodeInfo,
     155              :     kAccSessionId,
     156              :     kAccNodeId,
     157              :     kAccDisc,
     158              : };
     159              : 
     160              : class DLL_EXPORT WiFiPAFLayer
     161              : {
     162              :     friend class WiFiPAFEndPoint;
     163              :     friend class TestWiFiPAFLayer;
     164              : 
     165              : public:
     166              :     State mAppState                          = State::kNotReady;
     167              :     WiFiPAFLayerDelegate * mWiFiPAFTransport = nullptr;
     168              : 
     169              :     WiFiPAFLayer();
     170              :     static WiFiPAFLayer & GetWiFiPAFLayer();
     171              :     CHIP_ERROR Init(chip::System::Layer * systemLayer);
     172              : 
     173              :     typedef void (*OnCancelDeviceHandle)(uint32_t id, WiFiPAF::WiFiPafRole role);
     174              :     void Shutdown(OnCancelDeviceHandle OnCancelDevice);
     175              :     bool OnWiFiPAFMessageReceived(WiFiPAFSession & RxInfo, System::PacketBufferHandle && msg);
     176              :     CHIP_ERROR OnWiFiPAFMsgRxComplete(WiFiPAFSession & RxInfo, System::PacketBufferHandle && msg);
     177            0 :     State GetWiFiPAFState() { return mAppState; };
     178              :     void SetWiFiPAFState(State state);
     179              :     CHIP_ERROR SendMessage(WiFiPAF::WiFiPAFSession & TxInfo, chip::System::PacketBufferHandle && msg);
     180              :     CHIP_ERROR HandleWriteConfirmed(WiFiPAF::WiFiPAFSession & TxInfo, bool result);
     181              :     CHIP_ERROR NewEndPoint(WiFiPAFEndPoint ** retEndPoint, WiFiPAFSession & SessionInfo, WiFiPafRole role);
     182              :     typedef void (*OnSubscribeCompleteFunct)(void * appState);
     183              :     typedef void (*OnSubscribeErrorFunct)(void * appState, CHIP_ERROR err);
     184              :     CHIP_ERROR HandleTransportConnectionInitiated(WiFiPAF::WiFiPAFSession & SessionInfo,
     185              :                                                   OnSubscribeCompleteFunct OnSubscribeDoneFunc = nullptr, void * appState = nullptr,
     186              :                                                   OnSubscribeErrorFunct OnSubscribeErrFunc = nullptr);
     187              :     void OnEndPointConnectComplete(WiFiPAFEndPoint * endPoint, CHIP_ERROR err);
     188              : 
     189              :     static WiFiPAFTransportProtocolVersion
     190              :     GetHighestSupportedProtocolVersion(const PAFTransportCapabilitiesRequestMessage & reqMsg);
     191              : 
     192              :     CHIP_ERROR AddPafSession(PafInfoAccess accType, WiFiPAFSession & SessionInfo);
     193              :     CHIP_ERROR RmPafSession(PafInfoAccess accType, WiFiPAFSession & SessionInfo);
     194              :     WiFiPAFSession * GetPAFInfo(PafInfoAccess accType, WiFiPAFSession & SessionInfo);
     195              : 
     196              : private:
     197              :     void InitialPafInfo();
     198              :     void CleanPafInfo(WiFiPAFSession & SessionInfo);
     199              :     WiFiPAFSession mPafInfoVect[WIFIPAF_LAYER_NUM_PAF_ENDPOINTS];
     200              :     chip::System::Layer * mSystemLayer;
     201              : };
     202              : 
     203              : } /* namespace WiFiPAF */
     204              : } /* namespace chip */
        

Generated by: LCOV version 2.0-1