blob: 1b5a693f24ac8de524d4150ec208830ce89fc880 [file] [log] [blame]
Tom Joseph4e57ada2016-08-10 06:51:12 -05001#pragma once
2
3#include "message.hpp"
4#include "session.hpp"
5
6namespace message
7{
8
9namespace parser
10{
11
12constexpr size_t RMCP_VERSION = 6;
13
14// RMCP Messages with class=IPMI should be sent with an RMCP Sequence
15// Number of FFh to indicate that an RMCP ACK message should not be
16// generated by the message receiver.
17constexpr size_t RMCP_SEQ = 0xFF;
18
19// RMCP Message Class 7h is for IPMI
20constexpr size_t RMCP_MESSAGE_CLASS_IPMI = 7;
21
Tom Joseph4e57ada2016-08-10 06:51:12 -050022enum class SessionHeader
23{
24 IPMI15 = 0x00,
25 IPMI20 = 0x06,
26 INVALID = 0xFF,
27};
28
29struct BasicHeader_t
30{
31 // RMCP Header
32 uint8_t version;
33 uint8_t reserved;
34 uint8_t rmcpSeqNum;
35 uint8_t classOfMsg;
36
37 // IPMI partial session header
38 union
39 {
40 uint8_t reserved1: 4;
41 uint8_t authType: 4;
42 uint8_t formatType;
43 } format;
44} __attribute__((packed));
45
46/*
47 * @brief Unflatten an incoming packet and prepare the IPMI message
48 *
49 * @param[in] inPacket - Incoming IPMI packet
50 *
51 * @return A tuple with IPMI message and the session header type to sent the
52 * response packet. In case of success incoming message and session
53 * header type. In case of failure nullptr and session header type
54 * would be invalid.
55 */
56std::tuple<std::unique_ptr<Message>, SessionHeader> unflatten(
57 std::vector<uint8_t>& inPacket);
58
59/*
60 * @brief Flatten an IPMI message and generate the IPMI packet with the
61 * session header
62 *
63 * @param[in] outMessage - IPMI message to be flattened
64 * @param[in] authType - Session header type to be added to the IPMI
65 * packet
66 *
67 * @return IPMI packet on success
68 */
69std::vector<uint8_t> flatten(Message& outMessage,
70 SessionHeader authType,
71 session::Session& session);
72
73} // namespace parser
74
75namespace ipmi15parser
76{
77
78struct SessionHeader_t
79{
80 struct parser::BasicHeader_t base;
81 uint32_t sessSeqNum;
82 uint32_t sessId;
83 // <Optional Field: AuthCode>
84 uint8_t payloadLength;
85} __attribute__((packed));
86
87struct SessionTrailer_t
88{
89 uint8_t legacyPad;
90} __attribute__((packed));
91
92/*
93 * @brief Unflatten an incoming packet and prepare the IPMI message
94 *
95 * @param[in] inPacket - Incoming IPMI packet
96 *
97 * @return IPMI message in the packet on success
98 */
99std::unique_ptr<Message> unflatten(std::vector<uint8_t>& inPacket);
100
101/*
102 * @brief Flatten an IPMI message and generate the IPMI packet with the
103 * session header
104 *
105 * @param[in] outMessage - IPMI message to be flattened
106 *
107 * @return IPMI packet on success
108 */
109std::vector<uint8_t> flatten(Message& outMessage, session::Session& session);
110
111} // namespace ipmi15parser
112
113namespace ipmi20parser
114{
115
116constexpr size_t MAX_INTEGRITY_DATA_LENGTH = 12;
117constexpr size_t PAYLOAD_ENCRYPT_MASK = 0x80;
118constexpr size_t PAYLOAD_AUTH_MASK = 0x40;
119
120struct SessionHeader_t
121{
122 struct parser::BasicHeader_t base;
123
124 uint8_t payloadType;
125
126 uint32_t sessId;
127 uint32_t sessSeqNum;
128 uint16_t payloadLength;
129} __attribute__((packed));
130
131struct SessionTrailer_t
132{
133 // Integrity Pad
134 uint8_t padLength;
135 uint8_t nextHeader;
Tom Joseph4e57ada2016-08-10 06:51:12 -0500136} __attribute__((packed));
137
138/*
139 * @brief Unflatten an incoming packet and prepare the IPMI message
140 *
141 * @param[in] inPacket - Incoming IPMI packet
142 *
143 * @return IPMI message in the packet on success
144 */
145std::unique_ptr<Message> unflatten(std::vector<uint8_t>& inPacket);
146
147/*
148 * @brief Flatten an IPMI message and generate the IPMI packet with the
149 * session header
150 *
151 * @param[in] outMessage - IPMI message to be flattened
152 *
153 * @return IPMI packet on success
154 */
155std::vector<uint8_t> flatten(Message& outMessage, session::Session& session);
156
157namespace internal
158{
159
160/*
161 * @brief Add sequence number to the message
162 *
163 * @param[in] packet - outgoing packet to which to add sequence number
164 * @param[in] session - session handle
165 *
166 */
167void addSequenceNumber(std::vector<uint8_t>& packet, session::Session& session);
168
169} // namespace internal
170
171} // namespace ipmi20parser
172
173} // namespace message