Add Set Package and Channel Mask to ncsi-netlink utility

The NCSI driver has added two commands for setting the Package Mask
and the Channel Mask within a package. The ncsi-netlink utility does
not support these new commands.

Add the ability to set the package and the channel mask values.

Tested:
Instrumented the NCSI kernel driver to print mask values.
Issued 'ncsi-netlink -x 3 -j 0x3' and saw the NCSI driver print the
new package mask.
Issued 'ncsi-netlink -x 3 -p 0 -k 0x3' and saw the NCSI driver
print the new channel mask.

Change-Id: Icd2188e789de43f631fe26d9e751d564ba5f822f
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/src/ncsi_util.cpp b/src/ncsi_util.cpp
index 839c80d..c3d3794 100644
--- a/src/ncsi_util.cpp
+++ b/src/ncsi_util.cpp
@@ -9,8 +9,6 @@
 #include <stdplus/numeric/str.hpp>
 #include <stdplus/str/buf.hpp>
 
-#include <iomanip>
-#include <iostream>
 #include <vector>
 
 namespace phosphor
@@ -344,7 +342,29 @@
         return ret;
     }
 
-    if (cmd.operation != DEFAULT_VALUE)
+    if ((cmd.ncsi_cmd == ncsi_nl_commands::NCSI_CMD_SET_PACKAGE_MASK) ||
+        (cmd.ncsi_cmd == ncsi_nl_commands::NCSI_CMD_SET_CHANNEL_MASK))
+    {
+        if (cmd.payload.size() != sizeof(unsigned int))
+        {
+            lg2::error("Package/Channel mask must be 32-bits");
+            return -EINVAL;
+        }
+        int maskAttr =
+            cmd.ncsi_cmd == ncsi_nl_commands::NCSI_CMD_SET_PACKAGE_MASK
+                ? NCSI_ATTR_PACKAGE_MASK
+                : NCSI_ATTR_CHANNEL_MASK;
+        ret = nla_put_u32(
+            msg.get(), maskAttr,
+            *(reinterpret_cast<const unsigned int*>(cmd.payload.data())));
+        if (ret < 0)
+        {
+            lg2::error("Failed to set the mask attribute, RC : {RC}", "RC",
+                       ret);
+            return ret;
+        }
+    }
+    else if (cmd.ncsi_cmd == ncsi_nl_commands::NCSI_CMD_SEND_CMD)
     {
         std::vector<unsigned char> pl(
             sizeof(NCSIPacketHeader) + cmd.payload.size());
@@ -457,6 +477,36 @@
     }
 }
 
+int setPackageMask(int ifindex, unsigned int mask)
+{
+    lg2::debug(
+        "Set Package Mask , INTERFACE_INDEX: {INTERFACE_INDEX} MASK: {MASK}",
+        "INTERFACE_INDEX", lg2::hex, ifindex, "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(
+        ifindex, internal::Command(ncsi_nl_commands::NCSI_CMD_SET_PACKAGE_MASK,
+                                   0, payload));
+}
+
+int setChannelMask(int ifindex, int package, unsigned int mask)
+{
+    lg2::debug(
+        "Set Channel Mask , INTERFACE_INDEX: {INTERFACE_INDEX}, PACKAGE : {PACKAGE} MASK: {MASK}",
+        "INTERFACE_INDEX", lg2::hex, ifindex, "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(
+        ifindex,
+        internal::Command(ncsi_nl_commands::NCSI_CMD_SET_CHANNEL_MASK, 0,
+                          payload),
+        package);
+    return 0;
+}
+
 } // namespace ncsi
 } // namespace network
 } // namespace phosphor