ncsi: move ncsi operations to Interface class
The existing NCSI operations are quite Interface-specific (ie., rely on
netlink-specific constructs), so move these to methods on the Interface
class.
We'll add alternative implementations in a future change.
Change-Id: I3ea5fcd64969a2c164503057e35881010ad141a0
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
diff --git a/src/ncsi_netlink_main.cpp b/src/ncsi_netlink_main.cpp
index 3ac42bd..04e0cbc 100644
--- a/src/ncsi_netlink_main.cpp
+++ b/src/ncsi_netlink_main.cpp
@@ -138,8 +138,8 @@
exitWithError("Package not specified.", argv);
}
- return ncsi::sendOemCommand(
- interface, packageInt, channelInt, operationInt,
+ return interface.sendOemCommand(
+ packageInt, channelInt, operationInt,
std::span<const unsigned char>(payload.begin(), payload.end()));
}
else if ((options)["set"] == "true")
@@ -149,15 +149,15 @@
{
exitWithError("Package not specified.", argv);
}
- return ncsi::setChannel(interface, packageInt, channelInt);
+ return interface.setChannel(packageInt, channelInt);
}
else if ((options)["info"] == "true")
{
- return ncsi::getInfo(interface, packageInt);
+ return interface.getInfo(packageInt);
}
else if ((options)["clear"] == "true")
{
- return ncsi::clearInterface(interface);
+ return interface.clearInterface();
}
else if (!(options)["pmask"].empty())
{
@@ -175,7 +175,7 @@
{
exitWithError("Package mask value is not valid", argv);
}
- return ncsi::setPackageMask(interface, mask);
+ return interface.setPackageMask(mask);
}
else if (!(options)["cmask"].empty())
{
@@ -197,7 +197,7 @@
{
exitWithError("Channel mask value is not valid", argv);
}
- return ncsi::setChannelMask(interface, packageInt, mask);
+ return interface.setChannelMask(packageInt, mask);
}
else
{
diff --git a/src/ncsi_util.cpp b/src/ncsi_util.cpp
index 3eb73ad..a8cfbb2 100644
--- a/src/ncsi_util.cpp
+++ b/src/ncsi_util.cpp
@@ -425,87 +425,84 @@
return std::to_string(interface.ifindex);
}
-int sendOemCommand(Interface& interface, int package, int channel,
- int operation, std::span<const unsigned char> payload)
+int Interface::sendOemCommand(int package, int channel, int operation,
+ std::span<const unsigned char> payload)
{
lg2::debug("Send OEM Command, CHANNEL : {CHANNEL} , PACKAGE : {PACKAGE}, "
"INTERFACE: {INTERFACE}",
"CHANNEL", lg2::hex, channel, "PACKAGE", lg2::hex, package,
- "INTERFACE", interface);
+ "INTERFACE", this);
if (!payload.empty())
{
lg2::debug("Payload: {PAYLOAD}", "PAYLOAD", toHexStr(payload));
}
return internal::applyCmd(
- interface,
+ *this,
internal::Command(ncsi_nl_commands::NCSI_CMD_SEND_CMD, operation,
payload),
package, channel, NONE, internal::sendCallBack);
}
-int setChannel(Interface& interface, int package, int channel)
+int Interface::setChannel(int package, int channel)
{
lg2::debug("Set CHANNEL : {CHANNEL} , PACKAGE : {PACKAGE}, INTERFACE : "
"{INTERFACE}",
"CHANNEL", lg2::hex, channel, "PACKAGE", lg2::hex, package,
- "INTERFACE", interface);
+ "INTERFACE", this);
return internal::applyCmd(
- interface, internal::Command(ncsi_nl_commands::NCSI_CMD_SET_INTERFACE),
+ *this, internal::Command(ncsi_nl_commands::NCSI_CMD_SET_INTERFACE),
package, channel);
}
-int clearInterface(Interface& interface)
+int Interface::clearInterface()
{
- lg2::debug("ClearInterface , INTERFACE : {INTERFACE}", "INTERFACE",
- interface);
+ lg2::debug("ClearInterface , INTERFACE : {INTERFACE}", "INTERFACE", this);
return internal::applyCmd(
- interface,
- internal::Command(ncsi_nl_commands::NCSI_CMD_CLEAR_INTERFACE));
+ *this, internal::Command(ncsi_nl_commands::NCSI_CMD_CLEAR_INTERFACE));
}
-int getInfo(Interface& interface, int package)
+int Interface::getInfo(int package)
{
lg2::debug("Get Info , PACKAGE : {PACKAGE}, INTERFACE: {INTERFACE}",
- "PACKAGE", lg2::hex, package, "INTERFACE", interface);
+ "PACKAGE", lg2::hex, package, "INTERFACE", this);
if (package == DEFAULT_VALUE)
{
return internal::applyCmd(
- interface, internal::Command(ncsi_nl_commands::NCSI_CMD_PKG_INFO),
+ *this, internal::Command(ncsi_nl_commands::NCSI_CMD_PKG_INFO),
package, DEFAULT_VALUE, NLM_F_DUMP, internal::infoCallBack);
}
else
{
- return internal::applyCmd(interface,
- ncsi_nl_commands::NCSI_CMD_PKG_INFO, package,
- DEFAULT_VALUE, NONE, internal::infoCallBack);
+ return internal::applyCmd(*this, ncsi_nl_commands::NCSI_CMD_PKG_INFO,
+ package, DEFAULT_VALUE, NONE,
+ internal::infoCallBack);
}
}
-int setPackageMask(Interface& interface, unsigned int mask)
+int Interface::setPackageMask(unsigned int mask)
{
lg2::debug("Set Package Mask , INTERFACE: {INTERFACE} MASK: {MASK}",
- "INTERFACE", interface, "MASK", lg2::hex, mask);
+ "INTERFACE", this, "MASK", lg2::hex, mask);
auto payload = std::span<const unsigned char>(
reinterpret_cast<const unsigned char*>(&mask),
reinterpret_cast<const unsigned char*>(&mask) + sizeof(decltype(mask)));
return internal::applyCmd(
- interface,
- internal::Command(ncsi_nl_commands::NCSI_CMD_SET_PACKAGE_MASK, 0,
- payload));
+ *this, internal::Command(ncsi_nl_commands::NCSI_CMD_SET_PACKAGE_MASK, 0,
+ payload));
}
-int setChannelMask(Interface& interface, int package, unsigned int mask)
+int Interface::setChannelMask(int package, unsigned int mask)
{
lg2::debug(
"Set Channel Mask , INTERFACE: {INTERFACE}, PACKAGE : {PACKAGE} MASK: {MASK}",
- "INTERFACE", interface, "PACKAGE", lg2::hex, package, "MASK", lg2::hex,
+ "INTERFACE", this, "PACKAGE", lg2::hex, package, "MASK", lg2::hex,
mask);
auto payload = std::span<const unsigned char>(
reinterpret_cast<const unsigned char*>(&mask),
reinterpret_cast<const unsigned char*>(&mask) + sizeof(decltype(mask)));
return internal::applyCmd(
- interface,
+ *this,
internal::Command(ncsi_nl_commands::NCSI_CMD_SET_CHANNEL_MASK, 0,
payload),
package);
diff --git a/src/ncsi_util.hpp b/src/ncsi_util.hpp
index a04e249..aa2051c 100644
--- a/src/ncsi_util.hpp
+++ b/src/ncsi_util.hpp
@@ -15,74 +15,67 @@
struct Interface
{
+ /* @brief This function will ask underlying NCSI driver
+ * to send an OEM command (command type 0x50) with
+ * the specified payload as the OEM data.
+ * This function talks with the NCSI driver over
+ * netlink messages.
+ * @param[in] package - NCSI Package.
+ * @param[in] channel - Channel number with in the package.
+ * @param[in] opcode - NCSI Send Command sub-operation
+ * @param[in] payload - OEM data to send.
+ * @returns 0 on success and negative value for failure.
+ */
+ int sendOemCommand(int package, int channel, int opcode,
+ std::span<const unsigned char> payload);
+
+ /* @brief This function will ask underlying NCSI driver
+ * to set a specific package or package/channel
+ * combination as the preferred choice.
+ * This function talks with the NCSI driver over
+ * netlink messages.
+ * @param[in] package - NCSI Package.
+ * @param[in] channel - Channel number with in the package.
+ * @returns 0 on success and negative value for failure.
+ */
+ int setChannel(int package, int channel);
+
+ /* @brief This function will ask underlying NCSI driver
+ * to clear any preferred setting from the interface.
+ * This function talks with the NCSI driver over
+ * netlink messages.
+ * @returns 0 on success and negative value for failure.
+ */
+ int clearInterface();
+
+ /* @brief This function is used to dump all the info
+ * of the package and the channels underlying
+ * the package.
+ * @param[in] package - NCSI Package.
+ * @returns 0 on success and negative value for failure.
+ */
+ int getInfo(int package);
+
+ /* @brief This function assigns a mask controlling responses to AEN from a
+ * package.
+ * @param[in] mask - A 32-bit mask integer
+ * @returns 0 on success and negative value for failure.
+ */
+ int setPackageMask(unsigned int mask);
+
+ /* @brief This function sets the AEN mask for the channels inside the
+ * selected package.
+ * @param[in] package - NCSI Package.
+ * @param[in] mask - A 32-bit mask integer
+ * @returns 0 on success and negative value for failure.
+ */
+ int setChannelMask(int package, unsigned int mask);
+
int ifindex;
};
std::string to_string(Interface& interface);
-/* @brief This function will ask underlying NCSI driver
- * to send an OEM command (command type 0x50) with
- * the specified payload as the OEM data.
- * This function talks with the NCSI driver over
- * netlink messages.
- * @param[in] interface - Interface
- * @param[in] package - NCSI Package.
- * @param[in] channel - Channel number with in the package.
- * @param[in] opcode - NCSI Send Command sub-operation
- * @param[in] payload - OEM data to send.
- * @returns 0 on success and negative value for failure.
- */
-int sendOemCommand(Interface& interface, int package, int channel, int opcode,
- std::span<const unsigned char> payload);
-
-/* @brief This function will ask underlying NCSI driver
- * to set a specific package or package/channel
- * combination as the preferred choice.
- * This function talks with the NCSI driver over
- * netlink messages.
- * @param[in] interface - Interface
- * @param[in] package - NCSI Package.
- * @param[in] channel - Channel number with in the package.
- * @returns 0 on success and negative value for failure.
- */
-int setChannel(Interface& interface, int package, int channel);
-
-/* @brief This function will ask underlying NCSI driver
- * to clear any preferred setting from the given
- * interface.
- * This function talks with the NCSI driver over
- * netlink messages.
- * @param[in] interface - Interface
- * @returns 0 on success and negative value for failure.
- */
-int clearInterface(Interface& interface);
-
-/* @brief This function is used to dump all the info
- * of the package and the channels underlying
- * the package.
- * @param[in] interface - Interface
- * @param[in] package - NCSI Package.
- * @returns 0 on success and negative value for failure.
- */
-int getInfo(Interface& interface, int package);
-
-/* @brief This function assigns a mask controlling responses to AEN from a
- * package.
- * @param[in] ifindex - Interface Index.
- * @param[in] mask - A 32-bit mask integer
- * @returns 0 on success and negative value for failure.
- */
-int setPackageMask(Interface& interface, unsigned int mask);
-
-/* @brief This function sets the AEN mask for the channels inside the selected
- * package.
- * @param[in] ifindex - Interface Index.
- * @param[in] package - NCSI Package.
- * @param[in] mask - A 32-bit mask integer
- * @returns 0 on success and negative value for failure.
- */
-int setChannelMask(Interface& interface, int package, unsigned int mask);
-
} // namespace ncsi
} // namespace network
} // namespace phosphor