blob: dd247c0373e9316ca51b5baaf24ad9ad3cd2be07 [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 YUd9555252021-09-14 20:30:41 +080079std::unique_ptr<sdbusplus::bus::match::match> selAddedMatch
80 __attribute__((init_priority(101)));
Lei YUb6b72b02021-09-14 21:06:05 +080081std::unique_ptr<sdbusplus::bus::match::match> selRemovedMatch
82 __attribute__((init_priority(101)));
Lei YU4106e422021-09-15 10:55:51 +080083std::unique_ptr<sdbusplus::bus::match::match> selUpdatedMatch
84 __attribute__((init_priority(101)));
Lei YUd9e57662021-09-14 18:06:28 +080085
Lei YUb6b72b02021-09-14 21:06:05 +080086static inline uint16_t getLoggingId(const std::string& p)
Lei YUd9e57662021-09-14 18:06:28 +080087{
88 namespace fs = std::filesystem;
89 fs::path entryPath(p);
Lei YUb6b72b02021-09-14 21:06:05 +080090 return std::stoul(entryPath.filename().string());
91}
92
93std::pair<uint16_t, SELEntry> parseLoggingEntry(const std::string& p)
94{
95 auto id = getLoggingId(p);
Lei YUd9e57662021-09-14 18:06:28 +080096 // TODO: parse the sel data
97 return {id, {}};
98}
99
Lei YUd9555252021-09-14 20:30:41 +0800100static void selAddedCallback(sdbusplus::message::message& m)
101{
102 sdbusplus::message::object_path objPath;
103 try
104 {
105 m.read(objPath);
106 }
107 catch (const sdbusplus::exception::exception& e)
108 {
109 log<level::ERR>("Failed to read object path");
110 return;
111 }
112 std::string p = objPath;
113 selCacheMap.insert(parseLoggingEntry(p));
114}
115
Lei YUb6b72b02021-09-14 21:06:05 +0800116static void selRemovedCallback(sdbusplus::message::message& m)
117{
118 sdbusplus::message::object_path objPath;
119 try
120 {
121 m.read(objPath);
122 }
123 catch (const sdbusplus::exception::exception& e)
124 {
125 log<level::ERR>("Failed to read object path");
126 return;
127 }
128 std::string p = objPath;
129 selCacheMap.erase(getLoggingId(p));
130}
131
Lei YU4106e422021-09-15 10:55:51 +0800132static void selUpdatedCallback(sdbusplus::message::message& m)
133{
134 std::string p = m.get_path();
135 auto entry = parseLoggingEntry(p);
136 selCacheMap.insert_or_assign(entry.first, std::move(entry.second));
137}
138
Lei YUd9555252021-09-14 20:30:41 +0800139void registerSelCallbackHandler()
140{
141 using namespace sdbusplus::bus::match::rules;
142 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
143 if (!selAddedMatch)
144 {
145 selAddedMatch = std::make_unique<sdbusplus::bus::match::match>(
146 bus, interfacesAdded(logWatchPath),
147 std::bind(selAddedCallback, std::placeholders::_1));
148 }
Lei YUb6b72b02021-09-14 21:06:05 +0800149 if (!selRemovedMatch)
150 {
151 selRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
152 bus, interfacesRemoved(logWatchPath),
153 std::bind(selRemovedCallback, std::placeholders::_1));
154 }
Lei YU4106e422021-09-15 10:55:51 +0800155 if (!selUpdatedMatch)
156 {
157 selUpdatedMatch = std::make_unique<sdbusplus::bus::match::match>(
158 bus,
159 type::signal() + member("PropertiesChanged"s) +
160 interface("org.freedesktop.DBus.Properties"s) +
161 argN(0, logEntryIntf),
162 std::bind(selUpdatedCallback, std::placeholders::_1));
163 }
Lei YUd9555252021-09-14 20:30:41 +0800164}
165
Lei YUd9e57662021-09-14 18:06:28 +0800166void initSELCache()
167{
168 try
169 {
170 ipmi::sel::readLoggingObjectPaths(cache::paths);
171 }
172 catch (const sdbusplus::exception::exception& e)
173 {
174 log<level::ERR>("Failed to get logging object paths");
175 return;
176 }
177 for (const auto& p : cache::paths)
178 {
179 selCacheMap.insert(parseLoggingEntry(p));
180 }
Lei YUd9555252021-09-14 20:30:41 +0800181 registerSelCallbackHandler();
Lei YUd9e57662021-09-14 18:06:28 +0800182}
183
Marri Devender Raocac383b2017-07-03 13:24:27 -0500184/**
185 * @enum Device access mode
186 */
187enum class AccessMode
188{
189 bytes, ///< Device is accessed by bytes
190 words ///< Device is accessed by words
191};
192
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000193/** @brief implements the get SEL Info command
194 * @returns IPMI completion code plus response data
195 * - selVersion - SEL revision
196 * - entries - Number of log entries in SEL.
197 * - freeSpace - Free Space in bytes.
198 * - addTimeStamp - Most recent addition timestamp
199 * - eraseTimeStamp - Most recent erase timestamp
200 * - operationSupport - Reserve & Delete SEL operations supported
201 */
202
203ipmi::RspType<uint8_t, // SEL revision.
204 uint16_t, // number of log entries in SEL.
205 uint16_t, // free Space in bytes.
206 uint32_t, // most recent addition timestamp
207 uint32_t, // most recent erase timestamp.
208
209 bool, // SEL allocation info supported
210 bool, // reserve SEL supported
211 bool, // partial Add SEL Entry supported
212 bool, // delete SEL supported
213 uint3_t, // reserved
214 bool // overflow flag
215 >
216 ipmiStorageGetSelInfo()
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530217{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000218 uint16_t entries = 0;
219 // Most recent addition timestamp.
220 uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp;
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530221
Tom Josephe59abfb2018-08-06 18:46:27 +0530222 try
223 {
224 ipmi::sel::readLoggingObjectPaths(cache::paths);
225 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500226 catch (const sdbusplus::exception::exception& e)
Tom Josephe59abfb2018-08-06 18:46:27 +0530227 {
228 // No action if reading log objects have failed for this command.
229 // readLoggingObjectPaths will throw exception if there are no log
230 // entries. The command will be responded with number of SEL entries
231 // as 0.
232 }
233
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530234 if (!cache::paths.empty())
235 {
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000236 entries = static_cast<uint16_t>(cache::paths.size());
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530237
238 try
239 {
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000240 addTimeStamp = static_cast<uint32_t>(
Patrick Venture0b02be92018-08-31 11:55:55 -0700241 (ipmi::sel::getEntryTimeStamp(cache::paths.back()).count()));
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530242 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500243 catch (const InternalFailure& e)
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530244 {
245 }
246 catch (const std::runtime_error& e)
247 {
248 log<level::ERR>(e.what());
249 }
250 }
251
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000252 constexpr uint8_t selVersion = ipmi::sel::selVersion;
253 constexpr uint16_t freeSpace = 0xFFFF;
254 constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp;
255 constexpr uint3_t reserved{0};
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530256
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000257 return ipmi::responseSuccess(
258 selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp,
259 ipmi::sel::operationSupport::getSelAllocationInfo,
260 ipmi::sel::operationSupport::reserveSel,
261 ipmi::sel::operationSupport::partialAddSelEntry,
262 ipmi::sel::operationSupport::deleteSel, reserved,
263 ipmi::sel::operationSupport::overflow);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530264}
265
Tom Josepha4953392017-06-30 19:09:47 +0530266ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
267 ipmi_request_t request, ipmi_response_t response,
268 ipmi_data_len_t data_len, ipmi_context_t context)
269{
Jason M. Bills851acb12019-02-04 14:06:57 -0800270 if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest))
271 {
272 *data_len = 0;
273 return IPMI_CC_REQ_DATA_LEN_INVALID;
274 }
275
Patrick Venture0b02be92018-08-31 11:55:55 -0700276 auto requestData =
277 reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request);
Tom Josepha4953392017-06-30 19:09:47 +0530278
279 if (requestData->reservationID != 0)
280 {
Jason M. Bills13e67c82018-09-10 14:12:16 -0700281 if (!checkSELReservation(requestData->reservationID))
Tom Josepha4953392017-06-30 19:09:47 +0530282 {
283 *data_len = 0;
284 return IPMI_CC_INVALID_RESERVATION_ID;
285 }
286 }
287
288 if (cache::paths.empty())
289 {
290 *data_len = 0;
291 return IPMI_CC_SENSOR_INVALID;
292 }
293
294 ipmi::sel::ObjectPaths::const_iterator iter;
295
296 // Check for the requested SEL Entry.
297 if (requestData->selRecordID == ipmi::sel::firstEntry)
298 {
299 iter = cache::paths.begin();
300 }
301 else if (requestData->selRecordID == ipmi::sel::lastEntry)
302 {
303 iter = cache::paths.end();
304 }
305 else
306 {
307 std::string objPath = std::string(ipmi::sel::logBasePath) + "/" +
308 std::to_string(requestData->selRecordID);
309
310 iter = std::find(cache::paths.begin(), cache::paths.end(), objPath);
311 if (iter == cache::paths.end())
312 {
313 *data_len = 0;
314 return IPMI_CC_SENSOR_INVALID;
315 }
316 }
317
Patrick Venture0b02be92018-08-31 11:55:55 -0700318 ipmi::sel::GetSELEntryResponse record{};
Tom Josepha4953392017-06-30 19:09:47 +0530319
320 // Convert the log entry into SEL record.
321 try
322 {
323 record = ipmi::sel::convertLogEntrytoSEL(*iter);
324 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500325 catch (const InternalFailure& e)
Tom Josepha4953392017-06-30 19:09:47 +0530326 {
327 *data_len = 0;
328 return IPMI_CC_UNSPECIFIED_ERROR;
329 }
330 catch (const std::runtime_error& e)
331 {
332 log<level::ERR>(e.what());
333 *data_len = 0;
334 return IPMI_CC_UNSPECIFIED_ERROR;
335 }
336
Tom Josepha4953392017-06-30 19:09:47 +0530337 // Identify the next SEL record ID
Patrick Venture0b02be92018-08-31 11:55:55 -0700338 if (iter != cache::paths.end())
Tom Josepha4953392017-06-30 19:09:47 +0530339 {
340 ++iter;
341 if (iter == cache::paths.end())
342 {
343 record.nextRecordID = ipmi::sel::lastEntry;
344 }
345 else
346 {
Vernon Mauery185b9f82018-07-20 10:52:36 -0700347 namespace fs = std::filesystem;
Tom Josepha4953392017-06-30 19:09:47 +0530348 fs::path path(*iter);
Patrick Venture0b02be92018-08-31 11:55:55 -0700349 record.nextRecordID = static_cast<uint16_t>(
350 std::stoul(std::string(path.filename().c_str())));
Tom Josepha4953392017-06-30 19:09:47 +0530351 }
352 }
353 else
354 {
355 record.nextRecordID = ipmi::sel::lastEntry;
356 }
357
358 if (requestData->readLength == ipmi::sel::entireRecord)
359 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700360 std::memcpy(response, &record, sizeof(record));
Tom Josepha4953392017-06-30 19:09:47 +0530361 *data_len = sizeof(record);
362 }
363 else
364 {
365 if (requestData->offset >= ipmi::sel::selRecordSize ||
366 requestData->readLength > ipmi::sel::selRecordSize)
367 {
368 *data_len = 0;
369 return IPMI_CC_INVALID_FIELD_REQUEST;
370 }
371
372 auto diff = ipmi::sel::selRecordSize - requestData->offset;
Patrick Venture0b02be92018-08-31 11:55:55 -0700373 auto readLength =
374 std::min(diff, static_cast<int>(requestData->readLength));
Tom Josepha4953392017-06-30 19:09:47 +0530375
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700376 std::memcpy(response, &record.nextRecordID,
377 sizeof(record.nextRecordID));
378 std::memcpy(static_cast<uint8_t*>(response) +
379 sizeof(record.nextRecordID),
Lei YUaf378fa2020-12-02 16:28:57 +0800380 &record.event.eventRecord.recordID + requestData->offset,
381 readLength);
Tom Josepha4953392017-06-30 19:09:47 +0530382 *data_len = sizeof(record.nextRecordID) + readLength;
383 }
384
385 return IPMI_CC_OK;
386}
387
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000388/** @brief implements the delete SEL entry command
389 * @request
390 * - reservationID; // reservation ID.
391 * - selRecordID; // SEL record ID.
392 *
393 * @returns ipmi completion code plus response data
394 * - Record ID of the deleted record
395 */
396ipmi::RspType<uint16_t // deleted record ID
397 >
398 deleteSELEntry(uint16_t reservationID, uint16_t selRecordID)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530399{
Jason M. Bills851acb12019-02-04 14:06:57 -0800400
Brad Bishop1a4117b2018-11-21 15:48:18 -0500401 namespace fs = std::filesystem;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530402
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000403 if (!checkSELReservation(reservationID))
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530404 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000405 return ipmi::responseInvalidReservationId();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530406 }
407
Jason M. Bills13e67c82018-09-10 14:12:16 -0700408 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
409 // deleted
410 cancelSELReservation();
411
Tom Josephe59abfb2018-08-06 18:46:27 +0530412 try
413 {
414 ipmi::sel::readLoggingObjectPaths(cache::paths);
415 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500416 catch (const sdbusplus::exception::exception& e)
Tom Josephe59abfb2018-08-06 18:46:27 +0530417 {
418 // readLoggingObjectPaths will throw exception if there are no error
419 // log entries.
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000420 return ipmi::responseSensorInvalid();
Tom Josephe59abfb2018-08-06 18:46:27 +0530421 }
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530422
423 if (cache::paths.empty())
424 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000425 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530426 }
427
428 ipmi::sel::ObjectPaths::const_iterator iter;
429 uint16_t delRecordID = 0;
430
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000431 if (selRecordID == ipmi::sel::firstEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530432 {
433 iter = cache::paths.begin();
434 fs::path path(*iter);
Patrick Venture0b02be92018-08-31 11:55:55 -0700435 delRecordID = static_cast<uint16_t>(
436 std::stoul(std::string(path.filename().c_str())));
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530437 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000438 else if (selRecordID == ipmi::sel::lastEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530439 {
440 iter = cache::paths.end();
441 fs::path path(*iter);
Patrick Venture0b02be92018-08-31 11:55:55 -0700442 delRecordID = static_cast<uint16_t>(
443 std::stoul(std::string(path.filename().c_str())));
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530444 }
445 else
446 {
447 std::string objPath = std::string(ipmi::sel::logBasePath) + "/" +
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000448 std::to_string(selRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530449
450 iter = std::find(cache::paths.begin(), cache::paths.end(), objPath);
451 if (iter == cache::paths.end())
452 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000453 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530454 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000455 delRecordID = selRecordID;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530456 }
457
458 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
459 std::string service;
460
461 try
462 {
463 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, *iter);
464 }
465 catch (const std::runtime_error& e)
466 {
467 log<level::ERR>(e.what());
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000468 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530469 }
470
Patrick Venture0b02be92018-08-31 11:55:55 -0700471 auto methodCall = bus.new_method_call(service.c_str(), (*iter).c_str(),
472 ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530473 auto reply = bus.call(methodCall);
474 if (reply.is_method_error())
475 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000476 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530477 }
478
479 // Invalidate the cache of dbus entry objects.
480 cache::paths.clear();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530481
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000482 return ipmi::responseSuccess(delRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530483}
484
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000485/** @brief implements the Clear SEL command
486 * @request
487 * - reservationID // Reservation ID.
488 * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) }
489 * - eraseOperation; // requested operation.
490 *
491 * @returns ipmi completion code plus response data
492 * - erase status
493 */
494
495ipmi::RspType<uint8_t // erase status
496 >
497 clearSEL(uint16_t reservationID, const std::array<char, 3>& clr,
498 uint8_t eraseOperation)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530499{
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000500 static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'};
501 if (clr != clrOk)
Jason M. Bills851acb12019-02-04 14:06:57 -0800502 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000503 return ipmi::responseInvalidFieldRequest();
Jason M. Bills851acb12019-02-04 14:06:57 -0800504 }
505
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000506 if (!checkSELReservation(reservationID))
Tom Joseph2f05bb52017-06-30 19:14:49 +0530507 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000508 return ipmi::responseInvalidReservationId();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530509 }
510
Tom Joseph2f05bb52017-06-30 19:14:49 +0530511 /*
512 * Erasure status cannot be fetched from DBUS, so always return erasure
513 * status as `erase completed`.
514 */
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000515 if (eraseOperation == ipmi::sel::getEraseStatus)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530516 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000517 return ipmi::responseSuccess(
518 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530519 }
520
Jason M. Bills13e67c82018-09-10 14:12:16 -0700521 // Per the IPMI spec, need to cancel any reservation when the SEL is cleared
522 cancelSELReservation();
523
Tom Joseph2f05bb52017-06-30 19:14:49 +0530524 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Tom Josephe59abfb2018-08-06 18:46:27 +0530525 ipmi::sel::ObjectPaths objectPaths;
Tom Joseph2f05bb52017-06-30 19:14:49 +0530526 auto depth = 0;
527
Patrick Venture0b02be92018-08-31 11:55:55 -0700528 auto mapperCall =
529 bus.new_method_call(ipmi::sel::mapperBusName, ipmi::sel::mapperObjPath,
530 ipmi::sel::mapperIntf, "GetSubTreePaths");
Tom Joseph2f05bb52017-06-30 19:14:49 +0530531 mapperCall.append(ipmi::sel::logBasePath);
532 mapperCall.append(depth);
533 mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf}));
534
Tom Josephe59abfb2018-08-06 18:46:27 +0530535 try
Tom Joseph2f05bb52017-06-30 19:14:49 +0530536 {
Tom Josephe59abfb2018-08-06 18:46:27 +0530537 auto reply = bus.call(mapperCall);
538 if (reply.is_method_error())
539 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000540 return ipmi::responseSuccess(
541 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Josephe59abfb2018-08-06 18:46:27 +0530542 }
Tom Joseph2f05bb52017-06-30 19:14:49 +0530543
Tom Josephe59abfb2018-08-06 18:46:27 +0530544 reply.read(objectPaths);
545 if (objectPaths.empty())
546 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000547 return ipmi::responseSuccess(
548 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Josephe59abfb2018-08-06 18:46:27 +0530549 }
550 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500551 catch (const sdbusplus::exception::exception& e)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530552 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000553 return ipmi::responseSuccess(
554 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530555 }
556
557 std::string service;
558
559 try
560 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700561 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf,
Tom Joseph2f05bb52017-06-30 19:14:49 +0530562 objectPaths.front());
563 }
564 catch (const std::runtime_error& e)
565 {
566 log<level::ERR>(e.what());
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000567 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530568 }
569
570 for (const auto& iter : objectPaths)
571 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700572 auto methodCall = bus.new_method_call(
573 service.c_str(), iter.c_str(), ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph2f05bb52017-06-30 19:14:49 +0530574
575 auto reply = bus.call(methodCall);
576 if (reply.is_method_error())
577 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000578 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530579 }
580 }
581
582 // Invalidate the cache of dbus entry objects.
583 cache::paths.clear();
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000584 return ipmi::responseSuccess(
585 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530586}
587
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000588/** @brief implements the get SEL time command
589 * @returns IPMI completion code plus response data
590 * -current time
591 */
592ipmi::RspType<uint32_t> // current time
593 ipmiStorageGetSelTime()
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500594{
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530595 using namespace std::chrono;
George Liu4d623e92020-05-25 16:51:57 +0800596 uint64_t bmc_time_usec = 0;
597 std::stringstream bmcTime;
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500598
Lei YUe8939392017-06-15 10:45:05 +0800599 try
600 {
601 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800602 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Vernon Mauery16b86932019-05-01 08:36:11 -0700603 std::variant<uint64_t> value;
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530604
George Liu4d623e92020-05-25 16:51:57 +0800605 // Get bmc time
606 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700607 DBUS_PROPERTIES, "Get");
Lei YUe8939392017-06-15 10:45:05 +0800608
609 method.append(TIME_INTERFACE, PROPERTY_ELAPSED);
610 auto reply = bus.call(method);
611 if (reply.is_method_error())
612 {
613 log<level::ERR>("Error getting time",
614 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800615 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000616 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800617 }
618 reply.read(value);
George Liu4d623e92020-05-25 16:51:57 +0800619 bmc_time_usec = std::get<uint64_t>(value);
Lei YUe8939392017-06-15 10:45:05 +0800620 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500621 catch (const InternalFailure& 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();
Lei YUe8939392017-06-15 10:45:05 +0800625 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530626 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800627 {
628 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000629 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530630 }
631
George Liu4d623e92020-05-25 16:51:57 +0800632 bmcTime << "BMC time:"
633 << duration_cast<seconds>(microseconds(bmc_time_usec)).count();
634 log<level::DEBUG>(bmcTime.str().c_str());
Nagaraju Goruganti8960b7c2018-04-29 22:38:40 -0500635
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530636 // Time is really long int but IPMI wants just uint32. This works okay until
637 // the number of seconds since 1970 overflows uint32 size.. Still a whole
638 // lot of time here to even think about that.
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000639 return ipmi::responseSuccess(
George Liu4d623e92020-05-25 16:51:57 +0800640 duration_cast<seconds>(microseconds(bmc_time_usec)).count());
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500641}
642
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000643/** @brief implements the set SEL time command
644 * @param selDeviceTime - epoch time
645 * -local time as the number of seconds from 00:00:00, January 1, 1970
646 * @returns IPMI completion code
647 */
648ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime)
Chris Austenb4f5b922015-10-13 12:44:43 -0500649{
Lei YUe8939392017-06-15 10:45:05 +0800650 using namespace std::chrono;
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000651 microseconds usec{seconds(selDeviceTime)};
Norman James82330442015-11-19 16:53:26 -0600652
Lei YUe8939392017-06-15 10:45:05 +0800653 try
654 {
655 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800656 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Andrew Geissler6467ed22020-05-16 16:03:53 -0500657 std::variant<uint64_t> value{(uint64_t)usec.count()};
Lei YUe8939392017-06-15 10:45:05 +0800658
George Liu4d623e92020-05-25 16:51:57 +0800659 // Set bmc time
660 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700661 DBUS_PROPERTIES, "Set");
Lei YUe8939392017-06-15 10:45:05 +0800662
663 method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value);
664 auto reply = bus.call(method);
665 if (reply.is_method_error())
666 {
667 log<level::ERR>("Error setting time",
668 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800669 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000670 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800671 }
Norman James82330442015-11-19 16:53:26 -0600672 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500673 catch (const InternalFailure& 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();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530677 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530678 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800679 {
680 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000681 return ipmi::responseUnspecifiedError();
Norman James82330442015-11-19 16:53:26 -0600682 }
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530683
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000684 return ipmi::responseSuccess();
Chris Austenb4f5b922015-10-13 12:44:43 -0500685}
686
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000687/** @brief implements the reserve SEL command
688 * @returns IPMI completion code plus response data
689 * - SEL reservation ID.
690 */
691ipmi::RspType<uint16_t> ipmiStorageReserveSel()
Chris Austenb4f5b922015-10-13 12:44:43 -0500692{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000693 return ipmi::responseSuccess(reserveSel());
Chris Austenb4f5b922015-10-13 12:44:43 -0500694}
695
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000696/** @brief implements the Add SEL entry command
697 * @request
698 *
699 * - recordID ID used for SEL Record access
700 * - recordType Record Type
701 * - timeStamp Time when event was logged. LS byte first
702 * - generatorID software ID if event was generated from
703 * system software
704 * - evmRev event message format version
705 * - sensorType sensor type code for service that generated
706 * the event
707 * - sensorNumber number of sensors that generated the event
708 * - eventDir event dir
709 * - eventData event data field contents
710 *
711 * @returns ipmi completion code plus response data
712 * - RecordID of the Added SEL entry
713 */
714ipmi::RspType<uint16_t // recordID of the Added SEL entry
715 >
716 ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, uint32_t timeStamp,
717 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType,
718 uint8_t sensorNumber, uint8_t eventDir,
719 std::array<uint8_t, eventDataSize> eventData)
Chris Austenb4f5b922015-10-13 12:44:43 -0500720{
Jason M. Bills13e67c82018-09-10 14:12:16 -0700721 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
722 // added
723 cancelSELReservation();
Tom Josephb647d5b2017-10-31 17:25:33 +0530724 // Hostboot sends SEL with OEM record type 0xDE to indicate that there is
725 // a maintenance procedure associated with eSEL record.
726 static constexpr auto procedureType = 0xDE;
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000727 if (recordType == procedureType)
Tom Josephb647d5b2017-10-31 17:25:33 +0530728 {
729 // In the OEM record type 0xDE, byte 11 in the SEL record indicate the
730 // procedure number.
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000731 createProcedureLogEntry(sensorType);
Tom Josephb647d5b2017-10-31 17:25:33 +0530732 }
Chris Austenb4f5b922015-10-13 12:44:43 -0500733
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000734 return ipmi::responseSuccess(recordID);
Chris Austenb4f5b922015-10-13 12:44:43 -0500735}
736
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300737bool isFruPresent(const std::string& fruPath)
738{
739 using namespace ipmi::fru;
740
741 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
742
743 auto propValue =
744 ipmi::getDbusProperty(bus, invMgrInterface, invObjPath + fruPath,
745 invItemInterface, itemPresentProp);
746
747 return std::get<bool>(propValue);
748}
749
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000750/** @brief implements the get FRU Inventory Area Info command
751 *
752 * @returns IPMI completion code plus response data
753 * - FRU Inventory area size in bytes,
754 * - access bit
755 **/
756ipmi::RspType<uint16_t, // FRU Inventory area size in bytes,
757 uint8_t // access size (bytes / words)
758 >
759 ipmiStorageGetFruInvAreaInfo(uint8_t fruID)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500760{
Tom Joseph187f5642018-03-29 13:49:06 +0530761
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000762 auto iter = frus.find(fruID);
Tom Joseph187f5642018-03-29 13:49:06 +0530763 if (iter == frus.end())
764 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000765 return ipmi::responseSensorInvalid();
Tom Joseph187f5642018-03-29 13:49:06 +0530766 }
767
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300768 auto path = iter->second[0].path;
769 if (!isFruPresent(path))
770 {
771 return ipmi::responseSensorInvalid();
772 }
773
Marri Devender Raocac383b2017-07-03 13:24:27 -0500774 try
775 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000776 return ipmi::responseSuccess(
777 static_cast<uint16_t>(getFruAreaData(fruID).size()),
778 static_cast<uint8_t>(AccessMode::bytes));
Marri Devender Raocac383b2017-07-03 13:24:27 -0500779 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700780 catch (const InternalFailure& e)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500781 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500782 log<level::ERR>(e.what());
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000783 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500784 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500785}
786
anil kumar appana5b7c3262019-05-27 18:10:23 +0000787/**@brief implements the Read FRU Data command
788 * @param fruDeviceId - FRU device ID. FFh = reserved
789 * @param offset - FRU inventory offset to read
790 * @param readCount - count to read
791 *
792 * @return IPMI completion code plus response data
793 * - returnCount - response data count.
794 * - data - response data
795 */
796ipmi::RspType<uint8_t, // count returned
797 std::vector<uint8_t>> // FRU data
798 ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset,
799 uint8_t readCount)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500800{
anil kumar appana5b7c3262019-05-27 18:10:23 +0000801 if (fruDeviceId == 0xFF)
Tom Joseph187f5642018-03-29 13:49:06 +0530802 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000803 return ipmi::responseInvalidFieldRequest();
Tom Joseph187f5642018-03-29 13:49:06 +0530804 }
805
anil kumar appana5b7c3262019-05-27 18:10:23 +0000806 auto iter = frus.find(fruDeviceId);
807 if (iter == frus.end())
808 {
809 return ipmi::responseSensorInvalid();
810 }
811
Marri Devender Raocac383b2017-07-03 13:24:27 -0500812 try
813 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000814 const auto& fruArea = getFruAreaData(fruDeviceId);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500815 auto size = fruArea.size();
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500816
Tom Josephefcd68b2018-04-26 18:46:27 +0530817 if (offset >= size)
818 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000819 return ipmi::responseParmOutOfRange();
Tom Josephefcd68b2018-04-26 18:46:27 +0530820 }
821
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500822 // Write the count of response data.
anil kumar appana5b7c3262019-05-27 18:10:23 +0000823 uint8_t returnCount;
824 if ((offset + readCount) <= size)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500825 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000826 returnCount = readCount;
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500827 }
828 else
829 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000830 returnCount = size - offset;
Marri Devender Raocac383b2017-07-03 13:24:27 -0500831 }
Ratan Gupta2848d602018-01-31 20:39:20 +0530832
anil kumar appana5b7c3262019-05-27 18:10:23 +0000833 std::vector<uint8_t> fruData((fruArea.begin() + offset),
834 (fruArea.begin() + offset + returnCount));
Ratan Gupta2848d602018-01-31 20:39:20 +0530835
anil kumar appana5b7c3262019-05-27 18:10:23 +0000836 return ipmi::responseSuccess(returnCount, fruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500837 }
838 catch (const InternalFailure& e)
839 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500840 log<level::ERR>(e.what());
anil kumar appana5b7c3262019-05-27 18:10:23 +0000841 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500842 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500843}
844
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000845ipmi::RspType<uint8_t, // SDR version
846 uint16_t, // record count LS first
847 uint16_t, // free space in bytes, LS first
848 uint32_t, // addition timestamp LS first
849 uint32_t, // deletion timestamp LS first
850 uint8_t> // operation Support
851 ipmiGetRepositoryInfo()
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600852{
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600853
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000854 constexpr uint8_t sdrVersion = 0x51;
855 constexpr uint16_t freeSpace = 0xFFFF;
856 constexpr uint32_t additionTimestamp = 0x0;
857 constexpr uint32_t deletionTimestamp = 0x0;
858 constexpr uint8_t operationSupport = 0;
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600859
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700860 uint16_t records = frus.size() + ipmi::sensor::sensors.size();
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600861
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000862 return ipmi::responseSuccess(sdrVersion, records, freeSpace,
863 additionTimestamp, deletionTimestamp,
864 operationSupport);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600865}
Chris Austenb4f5b922015-10-13 12:44:43 -0500866
Chris Austenb4f5b922015-10-13 12:44:43 -0500867void register_netfn_storage_functions()
868{
Lei YUd9e57662021-09-14 18:06:28 +0800869 initSELCache();
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530870 // <Get SEL Info>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000871 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
872 ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
873 ipmiStorageGetSelInfo);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530874
Tom05732372016-09-06 17:21:23 +0530875 // <Get SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000876 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
877 ipmi::storage::cmdGetSelTime, ipmi::Privilege::User,
878 ipmiStorageGetSelTime);
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500879
Tom05732372016-09-06 17:21:23 +0530880 // <Set SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000881 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
882 ipmi::storage::cmdSetSelTime,
883 ipmi::Privilege::Operator, ipmiStorageSetSelTime);
Chris Austenb4f5b922015-10-13 12:44:43 -0500884
Tom05732372016-09-06 17:21:23 +0530885 // <Reserve SEL>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000886 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
887 ipmi::storage::cmdReserveSel, ipmi::Privilege::User,
888 ipmiStorageReserveSel);
Tom Josepha4953392017-06-30 19:09:47 +0530889 // <Get SEL Entry>
Patrick Venture0b02be92018-08-31 11:55:55 -0700890 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL,
891 getSELEntry, PRIVILEGE_USER);
Tom Josepha4953392017-06-30 19:09:47 +0530892
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530893 // <Delete SEL Entry>
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000894 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
895 ipmi::storage::cmdDeleteSelEntry,
896 ipmi::Privilege::Operator, deleteSELEntry);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530897
Tom05732372016-09-06 17:21:23 +0530898 // <Add SEL Entry>
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000899 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
900 ipmi::storage::cmdAddSelEntry,
901 ipmi::Privilege::Operator, ipmiStorageAddSEL);
902
Tom Joseph2f05bb52017-06-30 19:14:49 +0530903 // <Clear SEL>
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000904 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
905 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
906 clearSEL);
907
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500908 // <Get FRU Inventory Area Info>
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000909 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
910 ipmi::storage::cmdGetFruInventoryAreaInfo,
911 ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500912
Jason M. Billsb5248c92019-06-24 15:53:08 -0700913 // <READ FRU Data>
anil kumar appana5b7c3262019-05-27 18:10:23 +0000914 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
915 ipmi::storage::cmdReadFruData,
916 ipmi::Privilege::Operator, ipmiStorageReadFruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500917
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600918 // <Get Repository Info>
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000919 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
920 ipmi::storage::cmdGetSdrRepositoryInfo,
921 ipmi::Privilege::User, ipmiGetRepositoryInfo);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600922
Tom Joseph5ca50952018-02-22 00:33:38 +0530923 // <Reserve SDR Repository>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000924 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
925 ipmi::storage::cmdReserveSdrRepository,
926 ipmi::Privilege::User, ipmiSensorReserveSdr);
Tom Joseph5ca50952018-02-22 00:33:38 +0530927
928 // <Get SDR>
Patrick Venture0b02be92018-08-31 11:55:55 -0700929 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr,
930 ipmi_sen_get_sdr, PRIVILEGE_USER);
Tom Joseph5ca50952018-02-22 00:33:38 +0530931
Marri Devender Rao908f7502017-07-10 01:49:54 -0500932 ipmi::fru::registerCallbackHandler();
Chris Austenb4f5b922015-10-13 12:44:43 -0500933 return;
934}