Added Cipher Suite priv param-24 to set/get LanCfg

IPMI Spec. 23.1(Set lan configuration) and 23.2(get lan configuration)
refers to set and get (write and read) privileges through set and get
lan configuration command using parameter 24 (0x18, RMCP+ Messaging
Cipher Suite Privilege Levels).

This patch allows us to create/update user setting Cipher Suite
privilege levels file.

This patch makes set/get Cipher Suite Privilege Level parameter data
to be persistent. Supports set and get Cipher Suite privilege levels
command for any channel.

Tested:
Set Lan config:
Command: ipmitool raw 0x0c 0x01 0x03 0x18 0x00 0x34 0x43 0x44 0x33 0x44
         0x44 0x44 0x44
Response:                       //Success

Get Lan config:
Command:  ipmitool  raw 0x0c 0x02 0x03 0x18 0x01 0x01
Response: 11 00 34 43 44 33 44 44 44 44

Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
Change-Id: I1357af820bd1082bda208aef3918be8c31bf1af3
diff --git a/user_channel/cipher_mgmt.cpp b/user_channel/cipher_mgmt.cpp
index 19dca48..ca9c2d4 100644
--- a/user_channel/cipher_mgmt.cpp
+++ b/user_channel/cipher_mgmt.cpp
@@ -22,7 +22,6 @@
 
 #include <filesystem>
 #include <fstream>
-#include <include/ipmid/api-types.hpp>
 #include <phosphor-logging/log.hpp>
 
 namespace ipmi
@@ -174,4 +173,72 @@
     return ipmi::privList.at(static_cast<size_t>(value));
 }
 
+ipmi::Cc CipherConfig::getCSPrivilegeLevels(
+    uint8_t chNum, std::array<uint4_t, maxCSRecords>& csPrivilegeLevels)
+{
+    if (!isValidChannel(chNum))
+    {
+        log<level::ERR>("Invalid channel number", entry("CHANNEL=%u", chNum));
+        return ccInvalidFieldRequest;
+    }
+
+    for (size_t csNum = 0; csNum < maxCSRecords; ++csNum)
+    {
+        csPrivilegeLevels[csNum] = csPrivilegeMap[{chNum, csNum}];
+    }
+    return ccSuccess;
+}
+
+ipmi::Cc CipherConfig::setCSPrivilegeLevels(
+    uint8_t chNum, const std::array<uint4_t, maxCSRecords>& requestData)
+{
+    if (!isValidChannel(chNum))
+    {
+        log<level::ERR>("Invalid channel number", entry("CHANNEL=%u", chNum));
+        return ccInvalidFieldRequest;
+    }
+
+    Json jsonData;
+    if (!fs::exists(cipherSuitePrivFileName))
+    {
+        log<level::INFO>("CS privilege levels user settings file does not "
+                         "exist. Creating...");
+    }
+    else
+    {
+        jsonData = readCSPrivilegeLevels(cipherSuitePrivFileName);
+        if (jsonData == nullptr)
+        {
+            return ccUnspecifiedError;
+        }
+    }
+
+    Json privData;
+    std::string csKey;
+    constexpr auto privMaxValue = static_cast<uint8_t>(ipmi::Privilege::Oem);
+    for (size_t csNum = 0; csNum < maxCSRecords; ++csNum)
+    {
+        csKey = "CipherID" + std::to_string(csNum);
+        auto priv = static_cast<uint8_t>(requestData[csNum]);
+
+        if (priv > privMaxValue)
+        {
+            return ccInvalidFieldRequest;
+        }
+        privData[csKey] = convertToPrivLimitString(priv);
+    }
+
+    std::string chKey = "Channel" + std::to_string(chNum);
+    jsonData[chKey] = privData;
+
+    if (writeCSPrivilegeLevels(jsonData))
+    {
+        log<level::ERR>("Error in setting CS Privilege Levels.");
+        return ccUnspecifiedError;
+    }
+
+    updateCSPrivilegesMap(jsonData);
+    return ccSuccess;
+}
+
 } // namespace ipmi