LCOV - code coverage report
Current view: top level - protocols/secure_channel - RendezvousParameters.h (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 0 33 0.0 %
Date: 2024-02-15 08:20:41 Functions: 0 17 0.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2020 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 <transport/raw/Base.h>
      21             : #include <transport/raw/PeerAddress.h>
      22             : #if CONFIG_NETWORK_LAYER_BLE
      23             : #include <ble/Ble.h>
      24             : #endif // CONFIG_NETWORK_LAYER_BLE
      25             : 
      26             : #include <lib/support/logging/CHIPLogging.h>
      27             : #include <messaging/ReliableMessageProtocolConfig.h>
      28             : #include <protocols/secure_channel/PASESession.h>
      29             : 
      30             : namespace chip {
      31             : 
      32             : // The largest supported value for Rendezvous discriminators
      33             : const uint16_t kMaxRendezvousDiscriminatorValue = 0xFFF;
      34             : 
      35             : // The largest supported value for session idle interval and session active interval
      36             : inline constexpr uint32_t kMaxSessionIdleInterval = 3600000;
      37             : 
      38             : class RendezvousParameters
      39             : {
      40             : public:
      41           0 :     RendezvousParameters() = default;
      42             : 
      43             :     bool HasSetupPINCode() const { return mSetupPINCode != 0; }
      44           0 :     uint32_t GetSetupPINCode() const { return mSetupPINCode; }
      45           0 :     RendezvousParameters & SetSetupPINCode(uint32_t setupPINCode)
      46             :     {
      47           0 :         mSetupPINCode = setupPINCode;
      48           0 :         return *this;
      49             :     }
      50             : 
      51             :     bool HasPeerAddress() const { return mPeerAddress.IsInitialized(); }
      52           0 :     Transport::PeerAddress GetPeerAddress() const { return mPeerAddress; }
      53           0 :     RendezvousParameters & SetPeerAddress(const Transport::PeerAddress & peerAddress)
      54             :     {
      55           0 :         mPeerAddress = peerAddress;
      56           0 :         return *this;
      57             :     }
      58             : 
      59             :     // Discriminators in RendezvousParameters are always long (12-bit)
      60             :     // discriminators.
      61           0 :     bool HasDiscriminator() const { return mDiscriminator <= kMaxRendezvousDiscriminatorValue; }
      62           0 :     uint16_t GetDiscriminator() const { return mDiscriminator; }
      63             :     RendezvousParameters & SetDiscriminator(uint16_t discriminator)
      64             :     {
      65             :         mDiscriminator = discriminator;
      66             :         return *this;
      67             :     }
      68             : 
      69             :     bool HasPASEVerifier() const { return mHasPASEVerifier; }
      70             :     const Spake2pVerifier & GetPASEVerifier() const { return mPASEVerifier; }
      71             :     RendezvousParameters & SetPASEVerifier(Spake2pVerifier & verifier)
      72             :     {
      73             :         memmove(&mPASEVerifier, &verifier, sizeof(verifier));
      74             :         mHasPASEVerifier = true;
      75             :         return *this;
      76             :     }
      77             : 
      78             : #if CONFIG_NETWORK_LAYER_BLE
      79           0 :     bool HasBleLayer() const { return mBleLayer != nullptr; }
      80             :     Ble::BleLayer * GetBleLayer() const { return mBleLayer; }
      81             :     RendezvousParameters & SetBleLayer(Ble::BleLayer * value)
      82             :     {
      83             :         mBleLayer = value;
      84             :         return *this;
      85             :     }
      86             : 
      87           0 :     bool HasConnectionObject() const { return mConnectionObject != BLE_CONNECTION_UNINITIALIZED; }
      88           0 :     BLE_CONNECTION_OBJECT GetConnectionObject() const { return mConnectionObject; }
      89           0 :     RendezvousParameters & SetConnectionObject(BLE_CONNECTION_OBJECT connObj)
      90             :     {
      91           0 :         mConnectionObject = connObj;
      92           0 :         return *this;
      93             :     }
      94             : 
      95           0 :     bool HasDiscoveredObject() const { return mDiscoveredObject != BLE_CONNECTION_UNINITIALIZED; }
      96           0 :     BLE_CONNECTION_OBJECT GetDiscoveredObject() const { return mDiscoveredObject; }
      97           0 :     RendezvousParameters & SetDiscoveredObject(BLE_CONNECTION_OBJECT connObj)
      98             :     {
      99           0 :         mDiscoveredObject = connObj;
     100           0 :         return *this;
     101             :     }
     102             : #else
     103             :     bool HasConnectionObject() const { return false; }
     104             :     bool HasDiscoveredObject() const { return false; }
     105             : #endif // CONFIG_NETWORK_LAYER_BLE
     106             : 
     107             :     bool HasMRPConfig() const { return mMRPConfig.HasValue(); }
     108           0 :     ReliableMessageProtocolConfig GetMRPConfig() const { return mMRPConfig.ValueOr(GetDefaultMRPConfig()); }
     109           0 :     RendezvousParameters & SetIdleInterval(System::Clock::Milliseconds32 interval)
     110             :     {
     111           0 :         if (!mMRPConfig.HasValue())
     112             :         {
     113           0 :             mMRPConfig.Emplace(GetDefaultMRPConfig());
     114             :         }
     115           0 :         mMRPConfig.Value().mIdleRetransTimeout = interval;
     116           0 :         return *this;
     117             :     }
     118             : 
     119           0 :     RendezvousParameters & SetActiveInterval(System::Clock::Milliseconds32 interval)
     120             :     {
     121           0 :         if (!mMRPConfig.HasValue())
     122             :         {
     123           0 :             mMRPConfig.Emplace(GetDefaultMRPConfig());
     124             :         }
     125           0 :         mMRPConfig.Value().mActiveRetransTimeout = interval;
     126           0 :         return *this;
     127             :     }
     128             : 
     129             : private:
     130             :     Transport::PeerAddress mPeerAddress;  ///< the peer node address
     131             :     uint32_t mSetupPINCode  = 0;          ///< the target peripheral setup PIN Code
     132             :     uint16_t mDiscriminator = UINT16_MAX; ///< the target peripheral discriminator
     133             : 
     134             :     Spake2pVerifier mPASEVerifier;
     135             :     bool mHasPASEVerifier = false;
     136             : 
     137             :     Optional<ReliableMessageProtocolConfig> mMRPConfig;
     138             : 
     139             : #if CONFIG_NETWORK_LAYER_BLE
     140             :     Ble::BleLayer * mBleLayer               = nullptr;
     141             :     BLE_CONNECTION_OBJECT mConnectionObject = BLE_CONNECTION_UNINITIALIZED;
     142             :     BLE_CONNECTION_OBJECT mDiscoveredObject = BLE_CONNECTION_UNINITIALIZED;
     143             : #endif // CONFIG_NETWORK_LAYER_BLE
     144             : };
     145             : 
     146             : } // namespace chip

Generated by: LCOV version 1.14