LCOV - code coverage report
Current view: top level - protocols/secure_channel - Constants.h (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 3 3 100.0 %
Date: 2024-02-15 08:20:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2020 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             :  *      The defines constants for the CHIP Secure Channel Protocol, present in
      22             :  *      every CHIP device.
      23             :  *
      24             :  */
      25             : 
      26             : #pragma once
      27             : 
      28             : #include <array>
      29             : #include <lib/support/CodeUtils.h>
      30             : #include <protocols/Protocols.h>
      31             : 
      32             : /**
      33             :  *   @namespace chip::Protocols::SecureChannel
      34             :  *
      35             :  *   @brief
      36             :  *     This namespace includes all interfaces within CHIP for the
      37             :  *     CHIP SecureChannel protocol.
      38             :  *
      39             :  *     The interfaces define message types and status codes.
      40             :  */
      41             : 
      42             : namespace chip {
      43             : namespace Protocols {
      44             : namespace SecureChannel {
      45             : 
      46             : inline constexpr char kProtocolName[] = "SecureChannel";
      47             : 
      48             : /**
      49             :  * SecureChannel Protocol Message Types
      50             :  */
      51             : enum class MsgType : uint8_t
      52             : {
      53             :     // Message Counter Synchronization Protocol Message Types
      54             :     MsgCounterSyncReq = 0x00,
      55             :     MsgCounterSyncRsp = 0x01,
      56             : 
      57             :     // Reliable Messaging Protocol Message Types
      58             :     StandaloneAck = 0x10,
      59             : 
      60             :     // Password-based session establishment Message Types
      61             :     PBKDFParamRequest  = 0x20,
      62             :     PBKDFParamResponse = 0x21,
      63             :     PASE_Pake1         = 0x22,
      64             :     PASE_Pake2         = 0x23,
      65             :     PASE_Pake3         = 0x24,
      66             : 
      67             :     // Certificate-based session establishment Message Types
      68             :     CASE_Sigma1       = 0x30,
      69             :     CASE_Sigma2       = 0x31,
      70             :     CASE_Sigma3       = 0x32,
      71             :     CASE_Sigma2Resume = 0x33,
      72             : 
      73             :     StatusReport = 0x40,
      74             : 
      75             :     ICD_CheckIn = 0x50,
      76             : };
      77             : 
      78             : // Placeholder value for the ProtocolCode field when the GeneralCode is Success or Continue.
      79             : inline constexpr uint16_t kProtocolCodeSuccess         = 0x0000;
      80             : inline constexpr uint16_t kProtocolCodeNoSharedRoot    = 0x0001;
      81             : inline constexpr uint16_t kProtocolCodeInvalidParam    = 0x0002;
      82             : inline constexpr uint16_t kProtocolCodeCloseSession    = 0x0003;
      83             : inline constexpr uint16_t kProtocolCodeBusy            = 0x0004;
      84             : inline constexpr uint16_t kProtocolCodeSessionNotFound = 0x0005;
      85             : 
      86             : // Placeholder value for the ProtocolCode field when there is no additional protocol-specific code to provide more information.
      87             : inline constexpr uint16_t kProtocolCodeGeneralFailure = 0xFFFF;
      88             : 
      89             : /**
      90             :  * Status Report - General Status Codes used to convey protocol-agnostic status info.
      91             :  */
      92             : enum class GeneralStatusCode : uint16_t
      93             : {
      94             :     kSuccess           = 0,  /**< Operation completed successfully. */
      95             :     kFailure           = 1,  /**< Generic failure, additional details may be included in the protocol specific status. */
      96             :     kBadPrecondition   = 2,  /**< Operation was rejected by the system because the system is in an invalid state. */
      97             :     kOutOfRange        = 3,  /**< A value was out of a required range. */
      98             :     kBadRequest        = 4,  /**< A request was unrecognized or malformed. */
      99             :     kUnsupported       = 5,  /**< An unrecognized or unsupported request was received. */
     100             :     kUnexpected        = 6,  /**< A request was not expected at this time. */
     101             :     kResourceExhausted = 7,  /**< Insufficient resources to process the given request. */
     102             :     kBusy              = 8,  /**< Device is busy and cannot handle this request at this time. */
     103             :     kTimeout           = 9,  /**< A timeout occurred. */
     104             :     kContinue          = 10, /**< Context-specific signal to proceed. */
     105             :     kAborted           = 11, /**< Failure, often due to a concurrency error. */
     106             :     kInvalidArgument   = 12, /**< An invalid/unsupported argument was provided. */
     107             :     kNotFound          = 13, /**< Some requested entity was not found. */
     108             :     kAlreadyExists     = 14, /**< The caller attempted to create something that already exists. */
     109             :     kPermissionDenied  = 15, /**< Caller does not have sufficient permissions to execute the requested operations. */
     110             :     kDataLoss          = 16, /**< Unrecoverable data loss or corruption has occurred. */
     111             : };
     112             : 
     113             : /**
     114             :  * Status Report - Status Codes specific only to the SecureChannel Protocol
     115             :  */
     116             : enum class StatusCode
     117             : {
     118             :     AlreadyMemberOfFabric = 1, /**< The recipient is already a member of a fabric. */
     119             :     NotMemberOfFabric     = 2, /**< The recipient is not a member of a fabric. */
     120             :     InvalidFabricConfig   = 3  /**< The specified fabric configuration was invalid. */
     121             : };
     122             : 
     123             : } // namespace SecureChannel
     124             : 
     125             : template <>
     126             : struct MessageTypeTraits<SecureChannel::MsgType>
     127             : {
     128       29997 :     static constexpr const Protocols::Id & ProtocolId() { return SecureChannel::Id; }
     129             : 
     130        6416 :     static auto GetTypeToNameTable()
     131             :     {
     132             :         static const std::array<MessageTypeNameLookup, 14> typeToNameTable = {
     133             :             {
     134             :                 { SecureChannel::MsgType::MsgCounterSyncReq, "MsgCounterSyncReq" },
     135             :                 { SecureChannel::MsgType::MsgCounterSyncRsp, "MsgCounterSyncRsp" },
     136             :                 { SecureChannel::MsgType::StandaloneAck, "StandaloneAck" },
     137             :                 { SecureChannel::MsgType::PBKDFParamRequest, "PBKDFParamRequest" },
     138             :                 { SecureChannel::MsgType::PBKDFParamResponse, "PBKDFParamResponse" },
     139             :                 { SecureChannel::MsgType::PASE_Pake1, "PASE_Pake1" },
     140             :                 { SecureChannel::MsgType::PASE_Pake2, "PASE_Pake2" },
     141             :                 { SecureChannel::MsgType::PASE_Pake3, "PASE_Pake3" },
     142             :                 { SecureChannel::MsgType::CASE_Sigma1, "CASE_Sigma1" },
     143             :                 { SecureChannel::MsgType::CASE_Sigma2, "CASE_Sigma2" },
     144             :                 { SecureChannel::MsgType::CASE_Sigma3, "CASE_Sigma3" },
     145             :                 { SecureChannel::MsgType::CASE_Sigma2Resume, "CASE_Sigma2Resume" },
     146             :                 { SecureChannel::MsgType::StatusReport, "StatusReport" },
     147             :                 { SecureChannel::MsgType::ICD_CheckIn, "ICD_CheckInMessage" },
     148             :             },
     149             :         };
     150             : 
     151        6416 :         return &typeToNameTable;
     152             :     }
     153             : };
     154             : 
     155             : } // namespace Protocols
     156             : } // namespace chip

Generated by: LCOV version 1.14