blob: 89274905e3b1cd246a85eeef64e8deb9340072cc [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 YUd9e57662021-09-14 18:06:28 +080081
82std::pair<uint16_t, SELEntry> parseLoggingEntry(const std::string& p)
83{
84 namespace fs = std::filesystem;
85 fs::path entryPath(p);
86 auto id = static_cast<uint16_t>(std::stoul(entryPath.filename().string()));
87 // TODO: parse the sel data
88 return {id, {}};
89}
90
Lei YUd9555252021-09-14 20:30:41 +080091static void selAddedCallback(sdbusplus::message::message& m)
92{
93 sdbusplus::message::object_path objPath;
94 try
95 {
96 m.read(objPath);
97 }
98 catch (const sdbusplus::exception::exception& e)
99 {
100 log<level::ERR>("Failed to read object path");
101 return;
102 }
103 std::string p = objPath;
104 selCacheMap.insert(parseLoggingEntry(p));
105}
106
107void registerSelCallbackHandler()
108{
109 using namespace sdbusplus::bus::match::rules;
110 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
111 if (!selAddedMatch)
112 {
113 selAddedMatch = std::make_unique<sdbusplus::bus::match::match>(
114 bus, interfacesAdded(logWatchPath),
115 std::bind(selAddedCallback, std::placeholders::_1));
116 }
117 // TODO: Add other callbacks
118}
119
Lei YUd9e57662021-09-14 18:06:28 +0800120void initSELCache()
121{
122 try
123 {
124 ipmi::sel::readLoggingObjectPaths(cache::paths);
125 }
126 catch (const sdbusplus::exception::exception& e)
127 {
128 log<level::ERR>("Failed to get logging object paths");
129 return;
130 }
131 for (const auto& p : cache::paths)
132 {
133 selCacheMap.insert(parseLoggingEntry(p));
134 }
Lei YUd9555252021-09-14 20:30:41 +0800135 registerSelCallbackHandler();
Lei YUd9e57662021-09-14 18:06:28 +0800136}
137
Marri Devender Raocac383b2017-07-03 13:24:27 -0500138/**
139 * @enum Device access mode
140 */
141enum class AccessMode
142{
143 bytes, ///< Device is accessed by bytes
144 words ///< Device is accessed by words
145};
146
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000147/** @brief implements the get SEL Info command
148 * @returns IPMI completion code plus response data
149 * - selVersion - SEL revision
150 * - entries - Number of log entries in SEL.
151 * - freeSpace - Free Space in bytes.
152 * - addTimeStamp - Most recent addition timestamp
153 * - eraseTimeStamp - Most recent erase timestamp
154 * - operationSupport - Reserve & Delete SEL operations supported
155 */
156
157ipmi::RspType<uint8_t, // SEL revision.
158 uint16_t, // number of log entries in SEL.
159 uint16_t, // free Space in bytes.
160 uint32_t, // most recent addition timestamp
161 uint32_t, // most recent erase timestamp.
162
163 bool, // SEL allocation info supported
164 bool, // reserve SEL supported
165 bool, // partial Add SEL Entry supported
166 bool, // delete SEL supported
167 uint3_t, // reserved
168 bool // overflow flag
169 >
170 ipmiStorageGetSelInfo()
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530171{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000172 uint16_t entries = 0;
173 // Most recent addition timestamp.
174 uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp;
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530175
Tom Josephe59abfb2018-08-06 18:46:27 +0530176 try
177 {
178 ipmi::sel::readLoggingObjectPaths(cache::paths);
179 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500180 catch (const sdbusplus::exception::exception& e)
Tom Josephe59abfb2018-08-06 18:46:27 +0530181 {
182 // No action if reading log objects have failed for this command.
183 // readLoggingObjectPaths will throw exception if there are no log
184 // entries. The command will be responded with number of SEL entries
185 // as 0.
186 }
187
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530188 if (!cache::paths.empty())
189 {
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000190 entries = static_cast<uint16_t>(cache::paths.size());
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530191
192 try
193 {
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000194 addTimeStamp = static_cast<uint32_t>(
Patrick Venture0b02be92018-08-31 11:55:55 -0700195 (ipmi::sel::getEntryTimeStamp(cache::paths.back()).count()));
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530196 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500197 catch (const InternalFailure& e)
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530198 {
199 }
200 catch (const std::runtime_error& e)
201 {
202 log<level::ERR>(e.what());
203 }
204 }
205
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000206 constexpr uint8_t selVersion = ipmi::sel::selVersion;
207 constexpr uint16_t freeSpace = 0xFFFF;
208 constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp;
209 constexpr uint3_t reserved{0};
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530210
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000211 return ipmi::responseSuccess(
212 selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp,
213 ipmi::sel::operationSupport::getSelAllocationInfo,
214 ipmi::sel::operationSupport::reserveSel,
215 ipmi::sel::operationSupport::partialAddSelEntry,
216 ipmi::sel::operationSupport::deleteSel, reserved,
217 ipmi::sel::operationSupport::overflow);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530218}
219
Tom Josepha4953392017-06-30 19:09:47 +0530220ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
221 ipmi_request_t request, ipmi_response_t response,
222 ipmi_data_len_t data_len, ipmi_context_t context)
223{
Jason M. Bills851acb12019-02-04 14:06:57 -0800224 if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest))
225 {
226 *data_len = 0;
227 return IPMI_CC_REQ_DATA_LEN_INVALID;
228 }
229
Patrick Venture0b02be92018-08-31 11:55:55 -0700230 auto requestData =
231 reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request);
Tom Josepha4953392017-06-30 19:09:47 +0530232
233 if (requestData->reservationID != 0)
234 {
Jason M. Bills13e67c82018-09-10 14:12:16 -0700235 if (!checkSELReservation(requestData->reservationID))
Tom Josepha4953392017-06-30 19:09:47 +0530236 {
237 *data_len = 0;
238 return IPMI_CC_INVALID_RESERVATION_ID;
239 }
240 }
241
242 if (cache::paths.empty())
243 {
244 *data_len = 0;
245 return IPMI_CC_SENSOR_INVALID;
246 }
247
248 ipmi::sel::ObjectPaths::const_iterator iter;
249
250 // Check for the requested SEL Entry.
251 if (requestData->selRecordID == ipmi::sel::firstEntry)
252 {
253 iter = cache::paths.begin();
254 }
255 else if (requestData->selRecordID == ipmi::sel::lastEntry)
256 {
257 iter = cache::paths.end();
258 }
259 else
260 {
261 std::string objPath = std::string(ipmi::sel::logBasePath) + "/" +
262 std::to_string(requestData->selRecordID);
263
264 iter = std::find(cache::paths.begin(), cache::paths.end(), objPath);
265 if (iter == cache::paths.end())
266 {
267 *data_len = 0;
268 return IPMI_CC_SENSOR_INVALID;
269 }
270 }
271
Patrick Venture0b02be92018-08-31 11:55:55 -0700272 ipmi::sel::GetSELEntryResponse record{};
Tom Josepha4953392017-06-30 19:09:47 +0530273
274 // Convert the log entry into SEL record.
275 try
276 {
277 record = ipmi::sel::convertLogEntrytoSEL(*iter);
278 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500279 catch (const InternalFailure& e)
Tom Josepha4953392017-06-30 19:09:47 +0530280 {
281 *data_len = 0;
282 return IPMI_CC_UNSPECIFIED_ERROR;
283 }
284 catch (const std::runtime_error& e)
285 {
286 log<level::ERR>(e.what());
287 *data_len = 0;
288 return IPMI_CC_UNSPECIFIED_ERROR;
289 }
290
Tom Josepha4953392017-06-30 19:09:47 +0530291 // Identify the next SEL record ID
Patrick Venture0b02be92018-08-31 11:55:55 -0700292 if (iter != cache::paths.end())
Tom Josepha4953392017-06-30 19:09:47 +0530293 {
294 ++iter;
295 if (iter == cache::paths.end())
296 {
297 record.nextRecordID = ipmi::sel::lastEntry;
298 }
299 else
300 {
Vernon Mauery185b9f82018-07-20 10:52:36 -0700301 namespace fs = std::filesystem;
Tom Josepha4953392017-06-30 19:09:47 +0530302 fs::path path(*iter);
Patrick Venture0b02be92018-08-31 11:55:55 -0700303 record.nextRecordID = static_cast<uint16_t>(
304 std::stoul(std::string(path.filename().c_str())));
Tom Josepha4953392017-06-30 19:09:47 +0530305 }
306 }
307 else
308 {
309 record.nextRecordID = ipmi::sel::lastEntry;
310 }
311
312 if (requestData->readLength == ipmi::sel::entireRecord)
313 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700314 std::memcpy(response, &record, sizeof(record));
Tom Josepha4953392017-06-30 19:09:47 +0530315 *data_len = sizeof(record);
316 }
317 else
318 {
319 if (requestData->offset >= ipmi::sel::selRecordSize ||
320 requestData->readLength > ipmi::sel::selRecordSize)
321 {
322 *data_len = 0;
323 return IPMI_CC_INVALID_FIELD_REQUEST;
324 }
325
326 auto diff = ipmi::sel::selRecordSize - requestData->offset;
Patrick Venture0b02be92018-08-31 11:55:55 -0700327 auto readLength =
328 std::min(diff, static_cast<int>(requestData->readLength));
Tom Josepha4953392017-06-30 19:09:47 +0530329
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700330 std::memcpy(response, &record.nextRecordID,
331 sizeof(record.nextRecordID));
332 std::memcpy(static_cast<uint8_t*>(response) +
333 sizeof(record.nextRecordID),
Lei YUaf378fa2020-12-02 16:28:57 +0800334 &record.event.eventRecord.recordID + requestData->offset,
335 readLength);
Tom Josepha4953392017-06-30 19:09:47 +0530336 *data_len = sizeof(record.nextRecordID) + readLength;
337 }
338
339 return IPMI_CC_OK;
340}
341
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000342/** @brief implements the delete SEL entry command
343 * @request
344 * - reservationID; // reservation ID.
345 * - selRecordID; // SEL record ID.
346 *
347 * @returns ipmi completion code plus response data
348 * - Record ID of the deleted record
349 */
350ipmi::RspType<uint16_t // deleted record ID
351 >
352 deleteSELEntry(uint16_t reservationID, uint16_t selRecordID)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530353{
Jason M. Bills851acb12019-02-04 14:06:57 -0800354
Brad Bishop1a4117b2018-11-21 15:48:18 -0500355 namespace fs = std::filesystem;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530356
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000357 if (!checkSELReservation(reservationID))
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530358 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000359 return ipmi::responseInvalidReservationId();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530360 }
361
Jason M. Bills13e67c82018-09-10 14:12:16 -0700362 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
363 // deleted
364 cancelSELReservation();
365
Tom Josephe59abfb2018-08-06 18:46:27 +0530366 try
367 {
368 ipmi::sel::readLoggingObjectPaths(cache::paths);
369 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500370 catch (const sdbusplus::exception::exception& e)
Tom Josephe59abfb2018-08-06 18:46:27 +0530371 {
372 // readLoggingObjectPaths will throw exception if there are no error
373 // log entries.
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000374 return ipmi::responseSensorInvalid();
Tom Josephe59abfb2018-08-06 18:46:27 +0530375 }
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530376
377 if (cache::paths.empty())
378 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000379 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530380 }
381
382 ipmi::sel::ObjectPaths::const_iterator iter;
383 uint16_t delRecordID = 0;
384
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000385 if (selRecordID == ipmi::sel::firstEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530386 {
387 iter = cache::paths.begin();
388 fs::path path(*iter);
Patrick Venture0b02be92018-08-31 11:55:55 -0700389 delRecordID = static_cast<uint16_t>(
390 std::stoul(std::string(path.filename().c_str())));
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530391 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000392 else if (selRecordID == ipmi::sel::lastEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530393 {
394 iter = cache::paths.end();
395 fs::path path(*iter);
Patrick Venture0b02be92018-08-31 11:55:55 -0700396 delRecordID = static_cast<uint16_t>(
397 std::stoul(std::string(path.filename().c_str())));
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530398 }
399 else
400 {
401 std::string objPath = std::string(ipmi::sel::logBasePath) + "/" +
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000402 std::to_string(selRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530403
404 iter = std::find(cache::paths.begin(), cache::paths.end(), objPath);
405 if (iter == cache::paths.end())
406 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000407 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530408 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000409 delRecordID = selRecordID;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530410 }
411
412 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
413 std::string service;
414
415 try
416 {
417 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, *iter);
418 }
419 catch (const std::runtime_error& e)
420 {
421 log<level::ERR>(e.what());
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000422 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530423 }
424
Patrick Venture0b02be92018-08-31 11:55:55 -0700425 auto methodCall = bus.new_method_call(service.c_str(), (*iter).c_str(),
426 ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530427 auto reply = bus.call(methodCall);
428 if (reply.is_method_error())
429 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000430 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530431 }
432
433 // Invalidate the cache of dbus entry objects.
434 cache::paths.clear();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530435
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000436 return ipmi::responseSuccess(delRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530437}
438
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000439/** @brief implements the Clear SEL command
440 * @request
441 * - reservationID // Reservation ID.
442 * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) }
443 * - eraseOperation; // requested operation.
444 *
445 * @returns ipmi completion code plus response data
446 * - erase status
447 */
448
449ipmi::RspType<uint8_t // erase status
450 >
451 clearSEL(uint16_t reservationID, const std::array<char, 3>& clr,
452 uint8_t eraseOperation)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530453{
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000454 static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'};
455 if (clr != clrOk)
Jason M. Bills851acb12019-02-04 14:06:57 -0800456 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000457 return ipmi::responseInvalidFieldRequest();
Jason M. Bills851acb12019-02-04 14:06:57 -0800458 }
459
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000460 if (!checkSELReservation(reservationID))
Tom Joseph2f05bb52017-06-30 19:14:49 +0530461 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000462 return ipmi::responseInvalidReservationId();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530463 }
464
Tom Joseph2f05bb52017-06-30 19:14:49 +0530465 /*
466 * Erasure status cannot be fetched from DBUS, so always return erasure
467 * status as `erase completed`.
468 */
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000469 if (eraseOperation == ipmi::sel::getEraseStatus)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530470 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000471 return ipmi::responseSuccess(
472 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530473 }
474
Jason M. Bills13e67c82018-09-10 14:12:16 -0700475 // Per the IPMI spec, need to cancel any reservation when the SEL is cleared
476 cancelSELReservation();
477
Tom Joseph2f05bb52017-06-30 19:14:49 +0530478 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Tom Josephe59abfb2018-08-06 18:46:27 +0530479 ipmi::sel::ObjectPaths objectPaths;
Tom Joseph2f05bb52017-06-30 19:14:49 +0530480 auto depth = 0;
481
Patrick Venture0b02be92018-08-31 11:55:55 -0700482 auto mapperCall =
483 bus.new_method_call(ipmi::sel::mapperBusName, ipmi::sel::mapperObjPath,
484 ipmi::sel::mapperIntf, "GetSubTreePaths");
Tom Joseph2f05bb52017-06-30 19:14:49 +0530485 mapperCall.append(ipmi::sel::logBasePath);
486 mapperCall.append(depth);
487 mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf}));
488
Tom Josephe59abfb2018-08-06 18:46:27 +0530489 try
Tom Joseph2f05bb52017-06-30 19:14:49 +0530490 {
Tom Josephe59abfb2018-08-06 18:46:27 +0530491 auto reply = bus.call(mapperCall);
492 if (reply.is_method_error())
493 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000494 return ipmi::responseSuccess(
495 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Josephe59abfb2018-08-06 18:46:27 +0530496 }
Tom Joseph2f05bb52017-06-30 19:14:49 +0530497
Tom Josephe59abfb2018-08-06 18:46:27 +0530498 reply.read(objectPaths);
499 if (objectPaths.empty())
500 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000501 return ipmi::responseSuccess(
502 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Josephe59abfb2018-08-06 18:46:27 +0530503 }
504 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500505 catch (const sdbusplus::exception::exception& e)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530506 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000507 return ipmi::responseSuccess(
508 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530509 }
510
511 std::string service;
512
513 try
514 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700515 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf,
Tom Joseph2f05bb52017-06-30 19:14:49 +0530516 objectPaths.front());
517 }
518 catch (const std::runtime_error& e)
519 {
520 log<level::ERR>(e.what());
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000521 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530522 }
523
524 for (const auto& iter : objectPaths)
525 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700526 auto methodCall = bus.new_method_call(
527 service.c_str(), iter.c_str(), ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph2f05bb52017-06-30 19:14:49 +0530528
529 auto reply = bus.call(methodCall);
530 if (reply.is_method_error())
531 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000532 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530533 }
534 }
535
536 // Invalidate the cache of dbus entry objects.
537 cache::paths.clear();
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000538 return ipmi::responseSuccess(
539 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530540}
541
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000542/** @brief implements the get SEL time command
543 * @returns IPMI completion code plus response data
544 * -current time
545 */
546ipmi::RspType<uint32_t> // current time
547 ipmiStorageGetSelTime()
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500548{
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530549 using namespace std::chrono;
George Liu4d623e92020-05-25 16:51:57 +0800550 uint64_t bmc_time_usec = 0;
551 std::stringstream bmcTime;
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500552
Lei YUe8939392017-06-15 10:45:05 +0800553 try
554 {
555 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800556 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Vernon Mauery16b86932019-05-01 08:36:11 -0700557 std::variant<uint64_t> value;
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530558
George Liu4d623e92020-05-25 16:51:57 +0800559 // Get bmc time
560 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700561 DBUS_PROPERTIES, "Get");
Lei YUe8939392017-06-15 10:45:05 +0800562
563 method.append(TIME_INTERFACE, PROPERTY_ELAPSED);
564 auto reply = bus.call(method);
565 if (reply.is_method_error())
566 {
567 log<level::ERR>("Error getting time",
568 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800569 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000570 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800571 }
572 reply.read(value);
George Liu4d623e92020-05-25 16:51:57 +0800573 bmc_time_usec = std::get<uint64_t>(value);
Lei YUe8939392017-06-15 10:45:05 +0800574 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500575 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800576 {
577 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000578 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800579 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530580 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800581 {
582 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000583 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530584 }
585
George Liu4d623e92020-05-25 16:51:57 +0800586 bmcTime << "BMC time:"
587 << duration_cast<seconds>(microseconds(bmc_time_usec)).count();
588 log<level::DEBUG>(bmcTime.str().c_str());
Nagaraju Goruganti8960b7c2018-04-29 22:38:40 -0500589
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530590 // Time is really long int but IPMI wants just uint32. This works okay until
591 // the number of seconds since 1970 overflows uint32 size.. Still a whole
592 // lot of time here to even think about that.
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000593 return ipmi::responseSuccess(
George Liu4d623e92020-05-25 16:51:57 +0800594 duration_cast<seconds>(microseconds(bmc_time_usec)).count());
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500595}
596
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000597/** @brief implements the set SEL time command
598 * @param selDeviceTime - epoch time
599 * -local time as the number of seconds from 00:00:00, January 1, 1970
600 * @returns IPMI completion code
601 */
602ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime)
Chris Austenb4f5b922015-10-13 12:44:43 -0500603{
Lei YUe8939392017-06-15 10:45:05 +0800604 using namespace std::chrono;
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000605 microseconds usec{seconds(selDeviceTime)};
Norman James82330442015-11-19 16:53:26 -0600606
Lei YUe8939392017-06-15 10:45:05 +0800607 try
608 {
609 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800610 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Andrew Geissler6467ed22020-05-16 16:03:53 -0500611 std::variant<uint64_t> value{(uint64_t)usec.count()};
Lei YUe8939392017-06-15 10:45:05 +0800612
George Liu4d623e92020-05-25 16:51:57 +0800613 // Set bmc time
614 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700615 DBUS_PROPERTIES, "Set");
Lei YUe8939392017-06-15 10:45:05 +0800616
617 method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value);
618 auto reply = bus.call(method);
619 if (reply.is_method_error())
620 {
621 log<level::ERR>("Error setting time",
622 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800623 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000624 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800625 }
Norman James82330442015-11-19 16:53:26 -0600626 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500627 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800628 {
629 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000630 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530631 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530632 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800633 {
634 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000635 return ipmi::responseUnspecifiedError();
Norman James82330442015-11-19 16:53:26 -0600636 }
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530637
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000638 return ipmi::responseSuccess();
Chris Austenb4f5b922015-10-13 12:44:43 -0500639}
640
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000641/** @brief implements the reserve SEL command
642 * @returns IPMI completion code plus response data
643 * - SEL reservation ID.
644 */
645ipmi::RspType<uint16_t> ipmiStorageReserveSel()
Chris Austenb4f5b922015-10-13 12:44:43 -0500646{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000647 return ipmi::responseSuccess(reserveSel());
Chris Austenb4f5b922015-10-13 12:44:43 -0500648}
649
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000650/** @brief implements the Add SEL entry command
651 * @request
652 *
653 * - recordID ID used for SEL Record access
654 * - recordType Record Type
655 * - timeStamp Time when event was logged. LS byte first
656 * - generatorID software ID if event was generated from
657 * system software
658 * - evmRev event message format version
659 * - sensorType sensor type code for service that generated
660 * the event
661 * - sensorNumber number of sensors that generated the event
662 * - eventDir event dir
663 * - eventData event data field contents
664 *
665 * @returns ipmi completion code plus response data
666 * - RecordID of the Added SEL entry
667 */
668ipmi::RspType<uint16_t // recordID of the Added SEL entry
669 >
670 ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, uint32_t timeStamp,
671 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType,
672 uint8_t sensorNumber, uint8_t eventDir,
673 std::array<uint8_t, eventDataSize> eventData)
Chris Austenb4f5b922015-10-13 12:44:43 -0500674{
Jason M. Bills13e67c82018-09-10 14:12:16 -0700675 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
676 // added
677 cancelSELReservation();
Tom Josephb647d5b2017-10-31 17:25:33 +0530678 // Hostboot sends SEL with OEM record type 0xDE to indicate that there is
679 // a maintenance procedure associated with eSEL record.
680 static constexpr auto procedureType = 0xDE;
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000681 if (recordType == procedureType)
Tom Josephb647d5b2017-10-31 17:25:33 +0530682 {
683 // In the OEM record type 0xDE, byte 11 in the SEL record indicate the
684 // procedure number.
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000685 createProcedureLogEntry(sensorType);
Tom Josephb647d5b2017-10-31 17:25:33 +0530686 }
Chris Austenb4f5b922015-10-13 12:44:43 -0500687
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000688 return ipmi::responseSuccess(recordID);
Chris Austenb4f5b922015-10-13 12:44:43 -0500689}
690
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300691bool isFruPresent(const std::string& fruPath)
692{
693 using namespace ipmi::fru;
694
695 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
696
697 auto propValue =
698 ipmi::getDbusProperty(bus, invMgrInterface, invObjPath + fruPath,
699 invItemInterface, itemPresentProp);
700
701 return std::get<bool>(propValue);
702}
703
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000704/** @brief implements the get FRU Inventory Area Info command
705 *
706 * @returns IPMI completion code plus response data
707 * - FRU Inventory area size in bytes,
708 * - access bit
709 **/
710ipmi::RspType<uint16_t, // FRU Inventory area size in bytes,
711 uint8_t // access size (bytes / words)
712 >
713 ipmiStorageGetFruInvAreaInfo(uint8_t fruID)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500714{
Tom Joseph187f5642018-03-29 13:49:06 +0530715
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000716 auto iter = frus.find(fruID);
Tom Joseph187f5642018-03-29 13:49:06 +0530717 if (iter == frus.end())
718 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000719 return ipmi::responseSensorInvalid();
Tom Joseph187f5642018-03-29 13:49:06 +0530720 }
721
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300722 auto path = iter->second[0].path;
723 if (!isFruPresent(path))
724 {
725 return ipmi::responseSensorInvalid();
726 }
727
Marri Devender Raocac383b2017-07-03 13:24:27 -0500728 try
729 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000730 return ipmi::responseSuccess(
731 static_cast<uint16_t>(getFruAreaData(fruID).size()),
732 static_cast<uint8_t>(AccessMode::bytes));
Marri Devender Raocac383b2017-07-03 13:24:27 -0500733 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700734 catch (const InternalFailure& e)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500735 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500736 log<level::ERR>(e.what());
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000737 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500738 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500739}
740
anil kumar appana5b7c3262019-05-27 18:10:23 +0000741/**@brief implements the Read FRU Data command
742 * @param fruDeviceId - FRU device ID. FFh = reserved
743 * @param offset - FRU inventory offset to read
744 * @param readCount - count to read
745 *
746 * @return IPMI completion code plus response data
747 * - returnCount - response data count.
748 * - data - response data
749 */
750ipmi::RspType<uint8_t, // count returned
751 std::vector<uint8_t>> // FRU data
752 ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset,
753 uint8_t readCount)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500754{
anil kumar appana5b7c3262019-05-27 18:10:23 +0000755 if (fruDeviceId == 0xFF)
Tom Joseph187f5642018-03-29 13:49:06 +0530756 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000757 return ipmi::responseInvalidFieldRequest();
Tom Joseph187f5642018-03-29 13:49:06 +0530758 }
759
anil kumar appana5b7c3262019-05-27 18:10:23 +0000760 auto iter = frus.find(fruDeviceId);
761 if (iter == frus.end())
762 {
763 return ipmi::responseSensorInvalid();
764 }
765
Marri Devender Raocac383b2017-07-03 13:24:27 -0500766 try
767 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000768 const auto& fruArea = getFruAreaData(fruDeviceId);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500769 auto size = fruArea.size();
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500770
Tom Josephefcd68b2018-04-26 18:46:27 +0530771 if (offset >= size)
772 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000773 return ipmi::responseParmOutOfRange();
Tom Josephefcd68b2018-04-26 18:46:27 +0530774 }
775
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500776 // Write the count of response data.
anil kumar appana5b7c3262019-05-27 18:10:23 +0000777 uint8_t returnCount;
778 if ((offset + readCount) <= size)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500779 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000780 returnCount = readCount;
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500781 }
782 else
783 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000784 returnCount = size - offset;
Marri Devender Raocac383b2017-07-03 13:24:27 -0500785 }
Ratan Gupta2848d602018-01-31 20:39:20 +0530786
anil kumar appana5b7c3262019-05-27 18:10:23 +0000787 std::vector<uint8_t> fruData((fruArea.begin() + offset),
788 (fruArea.begin() + offset + returnCount));
Ratan Gupta2848d602018-01-31 20:39:20 +0530789
anil kumar appana5b7c3262019-05-27 18:10:23 +0000790 return ipmi::responseSuccess(returnCount, fruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500791 }
792 catch (const InternalFailure& e)
793 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500794 log<level::ERR>(e.what());
anil kumar appana5b7c3262019-05-27 18:10:23 +0000795 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500796 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500797}
798
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000799ipmi::RspType<uint8_t, // SDR version
800 uint16_t, // record count LS first
801 uint16_t, // free space in bytes, LS first
802 uint32_t, // addition timestamp LS first
803 uint32_t, // deletion timestamp LS first
804 uint8_t> // operation Support
805 ipmiGetRepositoryInfo()
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600806{
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600807
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000808 constexpr uint8_t sdrVersion = 0x51;
809 constexpr uint16_t freeSpace = 0xFFFF;
810 constexpr uint32_t additionTimestamp = 0x0;
811 constexpr uint32_t deletionTimestamp = 0x0;
812 constexpr uint8_t operationSupport = 0;
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600813
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700814 uint16_t records = frus.size() + ipmi::sensor::sensors.size();
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600815
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000816 return ipmi::responseSuccess(sdrVersion, records, freeSpace,
817 additionTimestamp, deletionTimestamp,
818 operationSupport);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600819}
Chris Austenb4f5b922015-10-13 12:44:43 -0500820
Chris Austenb4f5b922015-10-13 12:44:43 -0500821void register_netfn_storage_functions()
822{
Lei YUd9e57662021-09-14 18:06:28 +0800823 initSELCache();
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530824 // <Get SEL Info>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000825 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
826 ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
827 ipmiStorageGetSelInfo);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530828
Tom05732372016-09-06 17:21:23 +0530829 // <Get SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000830 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
831 ipmi::storage::cmdGetSelTime, ipmi::Privilege::User,
832 ipmiStorageGetSelTime);
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500833
Tom05732372016-09-06 17:21:23 +0530834 // <Set SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000835 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
836 ipmi::storage::cmdSetSelTime,
837 ipmi::Privilege::Operator, ipmiStorageSetSelTime);
Chris Austenb4f5b922015-10-13 12:44:43 -0500838
Tom05732372016-09-06 17:21:23 +0530839 // <Reserve SEL>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000840 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
841 ipmi::storage::cmdReserveSel, ipmi::Privilege::User,
842 ipmiStorageReserveSel);
Tom Josepha4953392017-06-30 19:09:47 +0530843 // <Get SEL Entry>
Patrick Venture0b02be92018-08-31 11:55:55 -0700844 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL,
845 getSELEntry, PRIVILEGE_USER);
Tom Josepha4953392017-06-30 19:09:47 +0530846
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530847 // <Delete SEL Entry>
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000848 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
849 ipmi::storage::cmdDeleteSelEntry,
850 ipmi::Privilege::Operator, deleteSELEntry);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530851
Tom05732372016-09-06 17:21:23 +0530852 // <Add SEL Entry>
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000853 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
854 ipmi::storage::cmdAddSelEntry,
855 ipmi::Privilege::Operator, ipmiStorageAddSEL);
856
Tom Joseph2f05bb52017-06-30 19:14:49 +0530857 // <Clear SEL>
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000858 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
859 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
860 clearSEL);
861
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500862 // <Get FRU Inventory Area Info>
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000863 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
864 ipmi::storage::cmdGetFruInventoryAreaInfo,
865 ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500866
Jason M. Billsb5248c92019-06-24 15:53:08 -0700867 // <READ FRU Data>
anil kumar appana5b7c3262019-05-27 18:10:23 +0000868 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
869 ipmi::storage::cmdReadFruData,
870 ipmi::Privilege::Operator, ipmiStorageReadFruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500871
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600872 // <Get Repository Info>
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000873 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
874 ipmi::storage::cmdGetSdrRepositoryInfo,
875 ipmi::Privilege::User, ipmiGetRepositoryInfo);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600876
Tom Joseph5ca50952018-02-22 00:33:38 +0530877 // <Reserve SDR Repository>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000878 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
879 ipmi::storage::cmdReserveSdrRepository,
880 ipmi::Privilege::User, ipmiSensorReserveSdr);
Tom Joseph5ca50952018-02-22 00:33:38 +0530881
882 // <Get SDR>
Patrick Venture0b02be92018-08-31 11:55:55 -0700883 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr,
884 ipmi_sen_get_sdr, PRIVILEGE_USER);
Tom Joseph5ca50952018-02-22 00:33:38 +0530885
Marri Devender Rao908f7502017-07-10 01:49:54 -0500886 ipmi::fru::registerCallbackHandler();
Chris Austenb4f5b922015-10-13 12:44:43 -0500887 return;
888}