Fix: refactor get channel cipher suite command
Get channel cipher suites command updated as per new ipmi structure.
Tested:
ipmitool raw 0x06 0x54 0x01 0x00 0x80
01 c0 03 01 41 81 c0 11 03 44 81 //response
Also verified by issuing cmd:
ipmitool channel getciphers ipmi 0x01
which listed supported CIA algorithms as response
Signed-off-by: Ayushi Smriti <smriti.ayushi@linux.intel.com>
Change-Id: Ibc942f5b197c72071cd35a138fbe244db7519824
diff --git a/app/channel.cpp b/app/channel.cpp
index 6ea25c4..91cbe88 100644
--- a/app/channel.cpp
+++ b/app/channel.cpp
@@ -97,27 +97,39 @@
} // namespace cipher
-ipmi_ret_t getChannelCipherSuites(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
- ipmi_request_t request,
- ipmi_response_t response,
- ipmi_data_len_t data_len,
- ipmi_context_t context)
+/** @brief this command is used to look up what authentication, integrity,
+ * confidentiality algorithms are supported.
+ *
+ * @ param ctx - context pointer
+ * @ param channelNumber - channel number
+ * @ param payloadType - payload type
+ * @ param listIndex - list index
+ * @ param algoSelectBit - list algorithms
+ *
+ * @returns ipmi completion code plus response data
+ * - rspChannel - channel number for authentication algorithm.
+ * - rspRecords - cipher suite records.
+ **/
+ipmi::RspType<uint8_t, // Channel Number
+ std::vector<uint8_t> // Cipher Records
+ >
+ getChannelCipherSuites(ipmi::Context::ptr ctx, uint4_t channelNumber,
+ uint4_t reserved1, uint8_t payloadType,
+ uint6_t listIndex, uint1_t reserved2,
+ uint1_t algoSelectBit)
{
static std::vector<uint8_t> cipherRecords;
static std::vector<uint8_t> supportedAlgorithms;
static auto recordInit = false;
- auto requestData =
- reinterpret_cast<const GetChannelCipherRequest*>(request);
+ uint8_t rspChannel = ipmi::convertCurrentChannelNum(
+ static_cast<uint8_t>(channelNumber), ctx->channel);
- if (*data_len < sizeof(GetChannelCipherRequest))
+ if (!ipmi::isValidChannel(rspChannel) || reserved1 != 0 || reserved2 != 0)
{
- *data_len = 0;
- return IPMI_CC_REQ_DATA_LEN_INVALID;
+ return ipmi::responseInvalidFieldRequest();
}
- *data_len = 0;
-
if (!recordInit)
{
try
@@ -128,41 +140,28 @@
}
catch (const std::exception& e)
{
- return IPMI_CC_UNSPECIFIED_ERROR;
+ return ipmi::responseUnspecifiedError();
}
}
- const auto& records = (cipher::listCipherSuite ==
- (requestData->listIndex & cipher::listTypeMask))
- ? cipherRecords
- : supportedAlgorithms;
+ const std::vector<uint8_t>& records =
+ algoSelectBit ? cipherRecords : supportedAlgorithms;
+ static constexpr auto respSize = 16;
// List index(00h-3Fh), 0h selects the first set of 16, 1h selects the next
// set of 16 and so on.
- auto index =
- static_cast<size_t>(requestData->listIndex & cipher::listIndexMask);
// Calculate the number of record data bytes to be returned.
- auto start = std::min(index * cipher::respSize, records.size());
- auto end =
- std::min((index * cipher::respSize) + cipher::respSize, records.size());
+ auto start =
+ std::min(static_cast<size_t>(listIndex) * respSize, records.size());
+ auto end = std::min((static_cast<size_t>(listIndex) * respSize) + respSize,
+ records.size());
auto size = end - start;
- auto responseData = reinterpret_cast<GetChannelCipherRespHeader*>(response);
- responseData->channelNumber = cipher::defaultChannelNumber;
+ std::vector<uint8_t> rspRecords;
+ std::copy_n(records.data() + start, size, std::back_inserter(rspRecords));
- if (!size)
- {
- *data_len = sizeof(GetChannelCipherRespHeader);
- }
- else
- {
- std::copy_n(records.data() + start, size,
- static_cast<uint8_t*>(response) + 1);
- *data_len = size + sizeof(GetChannelCipherRespHeader);
- }
-
- return IPMI_CC_OK;
+ return ipmi::responseSuccess(rspChannel, rspRecords);
}
template <typename... ArgTypes>
diff --git a/app/channel.hpp b/app/channel.hpp
index 7004ddd..8e5accb 100644
--- a/app/channel.hpp
+++ b/app/channel.hpp
@@ -1,6 +1,6 @@
#include "nlohmann/json.hpp"
-#include <ipmid/api.h>
+#include <ipmid/api.hpp>
/** @brief The set channel access IPMI command.
*
@@ -53,31 +53,31 @@
ipmi_data_len_t data_len,
ipmi_context_t context);
-/** @brief Implementation of get channel cipher suites command
+/** @brief this command is used to look up what authentication, integrity,
+ * confidentiality algorithms are supported.
*
- * @param[in] netfn - Net Function
- * @param[in] cmd - Command
- * @param[in] request - Request pointer
- * @param[in,out] response - Response pointer
- * @param[in,out] data_len - Data Length
- * @param[in] context - Context
+ * @ param ctx - context pointer
+ * @ param channelNumber - channel number
+ * @ param payloadType - payload type
+ * @ param listIndex - list index
+ * @ param algoSelectBit - list algorithms
*
- * @return IPMI_CC_OK on success, non-zero otherwise.
- */
-ipmi_ret_t getChannelCipherSuites(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
- ipmi_request_t request,
- ipmi_response_t response,
- ipmi_data_len_t data_len,
- ipmi_context_t context);
+ * @returns ipmi completion code plus response data
+ * - rspChannel - channel number for authentication algorithm.
+ * - rspRecords - cipher suite records.
+ **/
+ipmi::RspType<uint8_t, // Channel Number
+ std::vector<uint8_t> // Cipher Records
+ >
+ getChannelCipherSuites(ipmi::Context::ptr ctx, uint4_t channelNumber,
+ uint4_t reserved1, uint8_t payloadType,
+ uint6_t listIndex, uint1_t reserved2,
+ uint1_t algoSelectBit);
namespace cipher
{
-static constexpr auto defaultChannelNumber = 1;
-static constexpr auto listTypeMask = 0x80;
static constexpr auto listCipherSuite = 0x80;
-static constexpr auto listIndexMask = 0x3F;
-static constexpr auto respSize = 16;
using Json = nlohmann::json;
static constexpr auto configFile = "/usr/share/ipmi-providers/cipher_list.json";
@@ -92,23 +92,3 @@
static constexpr auto confTag = 0x80;
} // namespace cipher
-
-/** @struct GetChannelCipherRequest
- *
- * IPMI payload for Get Channel Cipher Suites command request
- */
-struct GetChannelCipherRequest
-{
- uint8_t channelNumber; //!< Channel Number
- uint8_t payloadType; //!< Payload type number
- uint8_t listIndex; //!< List Index
-} __attribute__((packed));
-
-/** @struct GetChannelCipherRespHeader
- *
- * IPMI payload for Get Channel Cipher Suites command response header
- */
-struct GetChannelCipherRespHeader
-{
- uint8_t channelNumber; //!< Channel Number
-} __attribute__((packed));
diff --git a/apphandler.cpp b/apphandler.cpp
index 0c962cd..c5a608d 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -1217,8 +1217,9 @@
ipmiAppGetSystemGuid);
// <Get Channel Cipher Suites Command>
- ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_CIPHER_SUITES, NULL,
- getChannelCipherSuites, PRIVILEGE_CALLBACK);
+ ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
+ ipmi::app::cmdGetChannelCipherSuites,
+ ipmi::Privilege::Callback, getChannelCipherSuites);
// <Get System Info Command>
ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
diff --git a/apphandler.hpp b/apphandler.hpp
index d4dd8e8..4f03121 100644
--- a/apphandler.hpp
+++ b/apphandler.hpp
@@ -19,7 +19,6 @@
IPMI_CMD_SET_CHAN_ACCESS = 0x40,
IPMI_CMD_GET_CHANNEL_ACCESS = 0x41,
IPMI_CMD_GET_CHAN_INFO = 0x42,
- IPMI_CMD_GET_CHAN_CIPHER_SUITES = 0x54,
IPMI_CMD_SET_SYSTEM_INFO = 0x58,
IPMI_CMD_GET_SYSTEM_INFO = 0x59,
};