Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / protocols / secure_channel / StatusReport.h
1 /*
2  *
3  *    Copyright (c) 2021 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 #pragma once
20
21 #include <support/BufferWriter.h>
22 #include <system/SystemPacketBuffer.h>
23
24 namespace chip {
25 namespace Protocols {
26 namespace SecureChannel {
27
28 /**
29  *  Encapsulates the data included in a StatusReport message, and provides methods for writing to and reading from PacketBuffers
30  *  that contain StatusReport messages.
31  */
32 class DLL_EXPORT StatusReport
33 {
34 public:
35     /**
36      *  Construct a StatusReport with zero-d out fields (for use before calling \c Parse() ).
37      */
38     StatusReport();
39
40     /**
41      *  Construct a StatusReport with no additional ProtocolData.
42      *
43      *  @param generalCode Required, one of the \c GeneralStatusCode values listed in \c secure_channel/Constants.h
44      *  @param protocolId Must specify a ProtocolId which consists of Vendor Id (upper 16 bits) and ProtocolId (lower 16 bits)
45      *  @param protocolCode A code defined by the specified protocol which provides more information about the status
46      */
47     StatusReport(GeneralStatusCode generalCode, uint32_t protocolId, uint16_t protocolCode);
48
49     //
50     /**
51      *  Construct a StatusReport with additional ProtocolData.
52      *
53      *  @param generalCode Must specify a GeneralCode (see \c GeneralStatusCode )
54      *  @param protocolId Must specify a ProtocolId which consists of Vendor Id (upper 16 bits) and ProtocolId (lower 16 bits)
55      *  @param protocolCode A code defined by the specified protocol which provides more information about the status
56      *  @param protocolData A \c PacketBufferHandle containing the protocol-specific data
57      */
58     StatusReport(GeneralStatusCode generalCode, uint32_t protocolId, uint16_t protocolCode,
59                  System::PacketBufferHandle protocolData);
60
61     /**
62      *  Read the contents of a \c PacketBuffer containing a StatusReport message and store the field values in this object.
63      *
64      *  @note If there is additional data after the Protocol Code field in the message, it is assumed to be protocol-specific data.
65      *
66      *  @note This method assumes that the Header of the message has already been consumed, and that \c PacketBuffer::Start() points
67      *  to the beginning of the StatusReport data.
68      *
69      *  @param[in] buf A \c PacketBufferHandle containing the StatusReport message. This method will take ownership, and will
70      *                 allocate a new PacketBuffer if any protocol-specific data exists.
71      *
72      *  @return CHIP_ERROR Return an error if the message is malformed or buf is \c NULL
73      */
74     CHIP_ERROR Parse(System::PacketBufferHandle buf);
75
76     /**
77      *  Write the StatusReport contents into a buffer using a \c BufferWriter
78      *
79      *  @param[out] buf A \c BufferWriter which contains the buffer that will store the message fields.
80      *
81      *  @return BufferWriter Return a reference to the \c BufferWriter
82      */
83     Encoding::LittleEndian::BufferWriter & WriteToBuffer(Encoding::LittleEndian::BufferWriter & buf) const;
84
85     /**
86      *  Returns the minimum size of the buffer needed to write the message.
87      */
88     size_t Size() const;
89
90     GeneralStatusCode GetGeneralCode() const { return mGeneralCode; }
91     uint32_t GetProtocolId() const { return mProtocolId; }
92     uint16_t GetProtocolCode() const { return mProtocolCode; }
93     const System::PacketBufferHandle & GetProtocolData() const { return mProtocolData; }
94
95 private:
96     GeneralStatusCode mGeneralCode;
97     uint32_t mProtocolId;
98     uint16_t mProtocolCode;
99
100     System::PacketBufferHandle mProtocolData;
101 };
102
103 } // namespace SecureChannel
104 } // namespace Protocols
105 } // namespace chip