LCOV - code coverage report
Current view: top level - lib/core - NodeId.h (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 12 16 75.0 %
Date: 2024-02-15 08:20:41 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2021 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 <lib/core/GroupId.h>
      21             : #include <lib/core/PasscodeId.h>
      22             : 
      23             : #include <cstdint>
      24             : 
      25             : namespace chip {
      26             : 
      27             : // TODO: Consider making this a class and the various utility methods static
      28             : // methods.
      29             : using NodeId = uint64_t;
      30             : 
      31             : inline constexpr NodeId kUndefinedNodeId = 0ULL;
      32             : 
      33             : // The range of possible NodeId values has some pieces carved out for special
      34             : // uses.
      35             : inline constexpr NodeId kMinGroupNodeId = 0xFFFF'FFFF'FFFF'0000ULL;
      36             : // The max group id is complicated, depending on how we want to count the
      37             : // various special group ids.  Let's not define it for now, until we have use
      38             : // cases.
      39             : inline constexpr NodeId kMaskGroupId = 0x0000'0000'0000'FFFFULL;
      40             : 
      41             : inline constexpr NodeId kMinTemporaryLocalId = 0xFFFF'FFFE'0000'0000ULL;
      42             : // We use the largest available temporary local id to represent
      43             : // kPlaceholderNodeId, so the range is narrowed compared to the spec.
      44             : inline constexpr NodeId kMaxTemporaryLocalId = 0xFFFF'FFFE'FFFF'FFFEULL;
      45             : inline constexpr NodeId kPlaceholderNodeId   = 0xFFFF'FFFE'FFFF'FFFFULL;
      46             : 
      47             : inline constexpr NodeId kMinCASEAuthTag  = 0xFFFF'FFFD'0000'0000ULL;
      48             : inline constexpr NodeId kMaxCASEAuthTag  = 0xFFFF'FFFD'FFFF'FFFFULL;
      49             : inline constexpr NodeId kMaskCASEAuthTag = 0x0000'0000'FFFF'FFFFULL;
      50             : 
      51             : inline constexpr NodeId kMinPAKEKeyId        = 0xFFFF'FFFB'0000'0000ULL;
      52             : inline constexpr NodeId kMaxPAKEKeyId        = 0xFFFF'FFFB'FFFF'FFFFULL;
      53             : inline constexpr NodeId kMaskPAKEKeyId       = 0x0000'0000'0000'FFFFULL;
      54             : inline constexpr NodeId kMaskUnusedPAKEKeyId = 0x0000'0000'FFFF'0000ULL;
      55             : 
      56             : // There are more reserved ranges here, not assigned to anything yet, going down
      57             : // all the way to 0xFFFF'FFF0'0000'0000ULL
      58             : 
      59             : inline constexpr NodeId kMaxOperationalNodeId = 0xFFFF'FFEF'FFFF'FFFFULL;
      60             : 
      61       83504 : constexpr bool IsOperationalNodeId(NodeId aNodeId)
      62             : {
      63       83504 :     return (aNodeId != kUndefinedNodeId) && (aNodeId <= kMaxOperationalNodeId);
      64             : }
      65             : 
      66         293 : constexpr bool IsGroupId(NodeId aNodeId)
      67             : {
      68         293 :     return (aNodeId >= kMinGroupNodeId);
      69             : }
      70             : 
      71         582 : constexpr bool IsCASEAuthTag(NodeId aNodeId)
      72             : {
      73         582 :     return (aNodeId >= kMinCASEAuthTag) && (aNodeId <= kMaxCASEAuthTag);
      74             : }
      75             : 
      76           0 : constexpr bool IsPAKEKeyId(NodeId aNodeId)
      77             : {
      78           0 :     return (aNodeId >= kMinPAKEKeyId) && (aNodeId <= kMaxPAKEKeyId);
      79             : }
      80             : 
      81           1 : constexpr NodeId NodeIdFromGroupId(GroupId aGroupId)
      82             : {
      83           1 :     return kMinGroupNodeId | aGroupId;
      84             : }
      85             : 
      86          90 : constexpr GroupId GroupIdFromNodeId(NodeId aNodeId)
      87             : {
      88          90 :     return aNodeId & kMaskGroupId;
      89             : }
      90             : 
      91          40 : constexpr NodeId NodeIdFromPAKEKeyId(PasscodeId aPAKEKeyId)
      92             : {
      93          40 :     return kMinPAKEKeyId | aPAKEKeyId;
      94             : }
      95             : 
      96           0 : constexpr PasscodeId PAKEKeyIdFromNodeId(NodeId aNodeId)
      97             : {
      98           0 :     return aNodeId & kMaskPAKEKeyId;
      99             : }
     100             : 
     101             : } // namespace chip

Generated by: LCOV version 1.14