blob: ac907deec1153ecb309a33d489416e5276a8dc9e [file] [log] [blame]
AppaRao Puli071f3f22018-05-24 16:45:30 +05301/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#include "channel_mgmt.hpp"
18
19#include "apphandler.hpp"
Johnathan Manteyfd61fc32021-04-08 11:05:38 -070020#include "user_layer.hpp"
AppaRao Puli071f3f22018-05-24 16:45:30 +053021
Johnathan Mantey0a2abc82021-02-18 12:39:12 -080022#include <ifaddrs.h>
AppaRao Puli071f3f22018-05-24 16:45:30 +053023#include <sys/stat.h>
Johnathan Mantey0a2abc82021-02-18 12:39:12 -080024#include <sys/types.h>
AppaRao Puli071f3f22018-05-24 16:45:30 +053025#include <unistd.h>
26
27#include <boost/interprocess/sync/scoped_lock.hpp>
George Liu42f64ef2024-02-05 15:03:18 +080028#include <ipmid/utils.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050029#include <phosphor-logging/log.hpp>
30#include <sdbusplus/bus/match.hpp>
31#include <sdbusplus/server/object.hpp>
32
AppaRao Puli071f3f22018-05-24 16:45:30 +053033#include <cerrno>
AppaRao Puli9613ed72018-09-01 23:46:44 +053034#include <exception>
Patrick Williams3d8d7932022-06-16 12:01:28 -050035#include <filesystem>
AppaRao Puli071f3f22018-05-24 16:45:30 +053036#include <fstream>
AppaRao Puli071f3f22018-05-24 16:45:30 +053037#include <unordered_map>
38
39namespace ipmi
40{
41
42using namespace phosphor::logging;
43
44static constexpr const char* channelAccessDefaultFilename =
45 "/usr/share/ipmi-providers/channel_access.json";
46static constexpr const char* channelConfigDefaultFilename =
47 "/usr/share/ipmi-providers/channel_config.json";
48static constexpr const char* channelNvDataFilename =
49 "/var/lib/ipmi/channel_access_nv.json";
50static constexpr const char* channelVolatileDataFilename =
51 "/run/ipmi/channel_access_volatile.json";
52
AppaRao Puli9613ed72018-09-01 23:46:44 +053053// TODO: Get the service name dynamically..
54static constexpr const char* networkIntfServiceName =
55 "xyz.openbmc_project.Network";
56static constexpr const char* networkIntfObjectBasePath =
57 "/xyz/openbmc_project/network";
58static constexpr const char* networkChConfigIntfName =
59 "xyz.openbmc_project.Channel.ChannelAccess";
60static constexpr const char* privilegePropertyString = "MaxPrivilege";
61static constexpr const char* dBusPropertiesInterface =
62 "org.freedesktop.DBus.Properties";
63static constexpr const char* propertiesChangedSignal = "PropertiesChanged";
Willy Tuac05aa12021-11-16 21:15:58 -080064static constexpr const char* interfaceAddedSignal = "InterfacesAdded";
65static constexpr const char* interfaceRemovedSignal = "InterfacesRemoved";
AppaRao Puli9613ed72018-09-01 23:46:44 +053066
AppaRao Puli071f3f22018-05-24 16:45:30 +053067// STRING DEFINES: Should sync with key's in JSON
68static constexpr const char* nameString = "name";
69static constexpr const char* isValidString = "is_valid";
70static constexpr const char* activeSessionsString = "active_sessions";
Vernon Mauery58317122018-11-28 11:02:43 -080071static constexpr const char* maxTransferSizeString = "max_transfer_size";
AppaRao Puli071f3f22018-05-24 16:45:30 +053072static constexpr const char* channelInfoString = "channel_info";
73static constexpr const char* mediumTypeString = "medium_type";
74static constexpr const char* protocolTypeString = "protocol_type";
75static constexpr const char* sessionSupportedString = "session_supported";
76static constexpr const char* isIpmiString = "is_ipmi";
Johnathan Manteyfd61fc32021-04-08 11:05:38 -070077static constexpr const char* isManagementNIC = "is_management_nic";
AppaRao Puli071f3f22018-05-24 16:45:30 +053078static constexpr const char* authTypeSupportedString = "auth_type_supported";
79static constexpr const char* accessModeString = "access_mode";
80static constexpr const char* userAuthDisabledString = "user_auth_disabled";
81static constexpr const char* perMsgAuthDisabledString = "per_msg_auth_disabled";
82static constexpr const char* alertingDisabledString = "alerting_disabled";
83static constexpr const char* privLimitString = "priv_limit";
84static constexpr const char* authTypeEnabledString = "auth_type_enabled";
85
86// Default values
87static constexpr const char* defaultChannelName = "RESERVED";
88static constexpr const uint8_t defaultMediumType =
89 static_cast<uint8_t>(EChannelMediumType::reserved);
90static constexpr const uint8_t defaultProtocolType =
91 static_cast<uint8_t>(EChannelProtocolType::reserved);
92static constexpr const uint8_t defaultSessionSupported =
93 static_cast<uint8_t>(EChannelSessSupported::none);
94static constexpr const uint8_t defaultAuthType =
95 static_cast<uint8_t>(EAuthType::none);
96static constexpr const bool defaultIsIpmiState = false;
Vernon Mauery58317122018-11-28 11:02:43 -080097static constexpr size_t smallChannelSize = 64;
AppaRao Puli071f3f22018-05-24 16:45:30 +053098
Lei YU4b0ddb62019-01-25 16:43:50 +080099std::unique_ptr<sdbusplus::bus::match_t> chPropertiesSignal
100 __attribute__((init_priority(101)));
AppaRao Puli9613ed72018-09-01 23:46:44 +0530101
Willy Tuac05aa12021-11-16 21:15:58 -0800102std::unique_ptr<sdbusplus::bus::match_t> chInterfaceAddedSignal
103 __attribute__((init_priority(101)));
104
105std::unique_ptr<sdbusplus::bus::match_t> chInterfaceRemovedSignal
106 __attribute__((init_priority(101)));
107
AppaRao Puli071f3f22018-05-24 16:45:30 +0530108// String mappings use in JSON config file
109static std::unordered_map<std::string, EChannelMediumType> mediumTypeMap = {
110 {"reserved", EChannelMediumType::reserved},
111 {"ipmb", EChannelMediumType::ipmb},
112 {"icmb-v1.0", EChannelMediumType::icmbV10},
113 {"icmb-v0.9", EChannelMediumType::icmbV09},
114 {"lan-802.3", EChannelMediumType::lan8032},
115 {"serial", EChannelMediumType::serial},
116 {"other-lan", EChannelMediumType::otherLan},
117 {"pci-smbus", EChannelMediumType::pciSmbus},
118 {"smbus-v1.0", EChannelMediumType::smbusV11},
119 {"smbus-v2.0", EChannelMediumType::smbusV20},
120 {"usb-1x", EChannelMediumType::usbV1x},
121 {"usb-2x", EChannelMediumType::usbV2x},
122 {"system-interface", EChannelMediumType::systemInterface},
123 {"oem", EChannelMediumType::oem},
124 {"unknown", EChannelMediumType::unknown}};
125
ssekarf4b2b092018-07-25 18:49:08 +0530126static std::unordered_map<EInterfaceIndex, std::string> interfaceMap = {
Richard Marian Thomaiyar43cb1282018-12-08 17:22:53 +0530127 {interfaceKCS, "SMS"},
Richard Marian Thomaiyar73906b92019-01-04 23:48:02 +0530128 {interfaceLAN1, "eth0"},
ssekarf4b2b092018-07-25 18:49:08 +0530129 {interfaceUnknown, "unknown"}};
130
AppaRao Puli071f3f22018-05-24 16:45:30 +0530131static std::unordered_map<std::string, EChannelProtocolType> protocolTypeMap = {
132 {"na", EChannelProtocolType::na},
133 {"ipmb-1.0", EChannelProtocolType::ipmbV10},
134 {"icmb-2.0", EChannelProtocolType::icmbV11},
135 {"reserved", EChannelProtocolType::reserved},
136 {"ipmi-smbus", EChannelProtocolType::ipmiSmbus},
137 {"kcs", EChannelProtocolType::kcs},
138 {"smic", EChannelProtocolType::smic},
139 {"bt-10", EChannelProtocolType::bt10},
140 {"bt-15", EChannelProtocolType::bt15},
141 {"tmode", EChannelProtocolType::tMode},
142 {"oem", EChannelProtocolType::oem}};
143
144static std::array<std::string, 4> accessModeList = {
145 "disabled", "pre-boot", "always_available", "shared"};
146
147static std::array<std::string, 4> sessionSupportList = {
148 "session-less", "single-session", "multi-session", "session-based"};
149
Sumanth Bhate4e633e2019-05-14 12:13:57 +0000150const std::array<std::string, PRIVILEGE_OEM + 1> privList = {
AppaRao Puli071f3f22018-05-24 16:45:30 +0530151 "priv-reserved", "priv-callback", "priv-user",
152 "priv-operator", "priv-admin", "priv-oem"};
153
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530154std::string ChannelConfig::getChannelName(const uint8_t chNum)
Johnathan Mantey74a21022018-12-13 13:17:56 -0800155{
156 if (!isValidChannel(chNum))
157 {
158 log<level::ERR>("Invalid channel number.",
Richard Marian Thomaiyar619ed5f2020-01-17 12:17:47 +0530159 entry("CHANNEL_ID=%d", chNum));
Johnathan Mantey74a21022018-12-13 13:17:56 -0800160 throw std::invalid_argument("Invalid channel number");
161 }
162
163 return channelData[chNum].chName;
164}
165
166int ChannelConfig::convertToChannelNumberFromChannelName(
167 const std::string& chName)
168{
169 for (const auto& it : channelData)
170 {
171 if (it.chName == chName)
172 {
173 return it.chID;
174 }
175 }
176 log<level::ERR>("Invalid channel name.",
Richard Marian Thomaiyar619ed5f2020-01-17 12:17:47 +0530177 entry("CHANNEL=%s", chName.c_str()));
Johnathan Mantey74a21022018-12-13 13:17:56 -0800178 throw std::invalid_argument("Invalid channel name");
179
180 return -1;
181}
182
183std::string ChannelConfig::getChannelNameFromPath(const std::string& path)
AppaRao Puli9613ed72018-09-01 23:46:44 +0530184{
Peter Foley1214d6c2023-11-01 11:12:42 -0400185 const size_t length = strlen(networkIntfObjectBasePath);
Richard Marian Thomaiyarbbbc3952020-01-17 12:13:28 +0530186 if (((length + 1) >= path.size()) ||
187 path.compare(0, length, networkIntfObjectBasePath))
AppaRao Puli9613ed72018-09-01 23:46:44 +0530188 {
Richard Marian Thomaiyarbbbc3952020-01-17 12:13:28 +0530189 log<level::ERR>("Invalid object path.", entry("PATH=%s", path.c_str()));
190 throw std::invalid_argument("Invalid object path");
AppaRao Puli9613ed72018-09-01 23:46:44 +0530191 }
Richard Marian Thomaiyarbbbc3952020-01-17 12:13:28 +0530192 std::string chName(path, length + 1);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800193 return chName;
AppaRao Puli9613ed72018-09-01 23:46:44 +0530194}
195
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800196void ChannelConfig::processChAccessPropChange(
197 const std::string& path, const DbusChObjProperties& chProperties)
AppaRao Puli9613ed72018-09-01 23:46:44 +0530198{
199 // Get interface name from path. ex: '/xyz/openbmc_project/network/eth0'
Johnathan Mantey74a21022018-12-13 13:17:56 -0800200 std::string chName;
AppaRao Puli9613ed72018-09-01 23:46:44 +0530201 try
202 {
Johnathan Mantey74a21022018-12-13 13:17:56 -0800203 chName = getChannelNameFromPath(path);
AppaRao Puli9613ed72018-09-01 23:46:44 +0530204 }
205 catch (const std::invalid_argument& e)
206 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +0530207 log<level::ERR>("Exception: ", entry("MSG=%s", e.what()));
AppaRao Puli9613ed72018-09-01 23:46:44 +0530208 return;
209 }
210
211 // Get the MaxPrivilege property value from the signal
212 std::string intfPrivStr;
213 std::string propName;
214 for (const auto& prop : chProperties)
215 {
216 if (prop.first == privilegePropertyString)
217 {
218 propName = privilegePropertyString;
Vernon Maueryf442e112019-04-09 11:44:36 -0700219 intfPrivStr = std::get<std::string>(prop.second);
AppaRao Puli9613ed72018-09-01 23:46:44 +0530220 break;
221 }
222 }
223
224 if (propName != privilegePropertyString)
225 {
226 log<level::ERR>("Unknown signal caught.");
227 return;
228 }
229
230 if (intfPrivStr.empty())
231 {
232 log<level::ERR>("Invalid privilege string.",
Ayushi Smriti05ad3412019-10-16 16:10:18 +0530233 entry("INTF=%s", chName.c_str()));
AppaRao Puli9613ed72018-09-01 23:46:44 +0530234 return;
235 }
236
237 uint8_t intfPriv = 0;
Johnathan Mantey74a21022018-12-13 13:17:56 -0800238 int chNum;
AppaRao Puli9613ed72018-09-01 23:46:44 +0530239 try
240 {
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800241 intfPriv = static_cast<uint8_t>(convertToPrivLimitIndex(intfPrivStr));
Johnathan Mantey74a21022018-12-13 13:17:56 -0800242 chNum = convertToChannelNumberFromChannelName(chName);
AppaRao Puli9613ed72018-09-01 23:46:44 +0530243 }
244 catch (const std::invalid_argument& e)
245 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +0530246 log<level::ERR>("Exception: ", entry("MSG=%s", e.what()));
AppaRao Puli9613ed72018-09-01 23:46:44 +0530247 return;
248 }
249
250 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800251 channelLock{*channelMutex};
AppaRao Puli9613ed72018-09-01 23:46:44 +0530252 // skip updating the values, if this property change originated from IPMI.
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800253 if (signalFlag & (1 << chNum))
AppaRao Puli9613ed72018-09-01 23:46:44 +0530254 {
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800255 signalFlag &= ~(1 << chNum);
AppaRao Puli9613ed72018-09-01 23:46:44 +0530256 log<level::DEBUG>("Request originated from IPMI so ignoring signal");
257 return;
258 }
259
260 // Update both volatile & Non-volatile, if there is mismatch.
261 // as property change other than IPMI, has to update both volatile &
262 // non-volatile data.
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800263 checkAndReloadVolatileData();
264 checkAndReloadNVData();
265 if (channelData[chNum].chAccess.chNonVolatileData.privLimit != intfPriv)
AppaRao Puli9613ed72018-09-01 23:46:44 +0530266 {
267 // Update NV data
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800268 channelData[chNum].chAccess.chNonVolatileData.privLimit = intfPriv;
269 if (writeChannelPersistData() != 0)
AppaRao Puli9613ed72018-09-01 23:46:44 +0530270 {
271 log<level::ERR>("Failed to update the persist data file");
272 return;
273 }
274
275 // Update Volatile data
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800276 if (channelData[chNum].chAccess.chVolatileData.privLimit != intfPriv)
AppaRao Puli9613ed72018-09-01 23:46:44 +0530277 {
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800278 channelData[chNum].chAccess.chVolatileData.privLimit = intfPriv;
279 if (writeChannelVolatileData() != 0)
AppaRao Puli9613ed72018-09-01 23:46:44 +0530280 {
281 log<level::ERR>("Failed to update the volatile data file");
282 return;
283 }
284 }
285 }
286
287 return;
288}
289
AppaRao Puli071f3f22018-05-24 16:45:30 +0530290ChannelConfig& getChannelConfigObject()
291{
292 static ChannelConfig channelConfig;
293 return channelConfig;
294}
295
AppaRao Puli9613ed72018-09-01 23:46:44 +0530296ChannelConfig::~ChannelConfig()
297{
298 if (signalHndlrObjectState)
299 {
300 chPropertiesSignal.reset();
Willy Tuac05aa12021-11-16 21:15:58 -0800301 chInterfaceAddedSignal.reset();
302 chInterfaceRemovedSignal.reset();
AppaRao Puli9613ed72018-09-01 23:46:44 +0530303 sigHndlrLock.unlock();
304 }
305}
306
AppaRao Puli071f3f22018-05-24 16:45:30 +0530307ChannelConfig::ChannelConfig() : bus(ipmid_get_sd_bus_connection())
308{
309 std::ofstream mutexCleanUpFile;
310 mutexCleanUpFile.open(ipmiChMutexCleanupLockFile,
311 std::ofstream::out | std::ofstream::app);
312 if (!mutexCleanUpFile.good())
313 {
314 log<level::DEBUG>("Unable to open mutex cleanup file");
315 return;
316 }
317 mutexCleanUpFile.close();
318 mutexCleanupLock =
319 boost::interprocess::file_lock(ipmiChMutexCleanupLockFile);
320 if (mutexCleanupLock.try_lock())
321 {
322 boost::interprocess::named_recursive_mutex::remove(ipmiChannelMutex);
323 channelMutex =
324 std::make_unique<boost::interprocess::named_recursive_mutex>(
325 boost::interprocess::open_or_create, ipmiChannelMutex);
326 mutexCleanupLock.lock_sharable();
327 }
328 else
329 {
330 mutexCleanupLock.lock_sharable();
331 channelMutex =
332 std::make_unique<boost::interprocess::named_recursive_mutex>(
333 boost::interprocess::open_or_create, ipmiChannelMutex);
334 }
335
336 initChannelPersistData();
AppaRao Puli9613ed72018-09-01 23:46:44 +0530337
338 sigHndlrLock = boost::interprocess::file_lock(channelNvDataFilename);
George Liu1a2e1502022-07-08 12:20:19 +0800339 // Register it for single object and single process either netipmid /
AppaRao Puli9613ed72018-09-01 23:46:44 +0530340 // host-ipmid
341 if (chPropertiesSignal == nullptr && sigHndlrLock.try_lock())
342 {
343 log<level::DEBUG>("Registering channel signal handler.");
344 chPropertiesSignal = std::make_unique<sdbusplus::bus::match_t>(
345 bus,
346 sdbusplus::bus::match::rules::path_namespace(
347 networkIntfObjectBasePath) +
348 sdbusplus::bus::match::rules::type::signal() +
349 sdbusplus::bus::match::rules::member(propertiesChangedSignal) +
350 sdbusplus::bus::match::rules::interface(
351 dBusPropertiesInterface) +
352 sdbusplus::bus::match::rules::argN(0, networkChConfigIntfName),
Patrick Williams5d82f472022-07-22 19:26:53 -0500353 [&](sdbusplus::message_t& msg) {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500354 DbusChObjProperties props;
355 std::string iface;
356 std::string path = msg.get_path();
357 msg.read(iface, props);
358 processChAccessPropChange(path, props);
Patrick Williams369824e2023-10-20 11:18:23 -0500359 });
AppaRao Puli9613ed72018-09-01 23:46:44 +0530360 signalHndlrObjectState = true;
Willy Tuac05aa12021-11-16 21:15:58 -0800361
362 chInterfaceAddedSignal = std::make_unique<sdbusplus::bus::match_t>(
363 bus,
364 sdbusplus::bus::match::rules::type::signal() +
365 sdbusplus::bus::match::rules::member(interfaceAddedSignal) +
366 sdbusplus::bus::match::rules::argNpath(
367 0, std::string(networkIntfObjectBasePath) + "/"),
Patrick Williams5d82f472022-07-22 19:26:53 -0500368 [&](sdbusplus::message_t&) { initChannelPersistData(); });
Willy Tuac05aa12021-11-16 21:15:58 -0800369
370 chInterfaceRemovedSignal = std::make_unique<sdbusplus::bus::match_t>(
371 bus,
372 sdbusplus::bus::match::rules::type::signal() +
373 sdbusplus::bus::match::rules::member(interfaceRemovedSignal) +
374 sdbusplus::bus::match::rules::argNpath(
375 0, std::string(networkIntfObjectBasePath) + "/"),
Patrick Williams5d82f472022-07-22 19:26:53 -0500376 [&](sdbusplus::message_t&) { initChannelPersistData(); });
AppaRao Puli9613ed72018-09-01 23:46:44 +0530377 }
378}
379
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530380bool ChannelConfig::isValidChannel(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530381{
Meera-Kattac1789482021-05-18 09:53:26 +0000382 if (chNum >= maxIpmiChannels)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530383 {
384 log<level::DEBUG>("Invalid channel ID - Out of range");
385 return false;
386 }
387
388 if (channelData[chNum].isChValid == false)
389 {
390 log<level::DEBUG>("Channel is not valid");
AppaRao Puli071f3f22018-05-24 16:45:30 +0530391 }
392
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800393 return channelData[chNum].isChValid;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530394}
395
396EChannelSessSupported
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530397 ChannelConfig::getChannelSessionSupport(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530398{
399 EChannelSessSupported chSessSupport =
400 (EChannelSessSupported)channelData[chNum].chInfo.sessionSupported;
401 return chSessSupport;
402}
403
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530404bool ChannelConfig::isValidAuthType(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530405 const EAuthType& authType)
406{
407 if ((authType < EAuthType::md2) || (authType > EAuthType::oem))
408 {
409 log<level::DEBUG>("Invalid authentication type");
410 return false;
411 }
412
413 uint8_t authTypeSupported = channelData[chNum].chInfo.authTypeSupported;
414 if (!(authTypeSupported & (1 << static_cast<uint8_t>(authType))))
415 {
416 log<level::DEBUG>("Authentication type is not supported.");
417 return false;
418 }
419
420 return true;
421}
422
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530423int ChannelConfig::getChannelActiveSessions(const uint8_t chNum)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530424{
425 // TODO: TEMPORARY FIX
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800426 // Channels active session count is managed separately
AppaRao Puli071f3f22018-05-24 16:45:30 +0530427 // by monitoring channel session which includes LAN and
428 // RAKP layer changes. This will be updated, once the
429 // authentication part is implemented.
430 return channelData[chNum].activeSessCount;
431}
432
Vernon Mauery58317122018-11-28 11:02:43 -0800433size_t ChannelConfig::getChannelMaxTransferSize(uint8_t chNum)
434{
435 return channelData[chNum].maxTransferSize;
436}
437
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000438Cc ChannelConfig::getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530439{
440 if (!isValidChannel(chNum))
441 {
442 log<level::DEBUG>("Invalid channel");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000443 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530444 }
445
446 std::copy_n(reinterpret_cast<uint8_t*>(&channelData[chNum].chInfo),
447 sizeof(channelData[chNum].chInfo),
448 reinterpret_cast<uint8_t*>(&chInfo));
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000449 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530450}
451
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000452Cc ChannelConfig::getChannelAccessData(const uint8_t chNum,
453 ChannelAccess& chAccessData)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530454{
455 if (!isValidChannel(chNum))
456 {
457 log<level::DEBUG>("Invalid channel");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000458 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530459 }
460
461 if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
462 {
463 log<level::DEBUG>("Session-less channel doesn't have access data.");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000464 return ccActionNotSupportedForChannel;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530465 }
466
467 if (checkAndReloadVolatileData() != 0)
468 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000469 return ccUnspecifiedError;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530470 }
471
472 std::copy_n(
473 reinterpret_cast<uint8_t*>(&channelData[chNum].chAccess.chVolatileData),
474 sizeof(channelData[chNum].chAccess.chVolatileData),
475 reinterpret_cast<uint8_t*>(&chAccessData));
476
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000477 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530478}
479
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000480Cc ChannelConfig::setChannelAccessData(const uint8_t chNum,
481 const ChannelAccess& chAccessData,
482 const uint8_t setFlag)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530483{
484 if (!isValidChannel(chNum))
485 {
486 log<level::DEBUG>("Invalid channel");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000487 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530488 }
489
490 if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
491 {
492 log<level::DEBUG>("Session-less channel doesn't have access data.");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000493 return ccActionNotSupportedForChannel;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530494 }
495
jayaprakash Mutyala0e2dbee2019-12-26 13:03:04 +0000496 if ((setFlag & setAccessMode) &&
497 (!isValidAccessMode(chAccessData.accessMode)))
AppaRao Puli071f3f22018-05-24 16:45:30 +0530498 {
jayaprakash Mutyala0e2dbee2019-12-26 13:03:04 +0000499 log<level::DEBUG>("Invalid access mode specified");
500 return ccAccessModeNotSupportedForChannel;
501 }
502 if ((setFlag & setPrivLimit) && (!isValidPrivLimit(chAccessData.privLimit)))
503 {
504 log<level::DEBUG>("Invalid privilege limit specified");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000505 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530506 }
507
508 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
509 channelLock{*channelMutex};
510
511 if (checkAndReloadVolatileData() != 0)
512 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000513 return ccUnspecifiedError;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530514 }
515
516 if (setFlag & setAccessMode)
517 {
518 channelData[chNum].chAccess.chVolatileData.accessMode =
519 chAccessData.accessMode;
520 }
521 if (setFlag & setUserAuthEnabled)
522 {
523 channelData[chNum].chAccess.chVolatileData.userAuthDisabled =
524 chAccessData.userAuthDisabled;
525 }
526 if (setFlag & setMsgAuthEnabled)
527 {
528 channelData[chNum].chAccess.chVolatileData.perMsgAuthDisabled =
529 chAccessData.perMsgAuthDisabled;
530 }
531 if (setFlag & setAlertingEnabled)
532 {
533 channelData[chNum].chAccess.chVolatileData.alertingDisabled =
534 chAccessData.alertingDisabled;
535 }
536 if (setFlag & setPrivLimit)
537 {
538 channelData[chNum].chAccess.chVolatileData.privLimit =
539 chAccessData.privLimit;
540 }
541
542 // Write Volatile data to file
543 if (writeChannelVolatileData() != 0)
544 {
545 log<level::DEBUG>("Failed to update the channel volatile data");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000546 return ccUnspecifiedError;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530547 }
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000548 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530549}
550
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000551Cc ChannelConfig::getChannelAccessPersistData(const uint8_t chNum,
552 ChannelAccess& chAccessData)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530553{
554 if (!isValidChannel(chNum))
555 {
556 log<level::DEBUG>("Invalid channel");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000557 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530558 }
559
560 if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
561 {
562 log<level::DEBUG>("Session-less channel doesn't have access data.");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000563 return ccActionNotSupportedForChannel;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530564 }
565
566 if (checkAndReloadNVData() != 0)
567 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000568 return ccUnspecifiedError;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530569 }
570
571 std::copy_n(reinterpret_cast<uint8_t*>(
572 &channelData[chNum].chAccess.chNonVolatileData),
573 sizeof(channelData[chNum].chAccess.chNonVolatileData),
574 reinterpret_cast<uint8_t*>(&chAccessData));
575
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000576 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530577}
578
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000579Cc ChannelConfig::setChannelAccessPersistData(const uint8_t chNum,
580 const ChannelAccess& chAccessData,
581 const uint8_t setFlag)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530582{
583 if (!isValidChannel(chNum))
584 {
585 log<level::DEBUG>("Invalid channel");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000586 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530587 }
588
589 if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
590 {
591 log<level::DEBUG>("Session-less channel doesn't have access data.");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000592 return ccActionNotSupportedForChannel;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530593 }
594
jayaprakash Mutyala0e2dbee2019-12-26 13:03:04 +0000595 if ((setFlag & setAccessMode) &&
596 (!isValidAccessMode(chAccessData.accessMode)))
AppaRao Puli071f3f22018-05-24 16:45:30 +0530597 {
jayaprakash Mutyala0e2dbee2019-12-26 13:03:04 +0000598 log<level::DEBUG>("Invalid access mode specified");
599 return ccAccessModeNotSupportedForChannel;
600 }
601 if ((setFlag & setPrivLimit) && (!isValidPrivLimit(chAccessData.privLimit)))
602 {
603 log<level::DEBUG>("Invalid privilege limit specified");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000604 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530605 }
606
607 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
608 channelLock{*channelMutex};
609
610 if (checkAndReloadNVData() != 0)
611 {
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000612 return ccUnspecifiedError;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530613 }
614
615 if (setFlag & setAccessMode)
616 {
617 channelData[chNum].chAccess.chNonVolatileData.accessMode =
618 chAccessData.accessMode;
619 }
620 if (setFlag & setUserAuthEnabled)
621 {
622 channelData[chNum].chAccess.chNonVolatileData.userAuthDisabled =
623 chAccessData.userAuthDisabled;
624 }
625 if (setFlag & setMsgAuthEnabled)
626 {
627 channelData[chNum].chAccess.chNonVolatileData.perMsgAuthDisabled =
628 chAccessData.perMsgAuthDisabled;
629 }
630 if (setFlag & setAlertingEnabled)
631 {
632 channelData[chNum].chAccess.chNonVolatileData.alertingDisabled =
633 chAccessData.alertingDisabled;
634 }
635 if (setFlag & setPrivLimit)
636 {
AppaRao Puli9613ed72018-09-01 23:46:44 +0530637 // Send Update to network channel config interfaces over dbus
AppaRao Puli9613ed72018-09-01 23:46:44 +0530638 std::string privStr = convertToPrivLimitString(chAccessData.privLimit);
Richard Marian Thomaiyar73906b92019-01-04 23:48:02 +0530639 std::string networkIntfObj = std::string(networkIntfObjectBasePath) +
640 "/" + channelData[chNum].chName;
AppaRao Puli9613ed72018-09-01 23:46:44 +0530641 try
642 {
Johnathan Manteyf92261d2018-12-10 15:49:34 -0800643 if (0 != setDbusProperty(networkIntfServiceName, networkIntfObj,
644 networkChConfigIntfName,
AppaRao Puli9613ed72018-09-01 23:46:44 +0530645 privilegePropertyString, privStr))
646 {
Richard Marian Thomaiyar73906b92019-01-04 23:48:02 +0530647 log<level::DEBUG>(
648 "Network interface does not exist",
Ayushi Smriti05ad3412019-10-16 16:10:18 +0530649 entry("INTERFACE=%s", channelData[chNum].chName.c_str()));
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000650 return ccUnspecifiedError;
AppaRao Puli9613ed72018-09-01 23:46:44 +0530651 }
652 }
Patrick Williams5d82f472022-07-22 19:26:53 -0500653 catch (const sdbusplus::exception_t& e)
AppaRao Puli9613ed72018-09-01 23:46:44 +0530654 {
655 log<level::ERR>("Exception: Network interface does not exist");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000656 return ccInvalidFieldRequest;
AppaRao Puli9613ed72018-09-01 23:46:44 +0530657 }
658 signalFlag |= (1 << chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530659 channelData[chNum].chAccess.chNonVolatileData.privLimit =
660 chAccessData.privLimit;
661 }
662
663 // Write persistent data to file
664 if (writeChannelPersistData() != 0)
665 {
666 log<level::DEBUG>("Failed to update the presist data file");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000667 return ccUnspecifiedError;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530668 }
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000669 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530670}
671
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000672Cc ChannelConfig::getChannelAuthTypeSupported(const uint8_t chNum,
673 uint8_t& authTypeSupported)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530674{
675 if (!isValidChannel(chNum))
676 {
677 log<level::DEBUG>("Invalid channel");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000678 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530679 }
680
681 authTypeSupported = channelData[chNum].chInfo.authTypeSupported;
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000682 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530683}
684
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000685Cc ChannelConfig::getChannelEnabledAuthType(const uint8_t chNum,
686 const uint8_t priv,
687 EAuthType& authType)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530688{
689 if (!isValidChannel(chNum))
690 {
691 log<level::DEBUG>("Invalid channel");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000692 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530693 }
694
695 if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
696 {
697 log<level::DEBUG>("Sessionless channel doesn't have access data.");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000698 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530699 }
700
701 if (!isValidPrivLimit(priv))
702 {
703 log<level::DEBUG>("Invalid privilege specified.");
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000704 return ccInvalidFieldRequest;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530705 }
706
707 // TODO: Hardcoded for now. Need to implement.
708 authType = EAuthType::none;
709
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000710 return ccSuccess;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530711}
712
713std::time_t ChannelConfig::getUpdatedFileTime(const std::string& fileName)
714{
715 struct stat fileStat;
716 if (stat(fileName.c_str(), &fileStat) != 0)
717 {
718 log<level::DEBUG>("Error in getting last updated time stamp");
719 return -EIO;
720 }
721 return fileStat.st_mtime;
722}
723
724EChannelAccessMode
725 ChannelConfig::convertToAccessModeIndex(const std::string& mode)
726{
727 auto iter = std::find(accessModeList.begin(), accessModeList.end(), mode);
728 if (iter == accessModeList.end())
729 {
730 log<level::ERR>("Invalid access mode.",
731 entry("MODE_STR=%s", mode.c_str()));
732 throw std::invalid_argument("Invalid access mode.");
733 }
734
735 return static_cast<EChannelAccessMode>(
736 std::distance(accessModeList.begin(), iter));
737}
738
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530739std::string ChannelConfig::convertToAccessModeString(const uint8_t value)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530740{
741 if (accessModeList.size() <= value)
742 {
743 log<level::ERR>("Invalid access mode.", entry("MODE_IDX=%d", value));
744 throw std::invalid_argument("Invalid access mode.");
745 }
746
747 return accessModeList.at(value);
748}
749
750CommandPrivilege
751 ChannelConfig::convertToPrivLimitIndex(const std::string& value)
752{
753 auto iter = std::find(privList.begin(), privList.end(), value);
754 if (iter == privList.end())
755 {
756 log<level::ERR>("Invalid privilege.",
757 entry("PRIV_STR=%s", value.c_str()));
758 throw std::invalid_argument("Invalid privilege.");
759 }
760
761 return static_cast<CommandPrivilege>(std::distance(privList.begin(), iter));
762}
763
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530764std::string ChannelConfig::convertToPrivLimitString(const uint8_t value)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530765{
766 if (privList.size() <= value)
767 {
768 log<level::ERR>("Invalid privilege.", entry("PRIV_IDX=%d", value));
769 throw std::invalid_argument("Invalid privilege.");
770 }
771
772 return privList.at(value);
773}
774
775EChannelSessSupported
776 ChannelConfig::convertToSessionSupportIndex(const std::string& value)
777{
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500778 auto iter = std::find(sessionSupportList.begin(), sessionSupportList.end(),
779 value);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530780 if (iter == sessionSupportList.end())
781 {
782 log<level::ERR>("Invalid session supported.",
783 entry("SESS_STR=%s", value.c_str()));
784 throw std::invalid_argument("Invalid session supported.");
785 }
786
787 return static_cast<EChannelSessSupported>(
788 std::distance(sessionSupportList.begin(), iter));
789}
790
791EChannelMediumType
792 ChannelConfig::convertToMediumTypeIndex(const std::string& value)
793{
794 std::unordered_map<std::string, EChannelMediumType>::iterator it =
795 mediumTypeMap.find(value);
796 if (it == mediumTypeMap.end())
797 {
798 log<level::ERR>("Invalid medium type.",
799 entry("MEDIUM_STR=%s", value.c_str()));
800 throw std::invalid_argument("Invalid medium type.");
801 }
802
803 return static_cast<EChannelMediumType>(it->second);
804}
805
806EChannelProtocolType
807 ChannelConfig::convertToProtocolTypeIndex(const std::string& value)
808{
809 std::unordered_map<std::string, EChannelProtocolType>::iterator it =
810 protocolTypeMap.find(value);
811 if (it == protocolTypeMap.end())
812 {
813 log<level::ERR>("Invalid protocol type.",
814 entry("PROTO_STR=%s", value.c_str()));
815 throw std::invalid_argument("Invalid protocol type.");
816 }
817
818 return static_cast<EChannelProtocolType>(it->second);
819}
820
821Json ChannelConfig::readJsonFile(const std::string& configFile)
822{
823 std::ifstream jsonFile(configFile);
824 if (!jsonFile.good())
825 {
Richard Marian Thomaiyarc4196802019-06-03 19:27:48 +0530826 log<level::INFO>("JSON file not found",
827 entry("FILE_NAME=%s", configFile.c_str()));
AppaRao Puli071f3f22018-05-24 16:45:30 +0530828 return nullptr;
829 }
830
831 Json data = nullptr;
832 try
833 {
834 data = Json::parse(jsonFile, nullptr, false);
835 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500836 catch (const Json::parse_error& e)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530837 {
838 log<level::DEBUG>("Corrupted channel config.",
Ayushi Smriti05ad3412019-10-16 16:10:18 +0530839 entry("MSG=%s", e.what()));
AppaRao Puli071f3f22018-05-24 16:45:30 +0530840 throw std::runtime_error("Corrupted channel config file");
841 }
842
843 return data;
844}
845
846int ChannelConfig::writeJsonFile(const std::string& configFile,
847 const Json& jsonData)
848{
Richard Marian Thomaiyar687df402019-05-09 00:16:53 +0530849 const std::string tmpFile = configFile + "_tmp";
850 int fd = open(tmpFile.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_SYNC,
851 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
852 if (fd < 0)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530853 {
Richard Marian Thomaiyar687df402019-05-09 00:16:53 +0530854 log<level::ERR>("Error in creating json file",
855 entry("FILE_NAME = %s", tmpFile.c_str()));
856 return -EIO;
857 }
858 const auto& writeData = jsonData.dump();
859 if (write(fd, writeData.c_str(), writeData.size()) !=
860 static_cast<ssize_t>(writeData.size()))
861 {
862 close(fd);
863 log<level::ERR>("Error in writing configuration file",
864 entry("FILE_NAME = %s", tmpFile.c_str()));
865 return -EIO;
866 }
867 close(fd);
868
869 if (std::rename(tmpFile.c_str(), configFile.c_str()) != 0)
870 {
871 log<level::ERR>("Error in renaming temporary data file",
872 entry("FILE_NAME = %s", tmpFile.c_str()));
AppaRao Puli071f3f22018-05-24 16:45:30 +0530873 return -EIO;
874 }
875
AppaRao Puli071f3f22018-05-24 16:45:30 +0530876 return 0;
877}
878
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530879void ChannelConfig::setDefaultChannelConfig(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530880 const std::string& chName)
881{
882 channelData[chNum].chName = chName;
883 channelData[chNum].chID = chNum;
884 channelData[chNum].isChValid = false;
885 channelData[chNum].activeSessCount = 0;
Johnathan Manteyfd61fc32021-04-08 11:05:38 -0700886 channelData[chNum].isManagementNIC = false;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530887
888 channelData[chNum].chInfo.mediumType = defaultMediumType;
889 channelData[chNum].chInfo.protocolType = defaultProtocolType;
890 channelData[chNum].chInfo.sessionSupported = defaultSessionSupported;
891 channelData[chNum].chInfo.isIpmi = defaultIsIpmiState;
892 channelData[chNum].chInfo.authTypeSupported = defaultAuthType;
893}
894
Johnathan Manteyfd61fc32021-04-08 11:05:38 -0700895uint8_t ChannelConfig::getManagementNICID()
896{
897 static bool idFound = false;
898 static uint8_t id = 0;
899
900 if (idFound)
901 {
902 return id;
903 }
904
905 for (uint8_t chIdx = 0; chIdx < maxIpmiChannels; chIdx++)
906 {
907 if (channelData[chIdx].isManagementNIC)
908 {
909 id = chIdx;
910 idFound = true;
911 break;
912 }
913 }
914
915 if (!idFound)
916 {
917 id = static_cast<uint8_t>(EChannelID::chanLan1);
918 idFound = true;
919 }
920 return id;
921}
922
AppaRao Puli071f3f22018-05-24 16:45:30 +0530923int ChannelConfig::loadChannelConfig()
924{
925 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
926 channelLock{*channelMutex};
927
928 Json data = readJsonFile(channelConfigDefaultFilename);
Johnathan Manteye5c4f1d2018-12-10 16:24:26 -0800929 if (data.empty())
AppaRao Puli071f3f22018-05-24 16:45:30 +0530930 {
931 log<level::DEBUG>("Error in opening IPMI Channel data file");
932 return -EIO;
933 }
934
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800935 channelData.fill(ChannelProperties{});
936
Johnathan Mantey0a2abc82021-02-18 12:39:12 -0800937 // Collect the list of NIC interfaces connected to the BMC. Use this
938 // information to only add IPMI channels that have active NIC interfaces.
Snehalatha Venkatesh55f5d532021-07-13 11:06:36 +0000939 struct ifaddrs *ifaddr = nullptr, *ifa = nullptr;
Johnathan Mantey0a2abc82021-02-18 12:39:12 -0800940 if (int err = getifaddrs(&ifaddr); err < 0)
941 {
942 log<level::DEBUG>("Unable to acquire network interfaces");
943 return -EIO;
944 }
945
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800946 for (int chNum = 0; chNum < maxIpmiChannels; chNum++)
AppaRao Puli071f3f22018-05-24 16:45:30 +0530947 {
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800948 try
AppaRao Puli071f3f22018-05-24 16:45:30 +0530949 {
AppaRao Puli071f3f22018-05-24 16:45:30 +0530950 std::string chKey = std::to_string(chNum);
951 Json jsonChData = data[chKey].get<Json>();
952 if (jsonChData.is_null())
953 {
AppaRao Puli071f3f22018-05-24 16:45:30 +0530954 // If user didn't want to configure specific channel (say
955 // reserved channel), then load that index with default values.
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800956 setDefaultChannelConfig(chNum, defaultChannelName);
957 continue;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530958 }
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800959 Json jsonChInfo = jsonChData[channelInfoString].get<Json>();
960 if (jsonChInfo.is_null())
AppaRao Puli071f3f22018-05-24 16:45:30 +0530961 {
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800962 log<level::ERR>("Invalid/corrupted channel config file");
Johnathan Mantey0a2abc82021-02-18 12:39:12 -0800963 freeifaddrs(ifaddr);
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800964 return -EBADMSG;
AppaRao Puli071f3f22018-05-24 16:45:30 +0530965 }
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800966
Johnathan Mantey0a2abc82021-02-18 12:39:12 -0800967 bool channelFound = true;
968 // Confirm the LAN channel is present
969 if (jsonChInfo[mediumTypeString].get<std::string>() == "lan-802.3")
970 {
971 channelFound = false;
972 for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
973 {
974 if (jsonChData[nameString].get<std::string>() ==
975 ifa->ifa_name)
976 {
977 channelFound = true;
978 break;
979 }
980 }
981 }
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800982 ChannelProperties& chData = channelData[chNum];
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800983 chData.chID = chNum;
Johnathan Mantey0a2abc82021-02-18 12:39:12 -0800984 chData.chName = jsonChData[nameString].get<std::string>();
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500985 chData.isChValid = channelFound &&
986 jsonChData[isValidString].get<bool>();
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800987 chData.activeSessCount = jsonChData.value(activeSessionsString, 0);
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500988 chData.maxTransferSize = jsonChData.value(maxTransferSizeString,
989 smallChannelSize);
Johnathan Manteyfd61fc32021-04-08 11:05:38 -0700990 if (jsonChData.count(isManagementNIC) != 0)
991 {
992 chData.isManagementNIC =
993 jsonChData[isManagementNIC].get<bool>();
994 }
995
Johnathan Mantey4c0435a2018-12-11 13:17:55 -0800996 std::string medTypeStr =
997 jsonChInfo[mediumTypeString].get<std::string>();
998 chData.chInfo.mediumType =
999 static_cast<uint8_t>(convertToMediumTypeIndex(medTypeStr));
1000 std::string protoTypeStr =
1001 jsonChInfo[protocolTypeString].get<std::string>();
1002 chData.chInfo.protocolType =
1003 static_cast<uint8_t>(convertToProtocolTypeIndex(protoTypeStr));
1004 std::string sessStr =
1005 jsonChInfo[sessionSupportedString].get<std::string>();
1006 chData.chInfo.sessionSupported =
1007 static_cast<uint8_t>(convertToSessionSupportIndex(sessStr));
1008 chData.chInfo.isIpmi = jsonChInfo[isIpmiString].get<bool>();
1009 chData.chInfo.authTypeSupported = defaultAuthType;
AppaRao Puli071f3f22018-05-24 16:45:30 +05301010 }
Johnathan Mantey4c0435a2018-12-11 13:17:55 -08001011 catch (const Json::exception& e)
1012 {
1013 log<level::DEBUG>("Json Exception caught.",
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301014 entry("MSG=%s", e.what()));
Johnathan Mantey0a2abc82021-02-18 12:39:12 -08001015 freeifaddrs(ifaddr);
1016
Johnathan Mantey4c0435a2018-12-11 13:17:55 -08001017 return -EBADMSG;
1018 }
1019 catch (const std::invalid_argument& e)
1020 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301021 log<level::ERR>("Corrupted config.", entry("MSG=%s", e.what()));
Johnathan Mantey0a2abc82021-02-18 12:39:12 -08001022 freeifaddrs(ifaddr);
Johnathan Mantey4c0435a2018-12-11 13:17:55 -08001023 return -EBADMSG;
1024 }
AppaRao Puli071f3f22018-05-24 16:45:30 +05301025 }
Johnathan Mantey0a2abc82021-02-18 12:39:12 -08001026 freeifaddrs(ifaddr);
AppaRao Puli071f3f22018-05-24 16:45:30 +05301027
1028 return 0;
1029}
1030
1031int ChannelConfig::readChannelVolatileData()
1032{
1033 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
1034 channelLock{*channelMutex};
1035
1036 Json data = readJsonFile(channelVolatileDataFilename);
1037 if (data == nullptr)
1038 {
1039 log<level::DEBUG>("Error in opening IPMI Channel data file");
1040 return -EIO;
1041 }
AppaRao Puli071f3f22018-05-24 16:45:30 +05301042 try
1043 {
1044 // Fill in global structure
1045 for (auto it = data.begin(); it != data.end(); ++it)
1046 {
1047 std::string chKey = it.key();
1048 uint8_t chNum = std::stoi(chKey, nullptr, 10);
Meera-Kattac1789482021-05-18 09:53:26 +00001049 if (chNum >= maxIpmiChannels)
AppaRao Puli071f3f22018-05-24 16:45:30 +05301050 {
1051 log<level::DEBUG>(
1052 "Invalid channel access entry in config file");
1053 throw std::out_of_range("Out of range - channel number");
1054 }
1055 Json jsonChData = it.value();
1056 if (!jsonChData.is_null())
1057 {
1058 std::string accModeStr =
1059 jsonChData[accessModeString].get<std::string>();
1060 channelData[chNum].chAccess.chVolatileData.accessMode =
1061 static_cast<uint8_t>(convertToAccessModeIndex(accModeStr));
1062 channelData[chNum].chAccess.chVolatileData.userAuthDisabled =
1063 jsonChData[userAuthDisabledString].get<bool>();
1064 channelData[chNum].chAccess.chVolatileData.perMsgAuthDisabled =
1065 jsonChData[perMsgAuthDisabledString].get<bool>();
1066 channelData[chNum].chAccess.chVolatileData.alertingDisabled =
1067 jsonChData[alertingDisabledString].get<bool>();
1068 std::string privStr =
1069 jsonChData[privLimitString].get<std::string>();
1070 channelData[chNum].chAccess.chVolatileData.privLimit =
1071 static_cast<uint8_t>(convertToPrivLimitIndex(privStr));
1072 }
1073 else
1074 {
1075 log<level::ERR>(
1076 "Invalid/corrupted volatile channel access file",
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301077 entry("FILE=%s", channelVolatileDataFilename));
AppaRao Puli071f3f22018-05-24 16:45:30 +05301078 throw std::runtime_error(
1079 "Corrupted volatile channel access file");
1080 }
1081 }
1082 }
1083 catch (const Json::exception& e)
1084 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301085 log<level::DEBUG>("Json Exception caught.", entry("MSG=%s", e.what()));
AppaRao Puli071f3f22018-05-24 16:45:30 +05301086 throw std::runtime_error("Corrupted volatile channel access file");
1087 }
1088 catch (const std::invalid_argument& e)
1089 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301090 log<level::ERR>("Corrupted config.", entry("MSG=%s", e.what()));
AppaRao Puli071f3f22018-05-24 16:45:30 +05301091 throw std::runtime_error("Corrupted volatile channel access file");
1092 }
1093
1094 // Update the timestamp
1095 voltFileLastUpdatedTime = getUpdatedFileTime(channelVolatileDataFilename);
1096 return 0;
1097}
1098
1099int ChannelConfig::readChannelPersistData()
1100{
1101 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
1102 channelLock{*channelMutex};
1103
1104 Json data = readJsonFile(channelNvDataFilename);
1105 if (data == nullptr)
1106 {
1107 log<level::DEBUG>("Error in opening IPMI Channel data file");
1108 return -EIO;
1109 }
AppaRao Puli071f3f22018-05-24 16:45:30 +05301110 try
1111 {
1112 // Fill in global structure
1113 for (auto it = data.begin(); it != data.end(); ++it)
1114 {
1115 std::string chKey = it.key();
1116 uint8_t chNum = std::stoi(chKey, nullptr, 10);
Meera-Kattac1789482021-05-18 09:53:26 +00001117 if (chNum >= maxIpmiChannels)
AppaRao Puli071f3f22018-05-24 16:45:30 +05301118 {
1119 log<level::DEBUG>(
1120 "Invalid channel access entry in config file");
1121 throw std::out_of_range("Out of range - channel number");
1122 }
1123 Json jsonChData = it.value();
1124 if (!jsonChData.is_null())
1125 {
1126 std::string accModeStr =
1127 jsonChData[accessModeString].get<std::string>();
1128 channelData[chNum].chAccess.chNonVolatileData.accessMode =
1129 static_cast<uint8_t>(convertToAccessModeIndex(accModeStr));
1130 channelData[chNum].chAccess.chNonVolatileData.userAuthDisabled =
1131 jsonChData[userAuthDisabledString].get<bool>();
1132 channelData[chNum]
1133 .chAccess.chNonVolatileData.perMsgAuthDisabled =
1134 jsonChData[perMsgAuthDisabledString].get<bool>();
1135 channelData[chNum].chAccess.chNonVolatileData.alertingDisabled =
1136 jsonChData[alertingDisabledString].get<bool>();
1137 std::string privStr =
1138 jsonChData[privLimitString].get<std::string>();
1139 channelData[chNum].chAccess.chNonVolatileData.privLimit =
1140 static_cast<uint8_t>(convertToPrivLimitIndex(privStr));
1141 }
1142 else
1143 {
1144 log<level::ERR>("Invalid/corrupted nv channel access file",
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301145 entry("FILE=%s", channelNvDataFilename));
AppaRao Puli071f3f22018-05-24 16:45:30 +05301146 throw std::runtime_error("Corrupted nv channel access file");
1147 }
1148 }
1149 }
1150 catch (const Json::exception& e)
1151 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301152 log<level::DEBUG>("Json Exception caught.", entry("MSG=%s", e.what()));
AppaRao Puli071f3f22018-05-24 16:45:30 +05301153 throw std::runtime_error("Corrupted nv channel access file");
1154 }
1155 catch (const std::invalid_argument& e)
1156 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301157 log<level::ERR>("Corrupted config.", entry("MSG=%s", e.what()));
AppaRao Puli071f3f22018-05-24 16:45:30 +05301158 throw std::runtime_error("Corrupted nv channel access file");
1159 }
1160
1161 // Update the timestamp
1162 nvFileLastUpdatedTime = getUpdatedFileTime(channelNvDataFilename);
1163 return 0;
1164}
1165
1166int ChannelConfig::writeChannelVolatileData()
1167{
1168 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
1169 channelLock{*channelMutex};
1170 Json outData;
1171
1172 try
1173 {
1174 for (uint8_t chNum = 0; chNum < maxIpmiChannels; chNum++)
1175 {
1176 if (getChannelSessionSupport(chNum) != EChannelSessSupported::none)
1177 {
1178 Json jsonObj;
1179 std::string chKey = std::to_string(chNum);
1180 std::string accModeStr = convertToAccessModeString(
1181 channelData[chNum].chAccess.chVolatileData.accessMode);
1182 jsonObj[accessModeString] = accModeStr;
1183 jsonObj[userAuthDisabledString] =
1184 channelData[chNum].chAccess.chVolatileData.userAuthDisabled;
1185 jsonObj[perMsgAuthDisabledString] =
1186 channelData[chNum]
1187 .chAccess.chVolatileData.perMsgAuthDisabled;
1188 jsonObj[alertingDisabledString] =
1189 channelData[chNum].chAccess.chVolatileData.alertingDisabled;
1190 std::string privStr = convertToPrivLimitString(
1191 channelData[chNum].chAccess.chVolatileData.privLimit);
1192 jsonObj[privLimitString] = privStr;
1193
1194 outData[chKey] = jsonObj;
1195 }
1196 }
1197 }
1198 catch (const std::invalid_argument& e)
1199 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301200 log<level::ERR>("Corrupted config.", entry("MSG=%s", e.what()));
AppaRao Puli071f3f22018-05-24 16:45:30 +05301201 return -EINVAL;
1202 }
1203
1204 if (writeJsonFile(channelVolatileDataFilename, outData) != 0)
1205 {
1206 log<level::DEBUG>("Error in write JSON data to file");
1207 return -EIO;
1208 }
1209
1210 // Update the timestamp
1211 voltFileLastUpdatedTime = getUpdatedFileTime(channelVolatileDataFilename);
1212 return 0;
1213}
1214
1215int ChannelConfig::writeChannelPersistData()
1216{
1217 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
1218 channelLock{*channelMutex};
1219 Json outData;
1220
1221 try
1222 {
1223 for (uint8_t chNum = 0; chNum < maxIpmiChannels; chNum++)
1224 {
1225 if (getChannelSessionSupport(chNum) != EChannelSessSupported::none)
1226 {
1227 Json jsonObj;
1228 std::string chKey = std::to_string(chNum);
1229 std::string accModeStr = convertToAccessModeString(
1230 channelData[chNum].chAccess.chNonVolatileData.accessMode);
1231 jsonObj[accessModeString] = accModeStr;
1232 jsonObj[userAuthDisabledString] =
1233 channelData[chNum]
1234 .chAccess.chNonVolatileData.userAuthDisabled;
1235 jsonObj[perMsgAuthDisabledString] =
1236 channelData[chNum]
1237 .chAccess.chNonVolatileData.perMsgAuthDisabled;
1238 jsonObj[alertingDisabledString] =
1239 channelData[chNum]
1240 .chAccess.chNonVolatileData.alertingDisabled;
1241 std::string privStr = convertToPrivLimitString(
1242 channelData[chNum].chAccess.chNonVolatileData.privLimit);
1243 jsonObj[privLimitString] = privStr;
1244
1245 outData[chKey] = jsonObj;
1246 }
1247 }
1248 }
1249 catch (const std::invalid_argument& e)
1250 {
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301251 log<level::ERR>("Corrupted config.", entry("MSG=%s", e.what()));
AppaRao Puli071f3f22018-05-24 16:45:30 +05301252 return -EINVAL;
1253 }
1254
1255 if (writeJsonFile(channelNvDataFilename, outData) != 0)
1256 {
1257 log<level::DEBUG>("Error in write JSON data to file");
1258 return -EIO;
1259 }
1260
1261 // Update the timestamp
1262 nvFileLastUpdatedTime = getUpdatedFileTime(channelNvDataFilename);
1263 return 0;
1264}
1265
1266int ChannelConfig::checkAndReloadNVData()
1267{
1268 std::time_t updateTime = getUpdatedFileTime(channelNvDataFilename);
1269 int ret = 0;
1270 if (updateTime != nvFileLastUpdatedTime || updateTime == -EIO)
1271 {
1272 try
1273 {
1274 ret = readChannelPersistData();
1275 }
1276 catch (const std::exception& e)
1277 {
1278 log<level::ERR>("Exception caught in readChannelPersistData.",
1279 entry("MSG=%s", e.what()));
1280 ret = -EIO;
1281 }
1282 }
1283 return ret;
1284}
1285
1286int ChannelConfig::checkAndReloadVolatileData()
1287{
1288 std::time_t updateTime = getUpdatedFileTime(channelVolatileDataFilename);
1289 int ret = 0;
1290 if (updateTime != voltFileLastUpdatedTime || updateTime == -EIO)
1291 {
1292 try
1293 {
1294 ret = readChannelVolatileData();
1295 }
1296 catch (const std::exception& e)
1297 {
1298 log<level::ERR>("Exception caught in readChannelVolatileData.",
1299 entry("MSG=%s", e.what()));
1300 ret = -EIO;
1301 }
1302 }
1303 return ret;
1304}
1305
Johnathan Manteyf92261d2018-12-10 15:49:34 -08001306int ChannelConfig::setDbusProperty(const std::string& service,
AppaRao Puli9613ed72018-09-01 23:46:44 +05301307 const std::string& objPath,
1308 const std::string& interface,
1309 const std::string& property,
1310 const DbusVariant& value)
1311{
1312 try
1313 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001314 auto method = bus.new_method_call(service.c_str(), objPath.c_str(),
1315 "org.freedesktop.DBus.Properties",
1316 "Set");
AppaRao Puli9613ed72018-09-01 23:46:44 +05301317
1318 method.append(interface, property, value);
1319
1320 auto reply = bus.call(method);
1321 }
Patrick Williams5d82f472022-07-22 19:26:53 -05001322 catch (const sdbusplus::exception_t& e)
AppaRao Puli9613ed72018-09-01 23:46:44 +05301323 {
1324 log<level::DEBUG>("set-property failed",
Ayushi Smriti05ad3412019-10-16 16:10:18 +05301325 entry("SERVICE=%s", service.c_str()),
1326 entry("OBJPATH=%s", objPath.c_str()),
1327 entry("INTERFACE=%s", interface.c_str()),
1328 entry("PROP=%s", property.c_str()));
AppaRao Puli9613ed72018-09-01 23:46:44 +05301329 return -EIO;
1330 }
1331
1332 return 0;
1333}
1334
AppaRao Puli9613ed72018-09-01 23:46:44 +05301335int ChannelConfig::syncNetworkChannelConfig()
1336{
1337 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
1338 channelLock{*channelMutex};
1339 bool isUpdated = false;
1340 for (uint8_t chNum = 0; chNum < maxIpmiChannels; chNum++)
1341 {
1342 if (getChannelSessionSupport(chNum) != EChannelSessSupported::none)
1343 {
1344 std::string intfPrivStr;
Jiaqing Zhao826bf662022-11-07 14:33:00 +08001345 uint8_t intfPriv = 0;
AppaRao Puli9613ed72018-09-01 23:46:44 +05301346 try
1347 {
AppaRao Puli9613ed72018-09-01 23:46:44 +05301348 std::string networkIntfObj =
Richard Marian Thomaiyar73906b92019-01-04 23:48:02 +05301349 std::string(networkIntfObjectBasePath) + "/" +
1350 channelData[chNum].chName;
George Liu42f64ef2024-02-05 15:03:18 +08001351 auto propValue = ipmi::getDbusProperty(
1352 bus, networkIntfServiceName, networkIntfObj,
1353 networkChConfigIntfName, privilegePropertyString);
1354
1355 intfPrivStr = std::get<std::string>(propValue);
Jiaqing Zhao826bf662022-11-07 14:33:00 +08001356 intfPriv =
1357 static_cast<uint8_t>(convertToPrivLimitIndex(intfPrivStr));
AppaRao Puli9613ed72018-09-01 23:46:44 +05301358 }
Vernon Maueryf442e112019-04-09 11:44:36 -07001359 catch (const std::bad_variant_access& e)
AppaRao Puli9613ed72018-09-01 23:46:44 +05301360 {
1361 log<level::DEBUG>(
1362 "exception: Network interface does not exist");
1363 continue;
1364 }
Patrick Williams5d82f472022-07-22 19:26:53 -05001365 catch (const sdbusplus::exception_t& e)
AppaRao Puli9613ed72018-09-01 23:46:44 +05301366 {
1367 log<level::DEBUG>(
1368 "exception: Network interface does not exist");
1369 continue;
1370 }
Jiaqing Zhao826bf662022-11-07 14:33:00 +08001371 catch (const std::invalid_argument& e)
1372 {
1373 log<level::DEBUG>("exception: Invalid privilege");
1374 continue;
1375 }
AppaRao Puli9613ed72018-09-01 23:46:44 +05301376
AppaRao Puli9613ed72018-09-01 23:46:44 +05301377 if (channelData[chNum].chAccess.chNonVolatileData.privLimit !=
1378 intfPriv)
1379 {
1380 isUpdated = true;
1381 channelData[chNum].chAccess.chNonVolatileData.privLimit =
1382 intfPriv;
1383 channelData[chNum].chAccess.chVolatileData.privLimit = intfPriv;
1384 }
1385 }
1386 }
1387
1388 if (isUpdated)
1389 {
1390 // Write persistent data to file
1391 if (writeChannelPersistData() != 0)
1392 {
1393 log<level::DEBUG>("Failed to update the persistent data file");
1394 return -EIO;
1395 }
1396 // Write Volatile data to file
1397 if (writeChannelVolatileData() != 0)
1398 {
1399 log<level::DEBUG>("Failed to update the channel volatile data");
1400 return -EIO;
1401 }
1402 }
1403
1404 return 0;
1405}
1406
AppaRao Puli071f3f22018-05-24 16:45:30 +05301407void ChannelConfig::initChannelPersistData()
1408{
Richard Marian Thomaiyare91474c2019-09-01 23:02:47 +05301409 boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
1410 channelLock{*channelMutex};
1411
AppaRao Puli071f3f22018-05-24 16:45:30 +05301412 /* Always read the channel config */
1413 if (loadChannelConfig() != 0)
1414 {
1415 log<level::ERR>("Failed to read channel config file");
1416 throw std::ios_base::failure("Failed to load channel configuration");
1417 }
1418
1419 /* Populate the channel persist data */
1420 if (readChannelPersistData() != 0)
1421 {
1422 // Copy default NV data to RW location
Patrick Williams3d8d7932022-06-16 12:01:28 -05001423 std::filesystem::copy_file(channelAccessDefaultFilename,
1424 channelNvDataFilename);
AppaRao Puli071f3f22018-05-24 16:45:30 +05301425
1426 // Load the channel access NV data
1427 if (readChannelPersistData() != 0)
1428 {
1429 log<level::ERR>("Failed to read channel access NV data");
1430 throw std::ios_base::failure(
1431 "Failed to read channel access NV configuration");
1432 }
1433 }
1434
1435 // First check the volatile data file
1436 // If not present, load the default values
1437 if (readChannelVolatileData() != 0)
1438 {
1439 // Copy default volatile data to temporary location
1440 // NV file(channelNvDataFilename) must have created by now.
Patrick Williams3d8d7932022-06-16 12:01:28 -05001441 std::filesystem::copy_file(channelNvDataFilename,
1442 channelVolatileDataFilename);
AppaRao Puli071f3f22018-05-24 16:45:30 +05301443
1444 // Load the channel access volatile data
1445 if (readChannelVolatileData() != 0)
1446 {
1447 log<level::ERR>("Failed to read channel access volatile data");
1448 throw std::ios_base::failure(
1449 "Failed to read channel access volatile configuration");
1450 }
1451 }
AppaRao Puli9613ed72018-09-01 23:46:44 +05301452
1453 // Synchronize the channel config(priv) with network channel
1454 // configuration(priv) over dbus
1455 if (syncNetworkChannelConfig() != 0)
1456 {
1457 log<level::ERR>(
1458 "Failed to synchronize data with network channel config over dbus");
1459 throw std::ios_base::failure(
1460 "Failed to synchronize data with network channel config over dbus");
1461 }
1462
1463 log<level::DEBUG>("Successfully completed channel data initialization.");
AppaRao Puli071f3f22018-05-24 16:45:30 +05301464 return;
1465}
1466
1467} // namespace ipmi