1 #pragma once
2 
3 #include "message_handler.hpp"
4 
5 #include <vector>
6 
7 namespace sol
8 {
9 
10 namespace command
11 {
12 
13 constexpr uint8_t IPMI_CC_PAYLOAD_ALREADY_ACTIVE = 0x80;
14 constexpr uint8_t IPMI_CC_PAYLOAD_TYPE_DISABLED = 0x81;
15 constexpr uint8_t IPMI_CC_PAYLOAD_ACTIVATION_LIMIT = 0x82;
16 constexpr uint8_t IPMI_CC_PAYLOAD_WITH_ENCRYPTION = 0x83;
17 constexpr uint8_t IPMI_CC_PAYLOAD_WITHOUT_ENCRYPTION = 0x84;
18 
19 /** @struct ActivatePayloadRequest
20  *
21  *  IPMI payload for Activate Payload command request.
22  */
23 struct ActivatePayloadRequest
24 {
25 #if BYTE_ORDER == LITTLE_ENDIAN
26     uint8_t payloadType : 6; //!< Payload type.
27     uint8_t reserved1 : 2;   //!< Reserved.
28 #endif
29 
30 #if BYTE_ORDER == BIG_ENDIAN
31     uint8_t reserved1 : 2;   //!< Payload type.
32     uint8_t payloadType : 6; //!< Payload type.
33 #endif
34 
35 #if BYTE_ORDER == LITTLE_ENDIAN
36     uint8_t payloadInstance : 4; //!< Payload instance.
37     uint8_t reserved2 : 4;       //!< Reserved.
38 #endif
39 
40 #if BYTE_ORDER == BIG_ENDIAN
41     uint8_t reserved2 : 4;       //!< Reserved.
42     uint8_t payloadInstance : 4; //!< Payload instance.
43 #endif
44 
45     /** @brief The following Auxiliary Request Data applies only for payload
46      *         SOL only.
47      */
48 #if BYTE_ORDER == LITTLE_ENDIAN
49     uint8_t reserved4 : 1;  //!< Reserved.
50     uint8_t handshake : 1;  //!< SOL startup handshake.
51     uint8_t alert : 2;      //!< Shared serial alert behavior.
52     uint8_t reserved3 : 1;  //!< Reserved.
53     uint8_t testMode : 1;   //!< Test mode.
54     uint8_t auth : 1;       //!< If true, activate payload with authentication.
55     uint8_t encryption : 1; //!< If true, activate payload with encryption.
56 #endif
57 
58 #if BYTE_ORDER == BIG_ENDIAN
59     uint8_t encryption : 1; //!< If true, activate payload with encryption.
60     uint8_t auth : 1;       //!< If true, activate payload with authentication.
61     uint8_t testMode : 1;   //!< Test mode.
62     uint8_t reserved3 : 1;  //!< Reserved.
63     uint8_t alert : 2;      //!< Shared serial alert behavior.
64     uint8_t handshake : 1;  //!< SOL startup handshake.
65     uint8_t reserved4 : 1;  //!< Reserved.
66 #endif
67 
68     uint8_t reserved5; //!< Reserved.
69     uint8_t reserved6; //!< Reserved.
70     uint8_t reserved7; //!< Reserved.
71 } __attribute__((packed));
72 
73 /** @struct ActivatePayloadResponse
74  *
75  *  IPMI payload for Activate Payload command response.
76  */
77 struct ActivatePayloadResponse
78 {
79     uint8_t completionCode; //!< Completion code.
80     uint8_t reserved1;      //!< Reserved.
81     uint8_t reserved2;      //!< Reserved.
82     uint8_t reserved3;      //!< Reserved.
83 
84     // Test Mode
85 #if BYTE_ORDER == LITTLE_ENDIAN
86     uint8_t testMode : 1;  //!< Test mode.
87     uint8_t reserved4 : 7; //!< Reserved.
88 #endif
89 
90 #if BYTE_ORDER == BIG_ENDIAN
91     uint8_t reserved4 : 7; //!< Reserved.
92     uint8_t testMode : 1;  //!< Test mode.
93 #endif
94 
95     uint16_t inPayloadSize;  //!< Inbound payload size
96     uint16_t outPayloadSize; //!< Outbound payload size.
97     uint16_t portNum;        //!< Payload UDP port number.
98     uint16_t vlanNum;        //!< Payload VLAN number.
99 } __attribute__((packed));
100 
101 /** @brief Activate Payload Command.
102  *
103  *  This command is used for activating and deactivating a payload type under a
104  *  given IPMI session. The UDP Port number for SOL is the same as the port that
105  *  was used to establish the IPMI session.
106  *
107  *  @param[in] inPayload - Request data for the command.
108  *  @param[in] handler - Reference to the message handler.
109  *
110  *  @return Response data for the command
111  */
112 std::vector<uint8_t> activatePayload(const std::vector<uint8_t>& inPayload,
113                                      const message::Handler& handler);
114 
115 constexpr uint8_t IPMI_CC_PAYLOAD_DEACTIVATED = 0x80;
116 
117 /** @struct DeactivatePayloadRequest
118  *
119  *  IPMI payload for Deactivate Payload command request.
120  */
121 struct DeactivatePayloadRequest
122 {
123 #if BYTE_ORDER == LITTLE_ENDIAN
124     uint8_t payloadType : 6; //!< Payload type.
125     uint8_t reserved1 : 2;   //!< Reserved.
126 #endif
127 
128 #if BYTE_ORDER == BIG_ENDIAN
129     uint8_t reserved1 : 2;   //!< Payload type.
130     uint8_t payloadType : 6; //!< Reserved.
131 #endif
132 
133 #if BYTE_ORDER == LITTLE_ENDIAN
134     uint8_t payloadInstance : 4; //!< Payload instance.
135     uint8_t reserved2 : 4;       //!< Reserved.
136 #endif
137 
138 #if BYTE_ORDER == BIG_ENDIAN
139     uint8_t reserved2 : 4;       //!< Reserved.
140     uint8_t payloadInstance : 4; //!< Payload instance.
141 #endif
142 
143     /** @brief No auxiliary data for payload type SOL */
144     uint8_t auxData1; //!< Auxiliary data 1
145     uint8_t auxData2; //!< Auxiliary data 2
146     uint8_t auxData3; //!< Auxiliary data 3
147     uint8_t auxData4; //!< Auxiliary data 4
148 } __attribute__((packed));
149 
150 /** @struct DeactivatePayloadResponse
151  *
152  * IPMI payload for Deactivate Payload Command response.
153  */
154 struct DeactivatePayloadResponse
155 {
156     uint8_t completionCode; //!< Completion code
157 } __attribute__((packed));
158 
159 /** @brief Deactivate Payload Command.
160  *
161  *  This command is used to terminate use of a given payload on an IPMI session.
162  *  This type of traffic then becomes freed for activation by another session,
163  *  or for possible re-activation under the present session.The Deactivate
164  *  Payload command does not cause the session to be terminated. The Close
165  *  Session command should be used for that purpose. A remote console
166  *  terminating a application does not need to explicitly deactivate payload(s)
167  *  prior to session. When a session terminates all payloads that were active
168  *  under that session are automatically deactivated by the BMC.
169  *
170  * @param[in] inPayload - Request data for the command.
171  * @param[in] handler - Reference to the message handler.
172  *
173  * @return Response data for the command.
174  */
175 std::vector<uint8_t> deactivatePayload(const std::vector<uint8_t>& inPayload,
176                                        const message::Handler& handler);
177 
178 /** @struct GetPayloadStatusRequest
179  *
180  *  IPMI payload for Get Payload Activation Status command request.
181  */
182 struct GetPayloadStatusRequest
183 {
184     uint8_t payloadType; //!< Payload type
185 } __attribute__((packed));
186 
187 /** @struct GetPayloadStatusResponse
188  *
189  *  IPMI payload for Get Payload Activation Status command response.
190  */
191 struct GetPayloadStatusResponse
192 {
193     uint8_t completionCode; //!< Completion code.
194 
195     uint8_t capacity; //!< Instance capacity.
196 
197     /* @brief Activation Status. */
198 #if BYTE_ORDER == LITTLE_ENDIAN
199     uint8_t instance1 : 1; //!< If true, Instance 1 is activated.
200     uint8_t instance2 : 1; //!< If true, Instance 2 is activated.
201     uint8_t instance3 : 1; //!< If true, Instance 3 is activated.
202     uint8_t instance4 : 1; //!< If true, Instance 4 is activated.
203     uint8_t instance5 : 1; //!< If true, Instance 5 is activated.
204     uint8_t instance6 : 1; //!< If true, Instance 6 is activated.
205     uint8_t instance7 : 1; //!< If true, Instance 7 is activated.
206     uint8_t instance8 : 1; //!< If true, Instance 8 is activated.
207 #endif
208 
209 #if BYTE_ORDER == BIG_ENDIAN
210     uint8_t instance8 : 1; //!< If true, Instance 8 is activated.
211     uint8_t instance7 : 1; //!< If true, Instance 7 is activated.
212     uint8_t instance6 : 1; //!< If true, Instance 6 is activated.
213     uint8_t instance5 : 1; //!< If true, Instance 5 is activated.
214     uint8_t instance4 : 1; //!< If true, Instance 4 is activated.
215     uint8_t instance3 : 1; //!< If true, Instance 3 is activated.
216     uint8_t instance2 : 1; //!< If true, Instance 2 is activated.
217     uint8_t instance1 : 1; //!< If true, Instance 1 is activated.
218 #endif
219 
220 #if BYTE_ORDER == LITTLE_ENDIAN
221     uint8_t instance9 : 1;  //!< If true, Instance 9 is activated.
222     uint8_t instance10 : 1; //!< If true, Instance 10 is activated.
223     uint8_t instance11 : 1; //!< If true, Instance 11 is activated.
224     uint8_t instance12 : 1; //!< If true, Instance 12 is activated.
225     uint8_t instance13 : 1; //!< If true, Instance 13 is activated.
226     uint8_t instance14 : 1; //!< If true, Instance 14 is activated.
227     uint8_t instance15 : 1; //!< If true, Instance 15 is activated.
228     uint8_t instance16 : 1; //!< If true, Instance 16 is activated.
229 #endif
230 
231 #if BYTE_ORDER == BIG_ENDIAN
232     uint8_t instance16 : 1; //!< If true, Instance 16 is activated.
233     uint8_t instance15 : 1; //!< If true, Instance 15 is activated.
234     uint8_t instance14 : 1; //!< If true, Instance 14 is activated.
235     uint8_t instance13 : 1; //!< If true, Instance 13 is activated.
236     uint8_t instance12 : 1; //!< If true, Instance 12 is activated.
237     uint8_t instance11 : 1; //!< If true, Instance 11 is activated.
238     uint8_t instance10 : 1; //!< If true, Instance 10 is activated.
239     uint8_t instance9 : 1;  //!< If true, Instance 9 is activated.
240 #endif
241 } __attribute__((packed));
242 
243 /** @brief Get Payload Activation Status Command.
244  *
245  *  This command returns how many instances of a given payload type are
246  *  presently activated, and how many total instances can be activated.
247  *
248  *  @param[in] inPayload - Request Data for the command.
249  *  @param[in] handler - Reference to the Message Handler.
250  *
251  *  @return Response data for the command
252  */
253 std::vector<uint8_t> getPayloadStatus(const std::vector<uint8_t>& inPayload,
254                                       const message::Handler& handler);
255 
256 /** @struct GetPayloadInfoRequest
257  *
258  *  IPMI payload for Get Payload Instance info command request.
259  */
260 struct GetPayloadInfoRequest
261 {
262     uint8_t payloadType;     //!< Payload type
263     uint8_t payloadInstance; //!< Payload instance
264 } __attribute__((packed));
265 
266 /** @struct GetPayloadInfoResponse
267  *
268  *  IPMI payload for Get Payload Instance info command response.
269  */
270 struct GetPayloadInfoResponse
271 {
272     uint8_t completionCode; //!< Completion code.
273     uint32_t sessionID;     //!< Session ID
274     uint8_t portNumber;     //!< Port number
275     uint8_t reserved[7];    //!< Reserved
276 } __attribute__((packed));
277 
278 /** @brief Get Payload Instance Info Command.
279  *
280  *  This command returns information about a specific instance of a payload
281  *  type. Session ID is returned by this command
282  *
283  *  @param[in] inPayload - Request Data for the command.
284  *  @param[in] handler - Reference to the Message Handler.
285  *
286  *  @return Response data for the command
287  */
288 std::vector<uint8_t> getPayloadInfo(const std::vector<uint8_t>& inPayload,
289                                     const message::Handler& handler);
290 
291 } // namespace command
292 
293 } // namespace sol
294