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 :
85 : // Placeholder value for the ProtocolCode field when there is no additional protocol-specific code to provide more information.
86 : inline constexpr uint16_t kProtocolCodeGeneralFailure = 0xFFFF;
87 :
88 : /**
89 : * Status Report - General Status Codes used to convey protocol-agnostic status info.
90 : */
91 : enum class GeneralStatusCode : uint16_t
92 : {
93 : kSuccess = 0, /**< Operation completed successfully. */
94 : kFailure = 1, /**< Generic failure, additional details may be included in the protocol specific status. */
95 : kBadPrecondition = 2, /**< Operation was rejected by the system because the system is in an invalid state. */
96 : kOutOfRange = 3, /**< A value was out of a required range. */
97 : kBadRequest = 4, /**< A request was unrecognized or malformed. */
98 : kUnsupported = 5, /**< An unrecognized or unsupported request was received. */
99 : kUnexpected = 6, /**< A request was not expected at this time. */
100 : kResourceExhausted = 7, /**< Insufficient resources to process the given request. */
101 : kBusy = 8, /**< Device is busy and cannot handle this request at this time. */
102 : kTimeout = 9, /**< A timeout occurred. */
103 : kContinue = 10, /**< Context-specific signal to proceed. */
104 : kAborted = 11, /**< Failure, often due to a concurrency error. */
105 : kInvalidArgument = 12, /**< An invalid/unsupported argument was provided. */
106 : kNotFound = 13, /**< Some requested entity was not found. */
107 : kAlreadyExists = 14, /**< The caller attempted to create something that already exists. */
108 : kPermissionDenied = 15, /**< Caller does not have sufficient permissions to execute the requested operations. */
109 : kDataLoss = 16, /**< Unrecoverable data loss or corruption has occurred. */
110 : };
111 :
112 : /**
113 : * Status Report - Status Codes specific only to the SecureChannel Protocol
114 : */
115 : enum class StatusCode
116 : {
117 : AlreadyMemberOfFabric = 1, /**< The recipient is already a member of a fabric. */
118 : NotMemberOfFabric = 2, /**< The recipient is not a member of a fabric. */
119 : InvalidFabricConfig = 3 /**< The specified fabric configuration was invalid. */
120 : };
121 :
122 : } // namespace SecureChannel
123 :
124 : template <>
125 : struct MessageTypeTraits<SecureChannel::MsgType>
126 : {
127 48727 : static constexpr const Protocols::Id & ProtocolId() { return SecureChannel::Id; }
128 :
129 9420 : static auto GetTypeToNameTable()
130 : {
131 : static const std::array<MessageTypeNameLookup, 14> typeToNameTable = {
132 : {
133 : { SecureChannel::MsgType::MsgCounterSyncReq, "MsgCounterSyncReq" },
134 : { SecureChannel::MsgType::MsgCounterSyncRsp, "MsgCounterSyncRsp" },
135 : { SecureChannel::MsgType::StandaloneAck, "StandaloneAck" },
136 : { SecureChannel::MsgType::PBKDFParamRequest, "PBKDFParamRequest" },
137 : { SecureChannel::MsgType::PBKDFParamResponse, "PBKDFParamResponse" },
138 : { SecureChannel::MsgType::PASE_Pake1, "PASE_Pake1" },
139 : { SecureChannel::MsgType::PASE_Pake2, "PASE_Pake2" },
140 : { SecureChannel::MsgType::PASE_Pake3, "PASE_Pake3" },
141 : { SecureChannel::MsgType::CASE_Sigma1, "CASE_Sigma1" },
142 : { SecureChannel::MsgType::CASE_Sigma2, "CASE_Sigma2" },
143 : { SecureChannel::MsgType::CASE_Sigma3, "CASE_Sigma3" },
144 : { SecureChannel::MsgType::CASE_Sigma2Resume, "CASE_Sigma2Resume" },
145 : { SecureChannel::MsgType::StatusReport, "StatusReport" },
146 : { SecureChannel::MsgType::ICD_CheckIn, "ICD_CheckInMessage" },
147 : },
148 : };
149 :
150 9420 : return &typeToNameTable;
151 : }
152 : };
153 :
154 : } // namespace Protocols
155 : } // namespace chip
|