1 #pragma once
2 
3 #include "manager.hpp"
4 
5 #include <ipmid/api.h>
6 
7 #include <functional>
8 
9 namespace blobs
10 {
11 
12 using IpmiBlobHandler =
13     std::function<ipmi_ret_t(ManagerInterface* mgr, const uint8_t* reqBuf,
14                              uint8_t* replyCmdBuf, size_t* dataLen)>;
15 
16 /**
17  * Validate the IPMI request and determine routing.
18  *
19  * @param[in] reqBuf - a pointer to the ipmi request packet buffer.
20  * @param[in,out] replyCmdBuf - a pointer to the ipmi reply packet buffer.
21  * @param[in,out] dataLen - initially the request length, set to reply length
22  *                          on return.
23  * @param[out] code - set to the IPMI error on failure, otherwise unset.
24  * @return the ipmi command handler, or nullptr on failure.
25  */
26 IpmiBlobHandler validateBlobCommand(const uint8_t* reqBuf, uint8_t* replyCmdBuf,
27                                     size_t* dataLen, ipmi_ret_t* code);
28 
29 /**
30  * Call the IPMI command and process the result, including running the CRC
31  * computation for the reply message if there is one.
32  *
33  * @param[in] cmd - a funtion pointer to the ipmi command to process.
34  * @param[in] mgr - a pointer to the manager interface.
35  * @param[in] reqBuf - a pointer to the ipmi request packet buffer.
36  * @param[in,out] replyCmdBuf - a pointer to the ipmi reply packet buffer.
37  * @param[in,out] dataLen - initially the request length, set to reply length
38  *                          on return.
39  * @return the ipmi command result.
40  */
41 ipmi_ret_t processBlobCommand(IpmiBlobHandler cmd, ManagerInterface* mgr,
42                               const uint8_t* reqBuf, uint8_t* replyCmdBuf,
43                               size_t* dataLen);
44 
45 /**
46  * Given an IPMI command, request buffer, and reply buffer, validate the request
47  * and call processBlobCommand.
48  */
49 ipmi_ret_t handleBlobCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
50                              uint8_t* replyCmdBuf, size_t* dataLen);
51 } // namespace blobs
52