summaryrefslogtreecommitdiffstats
path: root/user_channel/channel_mgmt.hpp
diff options
context:
space:
mode:
authorAppaRao Puli <apparao.puli@intel.com>2018-05-24 16:45:30 +0530
committerRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2018-11-20 10:09:26 +0530
commit071f3f2f298ab4a4799b7fcdba3255dfd999452d (patch)
treee56a267bf7e4eca8efc008d3a3d8b4b405268fcd /user_channel/channel_mgmt.hpp
parentb849110d32da5ca61f165abf553eac5b383d4f69 (diff)
downloadphosphor-host-ipmid-071f3f2f298ab4a4799b7fcdba3255dfd999452d.tar.gz
phosphor-host-ipmid-071f3f2f298ab4a4799b7fcdba3255dfd999452d.zip
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>
Diffstat (limited to 'user_channel/channel_mgmt.hpp')
-rw-r--r--user_channel/channel_mgmt.hpp334
1 files changed, 334 insertions, 0 deletions
diff --git a/user_channel/channel_mgmt.hpp b/user_channel/channel_mgmt.hpp
new file mode 100644
index 0000000..053fa39
--- /dev/null
+++ b/user_channel/channel_mgmt.hpp
@@ -0,0 +1,334 @@
+/*
+// 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.
+*/
+
+#pragma once
+#include "channel_layer.hpp"
+
+#include <boost/interprocess/sync/file_lock.hpp>
+#include <boost/interprocess/sync/named_recursive_mutex.hpp>
+#include <cstdint>
+#include <ctime>
+#include <nlohmann/json.hpp>
+#include <sdbusplus/bus.hpp>
+
+namespace ipmi
+{
+
+using Json = nlohmann::json;
+
+static constexpr const char* ipmiChannelMutex = "ipmi_channel_mutex";
+static constexpr const char* ipmiChMutexCleanupLockFile =
+ "/var/lib/ipmi/ipmi_channel_mutex_cleanup";
+
+struct ChannelAccessData
+{
+ ChannelAccess chNonVolatileData;
+ ChannelAccess chVolatileData;
+};
+
+struct ChannelData
+{
+ std::string chName;
+ uint8_t chID;
+ bool isChValid;
+ uint8_t activeSessCount;
+ ChannelInfo chInfo;
+ ChannelAccessData chAccess;
+};
+
+class ChannelConfig;
+
+ChannelConfig& getChannelConfigObject();
+
+class ChannelConfig
+{
+ public:
+ ChannelConfig(const ChannelConfig&) = delete;
+ ChannelConfig& operator=(const ChannelConfig&) = delete;
+ ChannelConfig(ChannelConfig&&) = delete;
+ ChannelConfig& operator=(ChannelConfig&&) = delete;
+
+ ~ChannelConfig() = default;
+ ChannelConfig();
+
+ /** @brief determines valid channel
+ *
+ * @param[in] chNum - channel number
+ *
+ * @return true if valid, false otherwise
+ */
+ bool isValidChannel(const uint8_t& chNum);
+
+ /** @brief determines valid authentication type
+ *
+ * @param[in] chNum - channel number
+ * @param[in] authType - authentication type
+ *
+ * @return true if valid, false otherwise
+ */
+ bool isValidAuthType(const uint8_t& chNum, const EAuthType& authType);
+
+ /** @brief determines supported session type of a channel
+ *
+ * @param[in] chNum - channel number
+ *
+ * @return EChannelSessSupported - supported session type
+ */
+ EChannelSessSupported getChannelSessionSupport(const uint8_t& chNum);
+
+ /** @brief determines number of active sessions on a channel
+ *
+ * @param[in] chNum - channel number
+ *
+ * @return numer of active sessions
+ */
+ int getChannelActiveSessions(const uint8_t& chNum);
+
+ /** @brief provides channel info details
+ *
+ * @param[in] chNum - channel number
+ * @param[out] chInfo - channel info details
+ *
+ * @return IPMI_CC_OK for success, others for failure.
+ */
+ ipmi_ret_t getChannelInfo(const uint8_t& chNum, ChannelInfo& chInfo);
+
+ /** @brief provides channel access data
+ *
+ * @param[in] chNum - channel number
+ * @param[out] chAccessData - channel access data
+ *
+ * @return IPMI_CC_OK for success, others for failure.
+ */
+ ipmi_ret_t getChannelAccessData(const uint8_t& chNum,
+ ChannelAccess& chAccessData);
+
+ /** @brief to set channel access data
+ *
+ * @param[in] chNum - channel number
+ * @param[in] chAccessData - channel access data
+ * @param[in] setFlag - flag to indicate updatable fields
+ *
+ * @return IPMI_CC_OK for success, others for failure.
+ */
+ ipmi_ret_t setChannelAccessData(const uint8_t& chNum,
+ const ChannelAccess& chAccessData,
+ const uint8_t& setFlag);
+
+ /** @brief to get channel access data persistent data
+ *
+ * @param[in] chNum - channel number
+ * @param[out] chAccessData - channel access data
+ *
+ * @return IPMI_CC_OK for success, others for failure.
+ */
+ ipmi_ret_t getChannelAccessPersistData(const uint8_t& chNum,
+ ChannelAccess& chAccessData);
+
+ /** @brief to set channel access data persistent data
+ *
+ * @param[in] chNum - channel number
+ * @param[in] chAccessData - channel access data
+ * @param[in] setFlag - flag to indicate updatable fields
+ *
+ * @return IPMI_CC_OK for success, others for failure.
+ */
+ ipmi_ret_t setChannelAccessPersistData(const uint8_t& chNum,
+ const ChannelAccess& chAccessData,
+ const uint8_t& setFlag);
+
+ /** @brief provides supported authentication type for the channel
+ *
+ * @param[in] chNum - channel number
+ * @param[out] authTypeSupported - supported authentication type
+ *
+ * @return IPMI_CC_OK for success, others for failure.
+ */
+ ipmi_ret_t getChannelAuthTypeSupported(const uint8_t& chNum,
+ uint8_t& authTypeSupported);
+
+ /** @brief provides enabled authentication type for the channel
+ *
+ * @param[in] chNum - channel number
+ * @param[in] priv - privilege
+ * @param[out] authType - enabled authentication type
+ *
+ * @return IPMI_CC_OK for success, others for failure.
+ */
+ ipmi_ret_t getChannelEnabledAuthType(const uint8_t& chNum,
+ const uint8_t& priv,
+ EAuthType& authType);
+
+ std::unique_ptr<boost::interprocess::named_recursive_mutex> channelMutex{
+ nullptr};
+
+ private:
+ ChannelData channelData[maxIpmiChannels];
+ std::time_t nvFileLastUpdatedTime;
+ std::time_t voltFileLastUpdatedTime;
+ std::time_t getUpdatedFileTime(const std::string& fileName);
+ boost::interprocess::file_lock mutexCleanupLock;
+ sdbusplus::bus::bus bus;
+
+ /** @brief function to initialize persistent channel configuration
+ *
+ */
+ void initChannelPersistData();
+
+ /** @brief function to set default channel configuration based on channel
+ * number
+ *
+ * @param[in] chNum - channel number
+ * @param[in] chName - channel name
+ */
+ void setDefaultChannelConfig(const uint8_t& chNum,
+ const std::string& chName);
+
+ /** @brief function to load all channel configuration
+ *
+ * @return 0 for success, -errno for failure.
+ */
+ int loadChannelConfig();
+
+ /** @brief function to read persistent channel data
+ *
+ * @return 0 for success, -errno for failure.
+ */
+ int readChannelPersistData();
+
+ /** @brief function to write persistent channel configuration to config file
+ *
+ * @return 0 for success, -errno for failure.
+ */
+ int writeChannelPersistData();
+
+ /** @brief function to read volatile channel data
+ *
+ * @return 0 for success, -errno for failure.
+ */
+ int readChannelVolatileData();
+
+ /** @brief function to write volatile channel configuration to config file
+ *
+ * @return 0 for success, -errno for failure.
+ */
+ int writeChannelVolatileData();
+
+ /** @brief function to check and reload persistent channel data
+ *
+ * @return 0 for success, -errno for failure.
+ */
+ int checkAndReloadNVData();
+
+ /** @brief function to check and reload volatile channel data
+ *
+ * @return 0 for success, -errno for failure.
+ */
+ int checkAndReloadVolatileData();
+
+ /** @brief function to read json config file
+ *
+ * @param[in] configFile - configuration file name
+ *
+ * @return Json object
+ */
+ Json readJsonFile(const std::string& configFile);
+
+ /** @brief function to write json config file
+ *
+ * @param[in] configFile - configuration file name
+ * @param[in] jsonData - json object
+ *
+ * @return 0 for success, -errno for failure.
+ */
+ int writeJsonFile(const std::string& configFile, const Json& jsonData);
+
+ /** @brief function to convert system access mode to Channel access mode
+ * type
+ *
+ * @param[in] mode - access mode in string
+ *
+ * @return Channel access mode.
+ */
+ EChannelAccessMode convertToAccessModeIndex(const std::string& mode);
+
+ /** @brief function to convert access mode value to string
+ *
+ * @param[in] value - acess mode value
+ *
+ * @return access mode in string
+ */
+ std::string convertToAccessModeString(const uint8_t& value);
+
+ /** @brief conver to channel privilege from system privilege
+ *
+ * @param[in] value - privilege value
+ *
+ * @return Channel privilege
+ */
+ CommandPrivilege convertToPrivLimitIndex(const std::string& value);
+
+ /** @brief function to convert privilege value to string
+ *
+ * @param[in] value - privilege value
+ *
+ * @return privilege in string
+ */
+ std::string convertToPrivLimitString(const uint8_t& value);
+
+ /** @brief function to convert session support string to value type
+ *
+ * @param[in] value - session support type in string
+ *
+ * @return support session type
+ */
+ EChannelSessSupported
+ convertToSessionSupportIndex(const std::string& value);
+
+ /** @brief function to convert medium type string to value type
+ *
+ * @param[in] value - medium type in string
+ *
+ * @return channel medium type
+ */
+ EChannelMediumType convertToMediumTypeIndex(const std::string& value);
+
+ /** @brief function to convert protocol type string to value type
+ *
+ * @param[in] value - protocol type in string
+ *
+ * @return channel protocol type
+ */
+ EChannelProtocolType convertToProtocolTypeIndex(const std::string& value);
+
+ /** @brief function to convert channel number to channel index
+ *
+ * @param[in] chNum - channel number
+ *
+ * @return channel index
+ */
+ uint8_t convertToChannelIndexNumber(const uint8_t& chNum);
+
+ /** @brief function to convert channel name to network interface name
+ *
+ * @param[in] value - channel interface name - ipmi centric
+ *
+ * @return network channel interface name
+ */
+ std::string convertToNetInterface(const std::string& value);
+};
+
+} // namespace ipmi
OpenPOWER on IntegriCloud