Added suppport to convert self channel number.

Define API for getting self channel number.

Change-Id: I4027f580f30bd2ba84b11260f11f86eb8e9af1ff
Signed-off-by: ssekar <suryakanth.sekar@intel.com>
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/user_channel/channel_layer.hpp b/user_channel/channel_layer.hpp
index 4c931df..fa15378 100644
--- a/user_channel/channel_layer.hpp
+++ b/user_channel/channel_layer.hpp
@@ -22,6 +22,7 @@
 {
 
 static constexpr uint8_t maxIpmiChannels = 16;
+static constexpr uint8_t selfChNum = 0xE;
 
 // IPMI return codes specific to channel
 enum ipmi_channel_return_codes
diff --git a/user_channel/channel_mgmt.cpp b/user_channel/channel_mgmt.cpp
index 4cae923..fc2ca1b 100644
--- a/user_channel/channel_mgmt.cpp
+++ b/user_channel/channel_mgmt.cpp
@@ -106,6 +106,11 @@
     {"oem", EChannelMediumType::oem},
     {"unknown", EChannelMediumType::unknown}};
 
+static std::unordered_map<EInterfaceIndex, std::string> interfaceMap = {
+    {interfaceKCS, "KCS"},
+    {interfaceLAN1, "LAN1"},
+    {interfaceUnknown, "unknown"}};
+
 static std::unordered_map<std::string, EChannelProtocolType> protocolTypeMap = {
     {"na", EChannelProtocolType::na},
     {"ipmb-1.0", EChannelProtocolType::ipmbV10},
@@ -791,6 +796,39 @@
     return static_cast<EChannelProtocolType>(it->second);
 }
 
+uint8_t ChannelConfig::convertToChannelIndexNumber(const uint8_t& chNum)
+{
+
+    // TODO: There is limitation in current design. we cannot detect exact
+    // LAN interface(eth0 or eth1) so Implementation may be updated
+    // when there is any design update to figure out all the interfaces
+    // independently based on the message.
+
+    static uint8_t curChannel = 0xFF;
+
+    if (curChannel == 0xFF)
+    {
+        auto it = interfaceMap.find(getInterfaceIndex());
+        if (it == interfaceMap.end())
+        {
+            log<level::ERR>("Invalid Interface type ",
+                            entry("InterfaceIndex: %d", getInterfaceIndex()));
+            throw std::invalid_argument("Invalid interface type.");
+        }
+
+        for (auto& channel : channelData)
+        {
+            std::string& interfaceName = it->second;
+            if (channel.chName == interfaceName)
+            {
+                curChannel = channel.chID;
+                break;
+            }
+        }
+    }
+    return ((chNum == selfChNum) ? curChannel : chNum);
+}
+
 std::string ChannelConfig::convertToNetInterface(const std::string& value)
 {
     auto it = channelToInterfaceMap.find(value);