3 * Copyright (c) 2021 Project CHIP Authors
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <support/BufferWriter.h>
22 #include <system/SystemPacketBuffer.h>
26 namespace SecureChannel {
29 * Encapsulates the data included in a StatusReport message, and provides methods for writing to and reading from PacketBuffers
30 * that contain StatusReport messages.
32 class DLL_EXPORT StatusReport
36 * Construct a StatusReport with zero-d out fields (for use before calling \c Parse() ).
41 * Construct a StatusReport with no additional ProtocolData.
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
47 StatusReport(GeneralStatusCode generalCode, uint32_t protocolId, uint16_t protocolCode);
51 * Construct a StatusReport with additional ProtocolData.
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
58 StatusReport(GeneralStatusCode generalCode, uint32_t protocolId, uint16_t protocolCode,
59 System::PacketBufferHandle protocolData);
62 * Read the contents of a \c PacketBuffer containing a StatusReport message and store the field values in this object.
64 * @note If there is additional data after the Protocol Code field in the message, it is assumed to be protocol-specific data.
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.
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.
72 * @return CHIP_ERROR Return an error if the message is malformed or buf is \c NULL
74 CHIP_ERROR Parse(System::PacketBufferHandle buf);
77 * Write the StatusReport contents into a buffer using a \c BufferWriter
79 * @param[out] buf A \c BufferWriter which contains the buffer that will store the message fields.
81 * @return BufferWriter Return a reference to the \c BufferWriter
83 Encoding::LittleEndian::BufferWriter & WriteToBuffer(Encoding::LittleEndian::BufferWriter & buf) const;
86 * Returns the minimum size of the buffer needed to write the message.
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; }
96 GeneralStatusCode mGeneralCode;
98 uint16_t mProtocolCode;
100 System::PacketBufferHandle mProtocolData;
103 } // namespace SecureChannel
104 } // namespace Protocols