IPMI channel to NIC device mapping modified within JSON config file

The IPMI to NIC channel mapping was done using a hard coded scheme.
The scheme used generic channel names which were then mapped to
specific device names.  The hard coded generic to specific naming
convention is removed, and the JSON file contains the device name
directly.

Change-Id: Ibc6821cae5a26f2666467aba5346d364053f2582
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/user_channel/channel_mgmt.cpp b/user_channel/channel_mgmt.cpp
index 45a703a..585d441 100644
--- a/user_channel/channel_mgmt.cpp
+++ b/user_channel/channel_mgmt.cpp
@@ -137,7 +137,36 @@
     "priv-reserved", "priv-callback", "priv-user",
     "priv-operator", "priv-admin",    "priv-oem"};
 
-std::string getNetIntfFromPath(const std::string& path)
+std::string ChannelConfig::getChannelName(const int chNum)
+{
+    if (!isValidChannel(chNum))
+    {
+        log<level::ERR>("Invalid channel number.",
+                        entry("ChannelID:%d", chNum));
+        throw std::invalid_argument("Invalid channel number");
+    }
+
+    return channelData[chNum].chName;
+}
+
+int ChannelConfig::convertToChannelNumberFromChannelName(
+    const std::string& chName)
+{
+    for (const auto& it : channelData)
+    {
+        if (it.chName == chName)
+        {
+            return it.chID;
+        }
+    }
+    log<level::ERR>("Invalid channel name.",
+                    entry("Channel:%s", chName.c_str()));
+    throw std::invalid_argument("Invalid channel name");
+
+    return -1;
+}
+
+std::string ChannelConfig::getChannelNameFromPath(const std::string& path)
 {
     std::size_t pos = path.find(networkIntfObjectBasePath);
     if (pos == std::string::npos)
@@ -146,19 +175,19 @@
                         entry("PATH:%s", path.c_str()));
         throw std::invalid_argument("Invalid interface path");
     }
-    std::string intfName =
+    std::string chName =
         path.substr(pos + strlen(networkIntfObjectBasePath) + 1);
-    return intfName;
+    return chName;
 }
 
 void ChannelConfig::processChAccessPropChange(
     const std::string& path, const DbusChObjProperties& chProperties)
 {
     // Get interface name from path. ex: '/xyz/openbmc_project/network/eth0'
-    std::string channelName;
+    std::string chName;
     try
     {
-        channelName = getNetIntfFromPath(path);
+        chName = getChannelNameFromPath(path);
     }
     catch (const std::invalid_argument& e)
     {
@@ -188,14 +217,16 @@
     if (intfPrivStr.empty())
     {
         log<level::ERR>("Invalid privilege string.",
-                        entry("INTF:%s", channelName.c_str()));
+                        entry("INTF:%s", chName.c_str()));
         return;
     }
 
     uint8_t intfPriv = 0;
+    int chNum;
     try
     {
         intfPriv = static_cast<uint8_t>(convertToPrivLimitIndex(intfPrivStr));
+        chNum = convertToChannelNumberFromChannelName(chName);
     }
     catch (const std::invalid_argument& e)
     {
@@ -205,21 +236,6 @@
 
     boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
         channelLock{*channelMutex};
-    uint8_t chNum = 0;
-    // Get the channel number based on the channel name.
-    for (chNum = 0; chNum < maxIpmiChannels; chNum++)
-    {
-        if (channelData[chNum].chName == channelName)
-        {
-            break;
-        }
-    }
-    if (chNum >= maxIpmiChannels)
-    {
-        log<level::ERR>("Invalid interface in signal path");
-        return;
-    }
-
     // skip updating the values, if this property change originated from IPMI.
     if (signalFlag & (1 << chNum))
     {