Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / protocols / secure_channel / Constants.h
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 <protocols/Protocols.h>
29 #include <support/CodeUtils.h>
30
31 /**
32  *   @namespace chip::Protocols::SecureChannel
33  *
34  *   @brief
35  *     This namespace includes all interfaces within CHIP for the
36  *     CHIP SecureChannel protocol.
37  *
38  *     The interfaces define message types and status codes.
39  */
40
41 namespace chip {
42 namespace Protocols {
43 namespace SecureChannel {
44
45 /**
46  * SecureChannel Protocol Message Types
47  */
48 enum class MsgType : uint8_t
49 {
50     // Message Counter Synchronization Protocol Message Types
51     MsgCounterSyncReq = 0x00,
52     MsgCounterSyncRsp = 0x01,
53
54     // Reliable Messaging Protocol Message Types
55     StandaloneAck = 0x10,
56
57     // Password-based session establishment Message Types
58     PBKDFParamRequest  = 0x20,
59     PBKDFParamResponse = 0x21,
60     PASE_Spake2p1      = 0x22,
61     PASE_Spake2p2      = 0x23,
62     PASE_Spake2p3      = 0x24,
63     PASE_Spake2pError  = 0x2F,
64
65     // Certificate-based session establishment Message Types
66     CASE_SigmaR1  = 0x30,
67     CASE_SigmaR2  = 0x31,
68     CASE_SigmaR3  = 0x32,
69     CASE_SigmaErr = 0x3F,
70
71     StatusReport = 0x40,
72 };
73
74 // Placeholder value for the ProtocolCode field when the GeneralCode is Success or Continue.
75 constexpr uint16_t kProtocolCodeSuccess = 0x0000;
76
77 // Placeholder value for the ProtocolCode field when there is no additional protocol-specific code to provide more information.
78 constexpr uint16_t kProtocolCodeGeneralFailure = 0xFFFF;
79
80 /**
81  * Status Report - General Status Codes used to convey protocol-agnostic status info.
82  */
83 enum class GeneralStatusCode : uint16_t
84 {
85     kSuccess           = 0,  /**< Operation completed successfully. */
86     kFailure           = 1,  /**< Generic failure, additional details may be included in the protocol specific status. */
87     kBadPrecondition   = 2,  /**< Operation was rejected by the system because the system is in an invalid state. */
88     kOutOfRange        = 3,  /**< A value was out of a required range. */
89     kBadRequest        = 4,  /**< A request was unrecognized or malformed. */
90     kUnsupported       = 5,  /**< An unrecognized or unsupported request was received. */
91     kUnexpected        = 6,  /**< A request was not expected at this time. */
92     kResourceExhausted = 7,  /**< Insufficient resources to process the given request. */
93     kBusy              = 8,  /**< Device is busy and cannot handle this request at this time. */
94     kTimeout           = 9,  /**< A timeout occurred. */
95     kContinue          = 10, /**< Context-specific signal to proceed. */
96     kAborted           = 11, /**< Failure, often due to a concurrency error. */
97     kInvalidArgument   = 12, /**< An invalid/unsupported argument was provided. */
98     kNotFound          = 13, /**< Some requested entity was not found. */
99     kAlreadyExists     = 14, /**< The caller attempted to create something that already exists. */
100     kPermissionDenied  = 15, /**< Caller does not have sufficient permissions to execute the requested operations. */
101     kDataLoss          = 16, /**< Unrecoverable data loss or corruption has occurred. */
102 };
103
104 /**
105  * Status Report - Status Codes specific only to the SecureChannel Protocol
106  */
107 enum class StatusCode
108 {
109     AlreadyMemberOfFabric = 1, /**< The recipient is already a member of a fabric. */
110     NotMemberOfFabric     = 2, /**< The recipient is not a member of a fabric. */
111     InvalidFabricConfig   = 3  /**< The specified fabric configuration was invalid. */
112 };
113
114 } // namespace SecureChannel
115
116 template <>
117 struct MessageTypeTraits<SecureChannel::MsgType>
118 {
119     static constexpr const Protocols::Id & ProtocolId() { return SecureChannel::Id; }
120 };
121
122 } // namespace Protocols
123 } // namespace chip