IPMI Channel commands implementation

IPMI Channel commands implemenation - squashed

commit e9a75d8dd6e89d17381f0310c7930586c6b79996
Author: AppaRao Puli <apparao.puli@intel.com>
Date:   Thu Jul 5 14:47:22 2018 +0530

    Channel layer separation

    De-coupling the channel management from ipmi channel commands
    implementation. This gives flexibility to load only needed
    stuff in different modules(host-ipmi or netipmid)

    Change-Id: Ib334562beb9325f7768ed6a15475cae15af17b19
    Signed-off-by: AppaRao Puli <apparao.puli@intel.com>
    Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>

commit 726ddf2af678ea6773f4b4b918fbd49be8c83e6a
Author: AppaRao Puli <apparao.puli@intel.com>
Date:   Thu May 24 16:45:30 2018 +0530

    IPMI Channel commands implementation

    Following IPMI channel commands are implemented.
     1) Set channel access (0x40)
     2) Get channel access (0x41)
     3) Get channel info (0x42)

    Also added code supported for LAN configuration parameters
     1) Authentication Type Support (selector #1)
     2) Authentication Type Enables (selector #2)

    Change-Id: Ic4156378c7756eca383dc3da52114fd119346ca6
    Signed-off-by: AppaRao Puli <apparao.puli@intel.com>
    Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>

Change-Id: Ic4156378c7756eca383dc3da52114fd119346ca6
Signed-off-by: AppaRao Puli <apparao.puli@intel.com>
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/user_channel/channel_layer.cpp b/user_channel/channel_layer.cpp
new file mode 100644
index 0000000..32f4ded
--- /dev/null
+++ b/user_channel/channel_layer.cpp
@@ -0,0 +1,131 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include "channel_layer.hpp"
+
+#include "channel_mgmt.hpp"
+
+#include <phosphor-logging/log.hpp>
+
+namespace ipmi
+{
+
+bool doesDeviceExist(const uint8_t& chNum)
+{
+    // TODO: This is not the reliable way to find the device
+    // associated with ethernet interface as the channel number to
+    // eth association is not done. Need to revisit later
+    struct stat fileStat;
+    std::string devName("/sys/class/net/eth");
+    devName += std::to_string(chNum - 1);
+
+    if (stat(devName.data(), &fileStat) != 0)
+    {
+        phosphor::logging::log<phosphor::logging::level::DEBUG>(
+            "Ethernet device not found");
+        return false;
+    }
+
+    return true;
+}
+
+bool isValidPrivLimit(const uint8_t& privLimit)
+{
+    return ((privLimit >= PRIVILEGE_CALLBACK) && (privLimit <= PRIVILEGE_OEM));
+}
+
+bool isValidAccessMode(const uint8_t& accessMode)
+{
+    return (
+        (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) &&
+        (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared)));
+}
+
+bool isValidChannel(const uint8_t& chNum)
+{
+    return getChannelConfigObject().isValidChannel(chNum);
+}
+
+bool isValidAuthType(const uint8_t& chNum, const EAuthType& authType)
+{
+    return getChannelConfigObject().isValidAuthType(chNum, authType);
+}
+
+EChannelSessSupported getChannelSessionSupport(const uint8_t& chNum)
+{
+    return getChannelConfigObject().getChannelSessionSupport(chNum);
+}
+
+int getChannelActiveSessions(const uint8_t& chNum)
+{
+    return getChannelConfigObject().getChannelActiveSessions(chNum);
+}
+
+ipmi_ret_t ipmiChannelInit()
+{
+    getChannelConfigObject();
+    return IPMI_CC_OK;
+}
+
+ipmi_ret_t getChannelInfo(const uint8_t& chNum, ChannelInfo& chInfo)
+{
+    return getChannelConfigObject().getChannelInfo(chNum, chInfo);
+}
+
+ipmi_ret_t getChannelAccessData(const uint8_t& chNum,
+                                ChannelAccess& chAccessData)
+{
+    return getChannelConfigObject().getChannelAccessData(chNum, chAccessData);
+}
+
+ipmi_ret_t setChannelAccessData(const uint8_t& chNum,
+                                const ChannelAccess& chAccessData,
+                                const uint8_t& setFlag)
+{
+    return getChannelConfigObject().setChannelAccessData(chNum, chAccessData,
+                                                         setFlag);
+}
+
+ipmi_ret_t getChannelAccessPersistData(const uint8_t& chNum,
+                                       ChannelAccess& chAccessData)
+{
+    return getChannelConfigObject().getChannelAccessPersistData(chNum,
+                                                                chAccessData);
+}
+
+ipmi_ret_t setChannelAccessPersistData(const uint8_t& chNum,
+                                       const ChannelAccess& chAccessData,
+                                       const uint8_t& setFlag)
+{
+    return getChannelConfigObject().setChannelAccessPersistData(
+        chNum, chAccessData, setFlag);
+}
+
+ipmi_ret_t getChannelAuthTypeSupported(const uint8_t& chNum,
+                                       uint8_t& authTypeSupported)
+{
+    return getChannelConfigObject().getChannelAuthTypeSupported(
+        chNum, authTypeSupported);
+}
+
+ipmi_ret_t getChannelEnabledAuthType(const uint8_t& chNum, const uint8_t& priv,
+                                     EAuthType& authType)
+{
+    return getChannelConfigObject().getChannelEnabledAuthType(chNum, priv,
+                                                              authType);
+}
+
+} // namespace ipmi