blob: 0f2fc2f3e8f0bd9767156e4291ca278a36a9bd14 [file] [log] [blame]
Patrick Venture3a5071a2018-09-12 13:27:42 -07001#include "storagehandler.hpp"
2
3#include "fruread.hpp"
4#include "read_fru_data.hpp"
5#include "selutility.hpp"
6#include "sensorhandler.hpp"
7#include "storageaddsel.hpp"
Patrick Venture3a5071a2018-09-12 13:27:42 -07008
Lei YU52d91242017-10-17 22:52:28 +08009#include <arpa/inet.h>
Patrick Venture3a5071a2018-09-12 13:27:42 -070010#include <mapper.h>
11#include <systemd/sd-bus.h>
Patrick Venture0b02be92018-08-31 11:55:55 -070012
13#include <algorithm>
Lei YU52d91242017-10-17 22:52:28 +080014#include <chrono>
15#include <cstdio>
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070016#include <cstring>
Vernon Mauerybdda8002019-02-26 10:18:51 -080017#include <filesystem>
Vernon Mauerye08fbff2019-04-03 09:19:34 -070018#include <ipmid/api.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070019#include <ipmid/utils.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070020#include <phosphor-logging/elog-errors.hpp>
21#include <phosphor-logging/log.hpp>
22#include <sdbusplus/server.hpp>
23#include <string>
Vernon Mauery16b86932019-05-01 08:36:11 -070024#include <variant>
Patrick Venture3a5071a2018-09-12 13:27:42 -070025#include <xyz/openbmc_project/Common/error.hpp>
26
Chris Austenb4f5b922015-10-13 12:44:43 -050027void register_netfn_storage_functions() __attribute__((constructor));
28
Patrick Venture0b02be92018-08-31 11:55:55 -070029unsigned int g_sel_time = 0xFFFFFFFF;
Patrick Venturedb0cbe62019-09-09 14:47:22 -070030namespace ipmi
31{
32namespace sensor
33{
34extern const IdInfoMap sensors;
35} // namespace sensor
36} // namespace ipmi
37
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -060038extern const FruMap frus;
anil kumar appana2c7db1d2019-05-28 11:20:19 +000039constexpr uint8_t eventDataSize = 3;
Patrick Venture0b02be92018-08-31 11:55:55 -070040namespace
41{
Lei YUe8939392017-06-15 10:45:05 +080042constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime";
George Liu4d623e92020-05-25 16:51:57 +080043constexpr auto BMC_TIME_PATH = "/xyz/openbmc_project/time/bmc";
Lei YUe8939392017-06-15 10:45:05 +080044constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties";
Patrick Venture0b02be92018-08-31 11:55:55 -070045constexpr auto PROPERTY_ELAPSED = "Elapsed";
Lei YUe8939392017-06-15 10:45:05 +080046
Lei YUd9555252021-09-14 20:30:41 +080047constexpr auto logWatchPath = "/xyz/openbmc_project/logging";
Lei YUd9e57662021-09-14 18:06:28 +080048constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
49constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
50constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
Patrick Venture0b02be92018-08-31 11:55:55 -070051} // namespace
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +053052
Tom Joseph6f7deaa2017-06-30 19:03:54 +053053namespace cache
54{
Patrick Venture0b02be92018-08-31 11:55:55 -070055/*
56 * This cache contains the object paths of the logging entries sorted in the
57 * order of the filename(numeric order). The cache is initialized by
58 * invoking readLoggingObjectPaths with the cache as the parameter. The
59 * cache is invoked in the execution of the Get SEL info and Delete SEL
60 * entry command. The Get SEL Info command is typically invoked before the
61 * Get SEL entry command, so the cache is utilized for responding to Get SEL
62 * entry command. The cache is invalidated by clearing after Delete SEL
63 * entry and Clear SEL command.
64 */
65ipmi::sel::ObjectPaths paths;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053066
Patrick Venture0b02be92018-08-31 11:55:55 -070067} // namespace cache
Tom Joseph6f7deaa2017-06-30 19:03:54 +053068
69using InternalFailure =
Patrick Venture0b02be92018-08-31 11:55:55 -070070 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053071using namespace phosphor::logging;
Marri Devender Raocac383b2017-07-03 13:24:27 -050072using namespace ipmi::fru;
73
Lei YUd9e57662021-09-14 18:06:28 +080074using SELRecordID = uint16_t;
75using SELEntry = ipmi::sel::SELEventRecordFormat;
76using SELCacheMap = std::map<SELRecordID, SELEntry>;
77
78SELCacheMap selCacheMap __attribute__((init_priority(101)));
Lei YU3df36612021-09-15 11:41:11 +080079bool selCacheMapInitialized;
Lei YUd9555252021-09-14 20:30:41 +080080std::unique_ptr<sdbusplus::bus::match::match> selAddedMatch
81 __attribute__((init_priority(101)));
Lei YUb6b72b02021-09-14 21:06:05 +080082std::unique_ptr<sdbusplus::bus::match::match> selRemovedMatch
83 __attribute__((init_priority(101)));
Lei YU4106e422021-09-15 10:55:51 +080084std::unique_ptr<sdbusplus::bus::match::match> selUpdatedMatch
85 __attribute__((init_priority(101)));
Lei YUd9e57662021-09-14 18:06:28 +080086
Lei YUb6b72b02021-09-14 21:06:05 +080087static inline uint16_t getLoggingId(const std::string& p)
Lei YUd9e57662021-09-14 18:06:28 +080088{
89 namespace fs = std::filesystem;
90 fs::path entryPath(p);
Lei YUb6b72b02021-09-14 21:06:05 +080091 return std::stoul(entryPath.filename().string());
92}
93
94std::pair<uint16_t, SELEntry> parseLoggingEntry(const std::string& p)
95{
96 auto id = getLoggingId(p);
Lei YU3df36612021-09-15 11:41:11 +080097 ipmi::sel::GetSELEntryResponse record{};
98 try
99 {
100 record = ipmi::sel::convertLogEntrytoSEL(p);
101 }
102 catch (const std::exception& e)
103 {
104 fprintf(stderr, "Failed to convert %s to SEL: %s\n", p.c_str(),
105 e.what());
106 }
107 return {id, std::move(record.event)};
Lei YUd9e57662021-09-14 18:06:28 +0800108}
109
Lei YUd9555252021-09-14 20:30:41 +0800110static void selAddedCallback(sdbusplus::message::message& m)
111{
112 sdbusplus::message::object_path objPath;
113 try
114 {
115 m.read(objPath);
116 }
117 catch (const sdbusplus::exception::exception& e)
118 {
119 log<level::ERR>("Failed to read object path");
120 return;
121 }
122 std::string p = objPath;
123 selCacheMap.insert(parseLoggingEntry(p));
124}
125
Lei YUb6b72b02021-09-14 21:06:05 +0800126static void selRemovedCallback(sdbusplus::message::message& m)
127{
128 sdbusplus::message::object_path objPath;
129 try
130 {
131 m.read(objPath);
132 }
133 catch (const sdbusplus::exception::exception& e)
134 {
135 log<level::ERR>("Failed to read object path");
136 return;
137 }
138 std::string p = objPath;
139 selCacheMap.erase(getLoggingId(p));
140}
141
Lei YU4106e422021-09-15 10:55:51 +0800142static void selUpdatedCallback(sdbusplus::message::message& m)
143{
144 std::string p = m.get_path();
145 auto entry = parseLoggingEntry(p);
146 selCacheMap.insert_or_assign(entry.first, std::move(entry.second));
147}
148
Lei YUd9555252021-09-14 20:30:41 +0800149void registerSelCallbackHandler()
150{
151 using namespace sdbusplus::bus::match::rules;
152 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
153 if (!selAddedMatch)
154 {
155 selAddedMatch = std::make_unique<sdbusplus::bus::match::match>(
156 bus, interfacesAdded(logWatchPath),
157 std::bind(selAddedCallback, std::placeholders::_1));
158 }
Lei YUb6b72b02021-09-14 21:06:05 +0800159 if (!selRemovedMatch)
160 {
161 selRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
162 bus, interfacesRemoved(logWatchPath),
163 std::bind(selRemovedCallback, std::placeholders::_1));
164 }
Lei YU4106e422021-09-15 10:55:51 +0800165 if (!selUpdatedMatch)
166 {
167 selUpdatedMatch = std::make_unique<sdbusplus::bus::match::match>(
168 bus,
169 type::signal() + member("PropertiesChanged"s) +
170 interface("org.freedesktop.DBus.Properties"s) +
171 argN(0, logEntryIntf),
172 std::bind(selUpdatedCallback, std::placeholders::_1));
173 }
Lei YUd9555252021-09-14 20:30:41 +0800174}
175
Lei YUd9e57662021-09-14 18:06:28 +0800176void initSELCache()
177{
178 try
179 {
180 ipmi::sel::readLoggingObjectPaths(cache::paths);
181 }
182 catch (const sdbusplus::exception::exception& e)
183 {
184 log<level::ERR>("Failed to get logging object paths");
185 return;
186 }
187 for (const auto& p : cache::paths)
188 {
189 selCacheMap.insert(parseLoggingEntry(p));
190 }
Lei YUd9555252021-09-14 20:30:41 +0800191 registerSelCallbackHandler();
Lei YU3df36612021-09-15 11:41:11 +0800192 selCacheMapInitialized = true;
Lei YUd9e57662021-09-14 18:06:28 +0800193}
194
Marri Devender Raocac383b2017-07-03 13:24:27 -0500195/**
196 * @enum Device access mode
197 */
198enum class AccessMode
199{
200 bytes, ///< Device is accessed by bytes
201 words ///< Device is accessed by words
202};
203
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000204/** @brief implements the get SEL Info command
205 * @returns IPMI completion code plus response data
206 * - selVersion - SEL revision
207 * - entries - Number of log entries in SEL.
208 * - freeSpace - Free Space in bytes.
209 * - addTimeStamp - Most recent addition timestamp
210 * - eraseTimeStamp - Most recent erase timestamp
211 * - operationSupport - Reserve & Delete SEL operations supported
212 */
213
214ipmi::RspType<uint8_t, // SEL revision.
215 uint16_t, // number of log entries in SEL.
216 uint16_t, // free Space in bytes.
217 uint32_t, // most recent addition timestamp
218 uint32_t, // most recent erase timestamp.
219
220 bool, // SEL allocation info supported
221 bool, // reserve SEL supported
222 bool, // partial Add SEL Entry supported
223 bool, // delete SEL supported
224 uint3_t, // reserved
225 bool // overflow flag
226 >
227 ipmiStorageGetSelInfo()
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530228{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000229 uint16_t entries = 0;
230 // Most recent addition timestamp.
231 uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp;
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530232
Tom Josephe59abfb2018-08-06 18:46:27 +0530233 try
234 {
235 ipmi::sel::readLoggingObjectPaths(cache::paths);
236 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500237 catch (const sdbusplus::exception::exception& e)
Tom Josephe59abfb2018-08-06 18:46:27 +0530238 {
239 // No action if reading log objects have failed for this command.
240 // readLoggingObjectPaths will throw exception if there are no log
241 // entries. The command will be responded with number of SEL entries
242 // as 0.
243 }
244
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530245 if (!cache::paths.empty())
246 {
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000247 entries = static_cast<uint16_t>(cache::paths.size());
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530248
249 try
250 {
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000251 addTimeStamp = static_cast<uint32_t>(
Patrick Venture0b02be92018-08-31 11:55:55 -0700252 (ipmi::sel::getEntryTimeStamp(cache::paths.back()).count()));
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530253 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500254 catch (const InternalFailure& e)
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530255 {
256 }
257 catch (const std::runtime_error& e)
258 {
259 log<level::ERR>(e.what());
260 }
261 }
262
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000263 constexpr uint8_t selVersion = ipmi::sel::selVersion;
264 constexpr uint16_t freeSpace = 0xFFFF;
265 constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp;
266 constexpr uint3_t reserved{0};
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530267
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000268 return ipmi::responseSuccess(
269 selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp,
270 ipmi::sel::operationSupport::getSelAllocationInfo,
271 ipmi::sel::operationSupport::reserveSel,
272 ipmi::sel::operationSupport::partialAddSelEntry,
273 ipmi::sel::operationSupport::deleteSel, reserved,
274 ipmi::sel::operationSupport::overflow);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530275}
276
Tom Josepha4953392017-06-30 19:09:47 +0530277ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
278 ipmi_request_t request, ipmi_response_t response,
279 ipmi_data_len_t data_len, ipmi_context_t context)
280{
Jason M. Bills851acb12019-02-04 14:06:57 -0800281 if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest))
282 {
283 *data_len = 0;
284 return IPMI_CC_REQ_DATA_LEN_INVALID;
285 }
286
Patrick Venture0b02be92018-08-31 11:55:55 -0700287 auto requestData =
288 reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request);
Tom Josepha4953392017-06-30 19:09:47 +0530289
290 if (requestData->reservationID != 0)
291 {
Jason M. Bills13e67c82018-09-10 14:12:16 -0700292 if (!checkSELReservation(requestData->reservationID))
Tom Josepha4953392017-06-30 19:09:47 +0530293 {
294 *data_len = 0;
295 return IPMI_CC_INVALID_RESERVATION_ID;
296 }
297 }
298
Lei YU3df36612021-09-15 11:41:11 +0800299 if (!selCacheMapInitialized)
300 {
301 // In case the initSELCache() fails, try it again
302 initSELCache();
303 }
304
305 if (selCacheMap.empty())
Tom Josepha4953392017-06-30 19:09:47 +0530306 {
307 *data_len = 0;
308 return IPMI_CC_SENSOR_INVALID;
309 }
310
Lei YU3df36612021-09-15 11:41:11 +0800311 SELCacheMap::const_iterator iter;
Tom Josepha4953392017-06-30 19:09:47 +0530312
313 // Check for the requested SEL Entry.
314 if (requestData->selRecordID == ipmi::sel::firstEntry)
315 {
Lei YU3df36612021-09-15 11:41:11 +0800316 iter = selCacheMap.begin();
Tom Josepha4953392017-06-30 19:09:47 +0530317 }
318 else if (requestData->selRecordID == ipmi::sel::lastEntry)
319 {
Lei YU3df36612021-09-15 11:41:11 +0800320 if (selCacheMap.size() > 1)
321 {
322 iter = selCacheMap.end();
323 --iter;
324 }
325 else
326 {
327 // Only one entry exists, return the first
328 iter = selCacheMap.begin();
329 }
Tom Josepha4953392017-06-30 19:09:47 +0530330 }
331 else
332 {
Lei YU3df36612021-09-15 11:41:11 +0800333 iter = selCacheMap.find(requestData->selRecordID);
334 if (iter == selCacheMap.end())
Tom Josepha4953392017-06-30 19:09:47 +0530335 {
336 *data_len = 0;
337 return IPMI_CC_SENSOR_INVALID;
338 }
339 }
340
Lei YU3df36612021-09-15 11:41:11 +0800341 ipmi::sel::GetSELEntryResponse record{0, iter->second};
Tom Josepha4953392017-06-30 19:09:47 +0530342 // Identify the next SEL record ID
Lei YU3df36612021-09-15 11:41:11 +0800343 ++iter;
344 if (iter == selCacheMap.end())
Tom Josepha4953392017-06-30 19:09:47 +0530345 {
Lei YU3df36612021-09-15 11:41:11 +0800346 record.nextRecordID = ipmi::sel::lastEntry;
Tom Josepha4953392017-06-30 19:09:47 +0530347 }
348 else
349 {
Lei YU3df36612021-09-15 11:41:11 +0800350 record.nextRecordID = iter->first;
Tom Josepha4953392017-06-30 19:09:47 +0530351 }
352
353 if (requestData->readLength == ipmi::sel::entireRecord)
354 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700355 std::memcpy(response, &record, sizeof(record));
Tom Josepha4953392017-06-30 19:09:47 +0530356 *data_len = sizeof(record);
357 }
358 else
359 {
360 if (requestData->offset >= ipmi::sel::selRecordSize ||
361 requestData->readLength > ipmi::sel::selRecordSize)
362 {
363 *data_len = 0;
364 return IPMI_CC_INVALID_FIELD_REQUEST;
365 }
366
367 auto diff = ipmi::sel::selRecordSize - requestData->offset;
Patrick Venture0b02be92018-08-31 11:55:55 -0700368 auto readLength =
369 std::min(diff, static_cast<int>(requestData->readLength));
Tom Josepha4953392017-06-30 19:09:47 +0530370
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700371 std::memcpy(response, &record.nextRecordID,
372 sizeof(record.nextRecordID));
373 std::memcpy(static_cast<uint8_t*>(response) +
374 sizeof(record.nextRecordID),
Lei YUaf378fa2020-12-02 16:28:57 +0800375 &record.event.eventRecord.recordID + requestData->offset,
376 readLength);
Tom Josepha4953392017-06-30 19:09:47 +0530377 *data_len = sizeof(record.nextRecordID) + readLength;
378 }
379
380 return IPMI_CC_OK;
381}
382
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000383/** @brief implements the delete SEL entry command
384 * @request
385 * - reservationID; // reservation ID.
386 * - selRecordID; // SEL record ID.
387 *
388 * @returns ipmi completion code plus response data
389 * - Record ID of the deleted record
390 */
391ipmi::RspType<uint16_t // deleted record ID
392 >
393 deleteSELEntry(uint16_t reservationID, uint16_t selRecordID)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530394{
Jason M. Bills851acb12019-02-04 14:06:57 -0800395
Brad Bishop1a4117b2018-11-21 15:48:18 -0500396 namespace fs = std::filesystem;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530397
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000398 if (!checkSELReservation(reservationID))
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530399 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000400 return ipmi::responseInvalidReservationId();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530401 }
402
Jason M. Bills13e67c82018-09-10 14:12:16 -0700403 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
404 // deleted
405 cancelSELReservation();
406
Tom Josephe59abfb2018-08-06 18:46:27 +0530407 try
408 {
409 ipmi::sel::readLoggingObjectPaths(cache::paths);
410 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500411 catch (const sdbusplus::exception::exception& e)
Tom Josephe59abfb2018-08-06 18:46:27 +0530412 {
413 // readLoggingObjectPaths will throw exception if there are no error
414 // log entries.
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000415 return ipmi::responseSensorInvalid();
Tom Josephe59abfb2018-08-06 18:46:27 +0530416 }
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530417
418 if (cache::paths.empty())
419 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000420 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530421 }
422
423 ipmi::sel::ObjectPaths::const_iterator iter;
424 uint16_t delRecordID = 0;
425
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000426 if (selRecordID == ipmi::sel::firstEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530427 {
428 iter = cache::paths.begin();
429 fs::path path(*iter);
Patrick Venture0b02be92018-08-31 11:55:55 -0700430 delRecordID = static_cast<uint16_t>(
431 std::stoul(std::string(path.filename().c_str())));
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530432 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000433 else if (selRecordID == ipmi::sel::lastEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530434 {
435 iter = cache::paths.end();
436 fs::path path(*iter);
Patrick Venture0b02be92018-08-31 11:55:55 -0700437 delRecordID = static_cast<uint16_t>(
438 std::stoul(std::string(path.filename().c_str())));
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530439 }
440 else
441 {
442 std::string objPath = std::string(ipmi::sel::logBasePath) + "/" +
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000443 std::to_string(selRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530444
445 iter = std::find(cache::paths.begin(), cache::paths.end(), objPath);
446 if (iter == cache::paths.end())
447 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000448 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530449 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000450 delRecordID = selRecordID;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530451 }
452
453 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
454 std::string service;
455
456 try
457 {
458 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, *iter);
459 }
460 catch (const std::runtime_error& e)
461 {
462 log<level::ERR>(e.what());
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000463 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530464 }
465
Patrick Venture0b02be92018-08-31 11:55:55 -0700466 auto methodCall = bus.new_method_call(service.c_str(), (*iter).c_str(),
467 ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530468 auto reply = bus.call(methodCall);
469 if (reply.is_method_error())
470 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000471 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530472 }
473
474 // Invalidate the cache of dbus entry objects.
475 cache::paths.clear();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530476
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000477 return ipmi::responseSuccess(delRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530478}
479
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000480/** @brief implements the Clear SEL command
481 * @request
482 * - reservationID // Reservation ID.
483 * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) }
484 * - eraseOperation; // requested operation.
485 *
486 * @returns ipmi completion code plus response data
487 * - erase status
488 */
489
490ipmi::RspType<uint8_t // erase status
491 >
492 clearSEL(uint16_t reservationID, const std::array<char, 3>& clr,
493 uint8_t eraseOperation)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530494{
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000495 static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'};
496 if (clr != clrOk)
Jason M. Bills851acb12019-02-04 14:06:57 -0800497 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000498 return ipmi::responseInvalidFieldRequest();
Jason M. Bills851acb12019-02-04 14:06:57 -0800499 }
500
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000501 if (!checkSELReservation(reservationID))
Tom Joseph2f05bb52017-06-30 19:14:49 +0530502 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000503 return ipmi::responseInvalidReservationId();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530504 }
505
Tom Joseph2f05bb52017-06-30 19:14:49 +0530506 /*
507 * Erasure status cannot be fetched from DBUS, so always return erasure
508 * status as `erase completed`.
509 */
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000510 if (eraseOperation == ipmi::sel::getEraseStatus)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530511 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000512 return ipmi::responseSuccess(
513 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530514 }
515
Jason M. Bills13e67c82018-09-10 14:12:16 -0700516 // Per the IPMI spec, need to cancel any reservation when the SEL is cleared
517 cancelSELReservation();
518
Tom Joseph2f05bb52017-06-30 19:14:49 +0530519 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Tom Josephe59abfb2018-08-06 18:46:27 +0530520 ipmi::sel::ObjectPaths objectPaths;
Tom Joseph2f05bb52017-06-30 19:14:49 +0530521 auto depth = 0;
522
Patrick Venture0b02be92018-08-31 11:55:55 -0700523 auto mapperCall =
524 bus.new_method_call(ipmi::sel::mapperBusName, ipmi::sel::mapperObjPath,
525 ipmi::sel::mapperIntf, "GetSubTreePaths");
Tom Joseph2f05bb52017-06-30 19:14:49 +0530526 mapperCall.append(ipmi::sel::logBasePath);
527 mapperCall.append(depth);
528 mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf}));
529
Tom Josephe59abfb2018-08-06 18:46:27 +0530530 try
Tom Joseph2f05bb52017-06-30 19:14:49 +0530531 {
Tom Josephe59abfb2018-08-06 18:46:27 +0530532 auto reply = bus.call(mapperCall);
533 if (reply.is_method_error())
534 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000535 return ipmi::responseSuccess(
536 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Josephe59abfb2018-08-06 18:46:27 +0530537 }
Tom Joseph2f05bb52017-06-30 19:14:49 +0530538
Tom Josephe59abfb2018-08-06 18:46:27 +0530539 reply.read(objectPaths);
540 if (objectPaths.empty())
541 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000542 return ipmi::responseSuccess(
543 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Josephe59abfb2018-08-06 18:46:27 +0530544 }
545 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500546 catch (const sdbusplus::exception::exception& e)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530547 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000548 return ipmi::responseSuccess(
549 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530550 }
551
552 std::string service;
553
554 try
555 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700556 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf,
Tom Joseph2f05bb52017-06-30 19:14:49 +0530557 objectPaths.front());
558 }
559 catch (const std::runtime_error& e)
560 {
561 log<level::ERR>(e.what());
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000562 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530563 }
564
565 for (const auto& iter : objectPaths)
566 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700567 auto methodCall = bus.new_method_call(
568 service.c_str(), iter.c_str(), ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph2f05bb52017-06-30 19:14:49 +0530569
570 auto reply = bus.call(methodCall);
571 if (reply.is_method_error())
572 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000573 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530574 }
575 }
576
577 // Invalidate the cache of dbus entry objects.
578 cache::paths.clear();
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000579 return ipmi::responseSuccess(
580 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530581}
582
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000583/** @brief implements the get SEL time command
584 * @returns IPMI completion code plus response data
585 * -current time
586 */
587ipmi::RspType<uint32_t> // current time
588 ipmiStorageGetSelTime()
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500589{
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530590 using namespace std::chrono;
George Liu4d623e92020-05-25 16:51:57 +0800591 uint64_t bmc_time_usec = 0;
592 std::stringstream bmcTime;
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500593
Lei YUe8939392017-06-15 10:45:05 +0800594 try
595 {
596 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800597 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Vernon Mauery16b86932019-05-01 08:36:11 -0700598 std::variant<uint64_t> value;
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530599
George Liu4d623e92020-05-25 16:51:57 +0800600 // Get bmc time
601 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700602 DBUS_PROPERTIES, "Get");
Lei YUe8939392017-06-15 10:45:05 +0800603
604 method.append(TIME_INTERFACE, PROPERTY_ELAPSED);
605 auto reply = bus.call(method);
606 if (reply.is_method_error())
607 {
608 log<level::ERR>("Error getting time",
609 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800610 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000611 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800612 }
613 reply.read(value);
George Liu4d623e92020-05-25 16:51:57 +0800614 bmc_time_usec = std::get<uint64_t>(value);
Lei YUe8939392017-06-15 10:45:05 +0800615 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500616 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800617 {
618 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000619 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800620 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530621 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800622 {
623 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000624 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530625 }
626
George Liu4d623e92020-05-25 16:51:57 +0800627 bmcTime << "BMC time:"
628 << duration_cast<seconds>(microseconds(bmc_time_usec)).count();
629 log<level::DEBUG>(bmcTime.str().c_str());
Nagaraju Goruganti8960b7c2018-04-29 22:38:40 -0500630
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530631 // Time is really long int but IPMI wants just uint32. This works okay until
632 // the number of seconds since 1970 overflows uint32 size.. Still a whole
633 // lot of time here to even think about that.
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000634 return ipmi::responseSuccess(
George Liu4d623e92020-05-25 16:51:57 +0800635 duration_cast<seconds>(microseconds(bmc_time_usec)).count());
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500636}
637
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000638/** @brief implements the set SEL time command
639 * @param selDeviceTime - epoch time
640 * -local time as the number of seconds from 00:00:00, January 1, 1970
641 * @returns IPMI completion code
642 */
643ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime)
Chris Austenb4f5b922015-10-13 12:44:43 -0500644{
Lei YUe8939392017-06-15 10:45:05 +0800645 using namespace std::chrono;
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000646 microseconds usec{seconds(selDeviceTime)};
Norman James82330442015-11-19 16:53:26 -0600647
Lei YUe8939392017-06-15 10:45:05 +0800648 try
649 {
650 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800651 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Andrew Geissler6467ed22020-05-16 16:03:53 -0500652 std::variant<uint64_t> value{(uint64_t)usec.count()};
Lei YUe8939392017-06-15 10:45:05 +0800653
George Liu4d623e92020-05-25 16:51:57 +0800654 // Set bmc time
655 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700656 DBUS_PROPERTIES, "Set");
Lei YUe8939392017-06-15 10:45:05 +0800657
658 method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value);
659 auto reply = bus.call(method);
660 if (reply.is_method_error())
661 {
662 log<level::ERR>("Error setting time",
663 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800664 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000665 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800666 }
Norman James82330442015-11-19 16:53:26 -0600667 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500668 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800669 {
670 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000671 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530672 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530673 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800674 {
675 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000676 return ipmi::responseUnspecifiedError();
Norman James82330442015-11-19 16:53:26 -0600677 }
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530678
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000679 return ipmi::responseSuccess();
Chris Austenb4f5b922015-10-13 12:44:43 -0500680}
681
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000682/** @brief implements the reserve SEL command
683 * @returns IPMI completion code plus response data
684 * - SEL reservation ID.
685 */
686ipmi::RspType<uint16_t> ipmiStorageReserveSel()
Chris Austenb4f5b922015-10-13 12:44:43 -0500687{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000688 return ipmi::responseSuccess(reserveSel());
Chris Austenb4f5b922015-10-13 12:44:43 -0500689}
690
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000691/** @brief implements the Add SEL entry command
692 * @request
693 *
694 * - recordID ID used for SEL Record access
695 * - recordType Record Type
696 * - timeStamp Time when event was logged. LS byte first
697 * - generatorID software ID if event was generated from
698 * system software
699 * - evmRev event message format version
700 * - sensorType sensor type code for service that generated
701 * the event
702 * - sensorNumber number of sensors that generated the event
703 * - eventDir event dir
704 * - eventData event data field contents
705 *
706 * @returns ipmi completion code plus response data
707 * - RecordID of the Added SEL entry
708 */
709ipmi::RspType<uint16_t // recordID of the Added SEL entry
710 >
711 ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, uint32_t timeStamp,
712 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType,
713 uint8_t sensorNumber, uint8_t eventDir,
714 std::array<uint8_t, eventDataSize> eventData)
Chris Austenb4f5b922015-10-13 12:44:43 -0500715{
Jason M. Bills13e67c82018-09-10 14:12:16 -0700716 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
717 // added
718 cancelSELReservation();
Tom Josephb647d5b2017-10-31 17:25:33 +0530719 // Hostboot sends SEL with OEM record type 0xDE to indicate that there is
720 // a maintenance procedure associated with eSEL record.
721 static constexpr auto procedureType = 0xDE;
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000722 if (recordType == procedureType)
Tom Josephb647d5b2017-10-31 17:25:33 +0530723 {
724 // In the OEM record type 0xDE, byte 11 in the SEL record indicate the
725 // procedure number.
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000726 createProcedureLogEntry(sensorType);
Tom Josephb647d5b2017-10-31 17:25:33 +0530727 }
Chris Austenb4f5b922015-10-13 12:44:43 -0500728
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000729 return ipmi::responseSuccess(recordID);
Chris Austenb4f5b922015-10-13 12:44:43 -0500730}
731
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300732bool isFruPresent(const std::string& fruPath)
733{
734 using namespace ipmi::fru;
735
736 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
737
738 auto propValue =
739 ipmi::getDbusProperty(bus, invMgrInterface, invObjPath + fruPath,
740 invItemInterface, itemPresentProp);
741
742 return std::get<bool>(propValue);
743}
744
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000745/** @brief implements the get FRU Inventory Area Info command
746 *
747 * @returns IPMI completion code plus response data
748 * - FRU Inventory area size in bytes,
749 * - access bit
750 **/
751ipmi::RspType<uint16_t, // FRU Inventory area size in bytes,
752 uint8_t // access size (bytes / words)
753 >
754 ipmiStorageGetFruInvAreaInfo(uint8_t fruID)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500755{
Tom Joseph187f5642018-03-29 13:49:06 +0530756
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000757 auto iter = frus.find(fruID);
Tom Joseph187f5642018-03-29 13:49:06 +0530758 if (iter == frus.end())
759 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000760 return ipmi::responseSensorInvalid();
Tom Joseph187f5642018-03-29 13:49:06 +0530761 }
762
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300763 auto path = iter->second[0].path;
764 if (!isFruPresent(path))
765 {
766 return ipmi::responseSensorInvalid();
767 }
768
Marri Devender Raocac383b2017-07-03 13:24:27 -0500769 try
770 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000771 return ipmi::responseSuccess(
772 static_cast<uint16_t>(getFruAreaData(fruID).size()),
773 static_cast<uint8_t>(AccessMode::bytes));
Marri Devender Raocac383b2017-07-03 13:24:27 -0500774 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700775 catch (const InternalFailure& e)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500776 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500777 log<level::ERR>(e.what());
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000778 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500779 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500780}
781
anil kumar appana5b7c3262019-05-27 18:10:23 +0000782/**@brief implements the Read FRU Data command
783 * @param fruDeviceId - FRU device ID. FFh = reserved
784 * @param offset - FRU inventory offset to read
785 * @param readCount - count to read
786 *
787 * @return IPMI completion code plus response data
788 * - returnCount - response data count.
789 * - data - response data
790 */
791ipmi::RspType<uint8_t, // count returned
792 std::vector<uint8_t>> // FRU data
793 ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset,
794 uint8_t readCount)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500795{
anil kumar appana5b7c3262019-05-27 18:10:23 +0000796 if (fruDeviceId == 0xFF)
Tom Joseph187f5642018-03-29 13:49:06 +0530797 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000798 return ipmi::responseInvalidFieldRequest();
Tom Joseph187f5642018-03-29 13:49:06 +0530799 }
800
anil kumar appana5b7c3262019-05-27 18:10:23 +0000801 auto iter = frus.find(fruDeviceId);
802 if (iter == frus.end())
803 {
804 return ipmi::responseSensorInvalid();
805 }
806
Marri Devender Raocac383b2017-07-03 13:24:27 -0500807 try
808 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000809 const auto& fruArea = getFruAreaData(fruDeviceId);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500810 auto size = fruArea.size();
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500811
Tom Josephefcd68b2018-04-26 18:46:27 +0530812 if (offset >= size)
813 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000814 return ipmi::responseParmOutOfRange();
Tom Josephefcd68b2018-04-26 18:46:27 +0530815 }
816
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500817 // Write the count of response data.
anil kumar appana5b7c3262019-05-27 18:10:23 +0000818 uint8_t returnCount;
819 if ((offset + readCount) <= size)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500820 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000821 returnCount = readCount;
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500822 }
823 else
824 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000825 returnCount = size - offset;
Marri Devender Raocac383b2017-07-03 13:24:27 -0500826 }
Ratan Gupta2848d602018-01-31 20:39:20 +0530827
anil kumar appana5b7c3262019-05-27 18:10:23 +0000828 std::vector<uint8_t> fruData((fruArea.begin() + offset),
829 (fruArea.begin() + offset + returnCount));
Ratan Gupta2848d602018-01-31 20:39:20 +0530830
anil kumar appana5b7c3262019-05-27 18:10:23 +0000831 return ipmi::responseSuccess(returnCount, fruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500832 }
833 catch (const InternalFailure& e)
834 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500835 log<level::ERR>(e.what());
anil kumar appana5b7c3262019-05-27 18:10:23 +0000836 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500837 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500838}
839
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000840ipmi::RspType<uint8_t, // SDR version
841 uint16_t, // record count LS first
842 uint16_t, // free space in bytes, LS first
843 uint32_t, // addition timestamp LS first
844 uint32_t, // deletion timestamp LS first
845 uint8_t> // operation Support
846 ipmiGetRepositoryInfo()
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600847{
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600848
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000849 constexpr uint8_t sdrVersion = 0x51;
850 constexpr uint16_t freeSpace = 0xFFFF;
851 constexpr uint32_t additionTimestamp = 0x0;
852 constexpr uint32_t deletionTimestamp = 0x0;
853 constexpr uint8_t operationSupport = 0;
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600854
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700855 uint16_t records = frus.size() + ipmi::sensor::sensors.size();
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600856
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000857 return ipmi::responseSuccess(sdrVersion, records, freeSpace,
858 additionTimestamp, deletionTimestamp,
859 operationSupport);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600860}
Chris Austenb4f5b922015-10-13 12:44:43 -0500861
Chris Austenb4f5b922015-10-13 12:44:43 -0500862void register_netfn_storage_functions()
863{
Lei YU3df36612021-09-15 11:41:11 +0800864 selCacheMapInitialized = false;
Lei YUd9e57662021-09-14 18:06:28 +0800865 initSELCache();
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530866 // <Get SEL Info>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000867 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
868 ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
869 ipmiStorageGetSelInfo);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530870
Tom05732372016-09-06 17:21:23 +0530871 // <Get SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000872 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
873 ipmi::storage::cmdGetSelTime, ipmi::Privilege::User,
874 ipmiStorageGetSelTime);
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500875
Tom05732372016-09-06 17:21:23 +0530876 // <Set SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000877 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
878 ipmi::storage::cmdSetSelTime,
879 ipmi::Privilege::Operator, ipmiStorageSetSelTime);
Chris Austenb4f5b922015-10-13 12:44:43 -0500880
Tom05732372016-09-06 17:21:23 +0530881 // <Reserve SEL>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000882 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
883 ipmi::storage::cmdReserveSel, ipmi::Privilege::User,
884 ipmiStorageReserveSel);
Tom Josepha4953392017-06-30 19:09:47 +0530885 // <Get SEL Entry>
Patrick Venture0b02be92018-08-31 11:55:55 -0700886 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL,
887 getSELEntry, PRIVILEGE_USER);
Tom Josepha4953392017-06-30 19:09:47 +0530888
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530889 // <Delete SEL Entry>
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000890 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
891 ipmi::storage::cmdDeleteSelEntry,
892 ipmi::Privilege::Operator, deleteSELEntry);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530893
Tom05732372016-09-06 17:21:23 +0530894 // <Add SEL Entry>
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000895 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
896 ipmi::storage::cmdAddSelEntry,
897 ipmi::Privilege::Operator, ipmiStorageAddSEL);
898
Tom Joseph2f05bb52017-06-30 19:14:49 +0530899 // <Clear SEL>
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000900 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
901 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
902 clearSEL);
903
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500904 // <Get FRU Inventory Area Info>
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000905 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
906 ipmi::storage::cmdGetFruInventoryAreaInfo,
907 ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500908
Jason M. Billsb5248c92019-06-24 15:53:08 -0700909 // <READ FRU Data>
anil kumar appana5b7c3262019-05-27 18:10:23 +0000910 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
911 ipmi::storage::cmdReadFruData,
912 ipmi::Privilege::Operator, ipmiStorageReadFruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500913
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600914 // <Get Repository Info>
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000915 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
916 ipmi::storage::cmdGetSdrRepositoryInfo,
917 ipmi::Privilege::User, ipmiGetRepositoryInfo);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600918
Tom Joseph5ca50952018-02-22 00:33:38 +0530919 // <Reserve SDR Repository>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000920 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
921 ipmi::storage::cmdReserveSdrRepository,
922 ipmi::Privilege::User, ipmiSensorReserveSdr);
Tom Joseph5ca50952018-02-22 00:33:38 +0530923
924 // <Get SDR>
Patrick Venture0b02be92018-08-31 11:55:55 -0700925 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr,
926 ipmi_sen_get_sdr, PRIVILEGE_USER);
Tom Joseph5ca50952018-02-22 00:33:38 +0530927
Marri Devender Rao908f7502017-07-10 01:49:54 -0500928 ipmi::fru::registerCallbackHandler();
Chris Austenb4f5b922015-10-13 12:44:43 -0500929 return;
930}