user_channel: Optimize ipmi complete code
Since the custom return status code is only used in commands.cpp,
optimize the ipmi status code and declare the return status code in
commands.cpp.
Change-Id: I198537e32e38edb9f5a9f8ff347323906bdc6703
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/user_channel/channelcommands.cpp b/user_channel/channelcommands.cpp
index cb4da6b..b4caf0c 100644
--- a/user_channel/channelcommands.cpp
+++ b/user_channel/channelcommands.cpp
@@ -24,6 +24,13 @@
namespace ipmi
{
+constexpr Cc ccPayloadTypeNotSupported = 0x80;
+
+static inline auto responsePayloadTypeNotSupported()
+{
+ return response(ccPayloadTypeNotSupported);
+}
+
/** @brief implements the set channel access command
* @ param ctx - context pointer
* @ param channel - channel number
@@ -369,7 +376,6 @@
{
uint8_t channel =
convertCurrentChannelNum(static_cast<uint8_t>(chNum), ctx->channel);
- constexpr uint8_t payloadTypeNotSupported = 0x80;
if (reserved || !isValidChannel(channel))
{
@@ -380,14 +386,14 @@
if (getChannelSessionSupport(channel) == EChannelSessSupported::none)
{
lg2::debug("Get channel payload version - No support on channel");
- return response(payloadTypeNotSupported);
+ return responsePayloadTypeNotSupported();
}
if (!isValidPayloadType(static_cast<PayloadType>(payloadTypeNum)))
{
lg2::error("Get channel payload version - Payload type unavailable");
- return response(payloadTypeNotSupported);
+ return responsePayloadTypeNotSupported();
}
// BCD encoded version representation - 1.0
diff --git a/user_channel/usercommands.cpp b/user_channel/usercommands.cpp
index 520501d..78c2647 100644
--- a/user_channel/usercommands.cpp
+++ b/user_channel/usercommands.cpp
@@ -32,6 +32,17 @@
static constexpr uint8_t enableOperation = 0x00;
static constexpr uint8_t disableOperation = 0x01;
+static constexpr uint8_t userIdEnabledViaSetPassword = 0x01;
+static constexpr uint8_t userIdDisabledViaSetPassword = 0x02;
+
+/** IPMI set password return codes (refer spec sec 22.30) */
+constexpr Cc ccPasswdFailMismatch = 0x80;
+
+static inline auto responsePasswdFailMismatch()
+{
+ return response(ccPasswdFailMismatch);
+}
+
/** @brief implements the set user access command
* @param ctx - IPMI context pointer (for channel)
* @param channel - channel number
@@ -353,7 +364,7 @@
{
lg2::debug("Test password failed, user Id: {USER_ID}", "USER_ID",
userId);
- return ipmi::response(ipmiCCPasswdFailMismatch);
+ return ipmi::responsePasswdFailMismatch();
}
return ipmi::responseSuccess();
}
diff --git a/user_channel/usercommands.hpp b/user_channel/usercommands.hpp
index a1fb7b9..447f8fa 100644
--- a/user_channel/usercommands.hpp
+++ b/user_channel/usercommands.hpp
@@ -15,22 +15,9 @@
*/
#pragma once
-#include <cstdint>
namespace ipmi
{
-/**
- * @enum IPMI set password return codes (refer spec sec 22.30)
- */
-enum ipmi_set_password_return_codes : uint8_t
-{
- ipmiCCPasswdFailMismatch = 0x80,
- ipmiCCPasswdFailWrongSize = 0x81,
-};
-
-static constexpr uint8_t userIdEnabledViaSetPassword = 0x1;
-static constexpr uint8_t userIdDisabledViaSetPassword = 0x2;
-
void registerUserIpmiFunctions();
} // namespace ipmi