blob: 2b9013aee12fb7100504e2d1df247898633f673c [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>
Lei YUa0bb2a32021-09-24 11:03:56 +080020#include <optional>
Patrick Venture3a5071a2018-09-12 13:27:42 -070021#include <phosphor-logging/elog-errors.hpp>
Lotus Xu57d35572021-01-24 11:13:13 +080022#include <phosphor-logging/elog.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070023#include <phosphor-logging/log.hpp>
24#include <sdbusplus/server.hpp>
25#include <string>
Vernon Mauery16b86932019-05-01 08:36:11 -070026#include <variant>
Patrick Venture3a5071a2018-09-12 13:27:42 -070027#include <xyz/openbmc_project/Common/error.hpp>
Lotus Xu57d35572021-01-24 11:13:13 +080028#include <xyz/openbmc_project/Logging/SEL/error.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070029
Chris Austenb4f5b922015-10-13 12:44:43 -050030void register_netfn_storage_functions() __attribute__((constructor));
31
Patrick Venture0b02be92018-08-31 11:55:55 -070032unsigned int g_sel_time = 0xFFFFFFFF;
Patrick Venturedb0cbe62019-09-09 14:47:22 -070033namespace ipmi
34{
35namespace sensor
36{
37extern const IdInfoMap sensors;
38} // namespace sensor
39} // namespace ipmi
Lotus Xu57d35572021-01-24 11:13:13 +080040extern const ipmi::sensor::InvObjectIDMap invSensors;
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -060041extern const FruMap frus;
anil kumar appana2c7db1d2019-05-28 11:20:19 +000042constexpr uint8_t eventDataSize = 3;
Patrick Venture0b02be92018-08-31 11:55:55 -070043namespace
44{
Lei YUe8939392017-06-15 10:45:05 +080045constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime";
George Liu4d623e92020-05-25 16:51:57 +080046constexpr auto BMC_TIME_PATH = "/xyz/openbmc_project/time/bmc";
Lei YUe8939392017-06-15 10:45:05 +080047constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties";
Patrick Venture0b02be92018-08-31 11:55:55 -070048constexpr auto PROPERTY_ELAPSED = "Elapsed";
Lei YUe8939392017-06-15 10:45:05 +080049
Lei YUd9555252021-09-14 20:30:41 +080050constexpr auto logWatchPath = "/xyz/openbmc_project/logging";
Lei YUd9e57662021-09-14 18:06:28 +080051constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
52constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
53constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
Patrick Venture0b02be92018-08-31 11:55:55 -070054} // namespace
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +053055
Tom Joseph6f7deaa2017-06-30 19:03:54 +053056using InternalFailure =
Patrick Venture0b02be92018-08-31 11:55:55 -070057 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053058using namespace phosphor::logging;
Marri Devender Raocac383b2017-07-03 13:24:27 -050059using namespace ipmi::fru;
Lotus Xu57d35572021-01-24 11:13:13 +080060using namespace xyz::openbmc_project::Logging::SEL;
61using SELCreated =
62 sdbusplus::xyz::openbmc_project::Logging::SEL::Error::Created;
Marri Devender Raocac383b2017-07-03 13:24:27 -050063
Lei YUd9e57662021-09-14 18:06:28 +080064using SELRecordID = uint16_t;
65using SELEntry = ipmi::sel::SELEventRecordFormat;
66using SELCacheMap = std::map<SELRecordID, SELEntry>;
67
68SELCacheMap selCacheMap __attribute__((init_priority(101)));
Lei YU3df36612021-09-15 11:41:11 +080069bool selCacheMapInitialized;
Lei YUd9555252021-09-14 20:30:41 +080070std::unique_ptr<sdbusplus::bus::match::match> selAddedMatch
71 __attribute__((init_priority(101)));
Lei YUb6b72b02021-09-14 21:06:05 +080072std::unique_ptr<sdbusplus::bus::match::match> selRemovedMatch
73 __attribute__((init_priority(101)));
Lei YU4106e422021-09-15 10:55:51 +080074std::unique_ptr<sdbusplus::bus::match::match> selUpdatedMatch
75 __attribute__((init_priority(101)));
Lei YUd9e57662021-09-14 18:06:28 +080076
Lei YUb6b72b02021-09-14 21:06:05 +080077static inline uint16_t getLoggingId(const std::string& p)
Lei YUd9e57662021-09-14 18:06:28 +080078{
79 namespace fs = std::filesystem;
80 fs::path entryPath(p);
Lei YUb6b72b02021-09-14 21:06:05 +080081 return std::stoul(entryPath.filename().string());
82}
83
Lei YUeba8e9a2021-09-15 13:16:17 +080084static inline std::string getLoggingObjPath(uint16_t id)
85{
86 return std::string(ipmi::sel::logBasePath) + "/" + std::to_string(id);
87}
88
Lei YUa0bb2a32021-09-24 11:03:56 +080089std::optional<std::pair<uint16_t, SELEntry>>
90 parseLoggingEntry(const std::string& p)
Lei YUb6b72b02021-09-14 21:06:05 +080091{
Lei YU3df36612021-09-15 11:41:11 +080092 try
93 {
Lei YUa0bb2a32021-09-24 11:03:56 +080094 auto id = getLoggingId(p);
95 ipmi::sel::GetSELEntryResponse record{};
Lei YU3df36612021-09-15 11:41:11 +080096 record = ipmi::sel::convertLogEntrytoSEL(p);
Lei YUa0bb2a32021-09-24 11:03:56 +080097 return std::pair<uint16_t, SELEntry>({id, std::move(record.event)});
Lei YU3df36612021-09-15 11:41:11 +080098 }
99 catch (const std::exception& e)
100 {
101 fprintf(stderr, "Failed to convert %s to SEL: %s\n", p.c_str(),
102 e.what());
103 }
Lei YUa0bb2a32021-09-24 11:03:56 +0800104 return std::nullopt;
Lei YUd9e57662021-09-14 18:06:28 +0800105}
106
Lei YUd9555252021-09-14 20:30:41 +0800107static void selAddedCallback(sdbusplus::message::message& m)
108{
109 sdbusplus::message::object_path objPath;
110 try
111 {
112 m.read(objPath);
113 }
114 catch (const sdbusplus::exception::exception& e)
115 {
116 log<level::ERR>("Failed to read object path");
117 return;
118 }
119 std::string p = objPath;
Lei YUa0bb2a32021-09-24 11:03:56 +0800120 auto entry = parseLoggingEntry(p);
121 if (entry)
122 {
123 selCacheMap.insert(std::move(*entry));
124 }
Lei YUd9555252021-09-14 20:30:41 +0800125}
126
Lei YUb6b72b02021-09-14 21:06:05 +0800127static void selRemovedCallback(sdbusplus::message::message& m)
128{
129 sdbusplus::message::object_path objPath;
130 try
131 {
132 m.read(objPath);
133 }
134 catch (const sdbusplus::exception::exception& e)
135 {
136 log<level::ERR>("Failed to read object path");
Lei YUb6b72b02021-09-14 21:06:05 +0800137 }
Lei YUa0bb2a32021-09-24 11:03:56 +0800138 try
139 {
140 std::string p = objPath;
141 selCacheMap.erase(getLoggingId(p));
142 }
143 catch (const std::invalid_argument& e)
144 {
145 log<level::ERR>("Invalid logging entry ID");
146 }
Lei YUb6b72b02021-09-14 21:06:05 +0800147}
148
Lei YU4106e422021-09-15 10:55:51 +0800149static void selUpdatedCallback(sdbusplus::message::message& m)
150{
151 std::string p = m.get_path();
152 auto entry = parseLoggingEntry(p);
Lei YUa0bb2a32021-09-24 11:03:56 +0800153 if (entry)
154 {
155 selCacheMap.insert_or_assign(entry->first, std::move(entry->second));
156 }
Lei YU4106e422021-09-15 10:55:51 +0800157}
158
Lei YUd9555252021-09-14 20:30:41 +0800159void registerSelCallbackHandler()
160{
161 using namespace sdbusplus::bus::match::rules;
162 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
163 if (!selAddedMatch)
164 {
165 selAddedMatch = std::make_unique<sdbusplus::bus::match::match>(
166 bus, interfacesAdded(logWatchPath),
167 std::bind(selAddedCallback, std::placeholders::_1));
168 }
Lei YUb6b72b02021-09-14 21:06:05 +0800169 if (!selRemovedMatch)
170 {
171 selRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
172 bus, interfacesRemoved(logWatchPath),
173 std::bind(selRemovedCallback, std::placeholders::_1));
174 }
Lei YU4106e422021-09-15 10:55:51 +0800175 if (!selUpdatedMatch)
176 {
177 selUpdatedMatch = std::make_unique<sdbusplus::bus::match::match>(
178 bus,
179 type::signal() + member("PropertiesChanged"s) +
180 interface("org.freedesktop.DBus.Properties"s) +
181 argN(0, logEntryIntf),
182 std::bind(selUpdatedCallback, std::placeholders::_1));
183 }
Lei YUd9555252021-09-14 20:30:41 +0800184}
185
Lei YUd9e57662021-09-14 18:06:28 +0800186void initSELCache()
187{
Lei YUc10cda12022-01-06 16:01:57 +0800188 registerSelCallbackHandler();
Lei YUeba8e9a2021-09-15 13:16:17 +0800189 ipmi::sel::ObjectPaths paths;
Lei YUd9e57662021-09-14 18:06:28 +0800190 try
191 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800192 ipmi::sel::readLoggingObjectPaths(paths);
Lei YUd9e57662021-09-14 18:06:28 +0800193 }
194 catch (const sdbusplus::exception::exception& e)
195 {
196 log<level::ERR>("Failed to get logging object paths");
197 return;
198 }
Lei YUeba8e9a2021-09-15 13:16:17 +0800199 for (const auto& p : paths)
Lei YUd9e57662021-09-14 18:06:28 +0800200 {
Lei YUa0bb2a32021-09-24 11:03:56 +0800201 auto entry = parseLoggingEntry(p);
202 if (entry)
203 {
204 selCacheMap.insert(std::move(*entry));
205 }
Lei YUd9e57662021-09-14 18:06:28 +0800206 }
Lei YU3df36612021-09-15 11:41:11 +0800207 selCacheMapInitialized = true;
Lei YUd9e57662021-09-14 18:06:28 +0800208}
209
Marri Devender Raocac383b2017-07-03 13:24:27 -0500210/**
211 * @enum Device access mode
212 */
213enum class AccessMode
214{
215 bytes, ///< Device is accessed by bytes
216 words ///< Device is accessed by words
217};
218
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000219/** @brief implements the get SEL Info command
220 * @returns IPMI completion code plus response data
221 * - selVersion - SEL revision
222 * - entries - Number of log entries in SEL.
223 * - freeSpace - Free Space in bytes.
224 * - addTimeStamp - Most recent addition timestamp
225 * - eraseTimeStamp - Most recent erase timestamp
226 * - operationSupport - Reserve & Delete SEL operations supported
227 */
228
229ipmi::RspType<uint8_t, // SEL revision.
230 uint16_t, // number of log entries in SEL.
231 uint16_t, // free Space in bytes.
232 uint32_t, // most recent addition timestamp
233 uint32_t, // most recent erase timestamp.
234
235 bool, // SEL allocation info supported
236 bool, // reserve SEL supported
237 bool, // partial Add SEL Entry supported
238 bool, // delete SEL supported
239 uint3_t, // reserved
240 bool // overflow flag
241 >
242 ipmiStorageGetSelInfo()
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530243{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000244 uint16_t entries = 0;
245 // Most recent addition timestamp.
246 uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp;
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530247
Lei YUeba8e9a2021-09-15 13:16:17 +0800248 if (!selCacheMapInitialized)
Tom Josephe59abfb2018-08-06 18:46:27 +0530249 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800250 // In case the initSELCache() fails, try it again
251 initSELCache();
Tom Josephe59abfb2018-08-06 18:46:27 +0530252 }
Lei YUeba8e9a2021-09-15 13:16:17 +0800253 if (!selCacheMap.empty())
Tom Josephe59abfb2018-08-06 18:46:27 +0530254 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800255 entries = static_cast<uint16_t>(selCacheMap.size());
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530256
257 try
258 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800259 auto objPath = getLoggingObjPath(selCacheMap.rbegin()->first);
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000260 addTimeStamp = static_cast<uint32_t>(
Lei YUeba8e9a2021-09-15 13:16:17 +0800261 (ipmi::sel::getEntryTimeStamp(objPath).count()));
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530262 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500263 catch (const InternalFailure& e)
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530264 {
265 }
266 catch (const std::runtime_error& e)
267 {
268 log<level::ERR>(e.what());
269 }
270 }
271
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000272 constexpr uint8_t selVersion = ipmi::sel::selVersion;
273 constexpr uint16_t freeSpace = 0xFFFF;
274 constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp;
275 constexpr uint3_t reserved{0};
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530276
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000277 return ipmi::responseSuccess(
278 selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp,
279 ipmi::sel::operationSupport::getSelAllocationInfo,
280 ipmi::sel::operationSupport::reserveSel,
281 ipmi::sel::operationSupport::partialAddSelEntry,
282 ipmi::sel::operationSupport::deleteSel, reserved,
283 ipmi::sel::operationSupport::overflow);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530284}
285
Tom Josepha4953392017-06-30 19:09:47 +0530286ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
287 ipmi_request_t request, ipmi_response_t response,
288 ipmi_data_len_t data_len, ipmi_context_t context)
289{
Jason M. Bills851acb12019-02-04 14:06:57 -0800290 if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest))
291 {
292 *data_len = 0;
293 return IPMI_CC_REQ_DATA_LEN_INVALID;
294 }
295
Patrick Venture0b02be92018-08-31 11:55:55 -0700296 auto requestData =
297 reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request);
Tom Josepha4953392017-06-30 19:09:47 +0530298
299 if (requestData->reservationID != 0)
300 {
Jason M. Bills13e67c82018-09-10 14:12:16 -0700301 if (!checkSELReservation(requestData->reservationID))
Tom Josepha4953392017-06-30 19:09:47 +0530302 {
303 *data_len = 0;
304 return IPMI_CC_INVALID_RESERVATION_ID;
305 }
306 }
307
Lei YU3df36612021-09-15 11:41:11 +0800308 if (!selCacheMapInitialized)
309 {
310 // In case the initSELCache() fails, try it again
311 initSELCache();
312 }
313
314 if (selCacheMap.empty())
Tom Josepha4953392017-06-30 19:09:47 +0530315 {
316 *data_len = 0;
317 return IPMI_CC_SENSOR_INVALID;
318 }
319
Lei YU3df36612021-09-15 11:41:11 +0800320 SELCacheMap::const_iterator iter;
Tom Josepha4953392017-06-30 19:09:47 +0530321
322 // Check for the requested SEL Entry.
323 if (requestData->selRecordID == ipmi::sel::firstEntry)
324 {
Lei YU3df36612021-09-15 11:41:11 +0800325 iter = selCacheMap.begin();
Tom Josepha4953392017-06-30 19:09:47 +0530326 }
327 else if (requestData->selRecordID == ipmi::sel::lastEntry)
328 {
Lei YU3df36612021-09-15 11:41:11 +0800329 if (selCacheMap.size() > 1)
330 {
331 iter = selCacheMap.end();
332 --iter;
333 }
334 else
335 {
336 // Only one entry exists, return the first
337 iter = selCacheMap.begin();
338 }
Tom Josepha4953392017-06-30 19:09:47 +0530339 }
340 else
341 {
Lei YU3df36612021-09-15 11:41:11 +0800342 iter = selCacheMap.find(requestData->selRecordID);
343 if (iter == selCacheMap.end())
Tom Josepha4953392017-06-30 19:09:47 +0530344 {
345 *data_len = 0;
346 return IPMI_CC_SENSOR_INVALID;
347 }
348 }
349
Lei YU3df36612021-09-15 11:41:11 +0800350 ipmi::sel::GetSELEntryResponse record{0, iter->second};
Tom Josepha4953392017-06-30 19:09:47 +0530351 // Identify the next SEL record ID
Lei YU3df36612021-09-15 11:41:11 +0800352 ++iter;
353 if (iter == selCacheMap.end())
Tom Josepha4953392017-06-30 19:09:47 +0530354 {
Lei YU3df36612021-09-15 11:41:11 +0800355 record.nextRecordID = ipmi::sel::lastEntry;
Tom Josepha4953392017-06-30 19:09:47 +0530356 }
357 else
358 {
Lei YU3df36612021-09-15 11:41:11 +0800359 record.nextRecordID = iter->first;
Tom Josepha4953392017-06-30 19:09:47 +0530360 }
361
362 if (requestData->readLength == ipmi::sel::entireRecord)
363 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700364 std::memcpy(response, &record, sizeof(record));
Tom Josepha4953392017-06-30 19:09:47 +0530365 *data_len = sizeof(record);
366 }
367 else
368 {
369 if (requestData->offset >= ipmi::sel::selRecordSize ||
370 requestData->readLength > ipmi::sel::selRecordSize)
371 {
372 *data_len = 0;
373 return IPMI_CC_INVALID_FIELD_REQUEST;
374 }
375
376 auto diff = ipmi::sel::selRecordSize - requestData->offset;
Patrick Venture0b02be92018-08-31 11:55:55 -0700377 auto readLength =
378 std::min(diff, static_cast<int>(requestData->readLength));
Tom Josepha4953392017-06-30 19:09:47 +0530379
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700380 std::memcpy(response, &record.nextRecordID,
381 sizeof(record.nextRecordID));
382 std::memcpy(static_cast<uint8_t*>(response) +
383 sizeof(record.nextRecordID),
Lei YUaf378fa2020-12-02 16:28:57 +0800384 &record.event.eventRecord.recordID + requestData->offset,
385 readLength);
Tom Josepha4953392017-06-30 19:09:47 +0530386 *data_len = sizeof(record.nextRecordID) + readLength;
387 }
388
389 return IPMI_CC_OK;
390}
391
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000392/** @brief implements the delete SEL entry command
393 * @request
394 * - reservationID; // reservation ID.
395 * - selRecordID; // SEL record ID.
396 *
397 * @returns ipmi completion code plus response data
398 * - Record ID of the deleted record
399 */
400ipmi::RspType<uint16_t // deleted record ID
401 >
402 deleteSELEntry(uint16_t reservationID, uint16_t selRecordID)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530403{
Jason M. Bills851acb12019-02-04 14:06:57 -0800404
Brad Bishop1a4117b2018-11-21 15:48:18 -0500405 namespace fs = std::filesystem;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530406
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000407 if (!checkSELReservation(reservationID))
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530408 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000409 return ipmi::responseInvalidReservationId();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530410 }
411
Jason M. Bills13e67c82018-09-10 14:12:16 -0700412 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
413 // deleted
414 cancelSELReservation();
415
Lei YUeba8e9a2021-09-15 13:16:17 +0800416 if (!selCacheMapInitialized)
Tom Josephe59abfb2018-08-06 18:46:27 +0530417 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800418 // In case the initSELCache() fails, try it again
419 initSELCache();
Tom Josephe59abfb2018-08-06 18:46:27 +0530420 }
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530421
Lei YUeba8e9a2021-09-15 13:16:17 +0800422 if (selCacheMap.empty())
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530423 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000424 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530425 }
426
Lei YUeba8e9a2021-09-15 13:16:17 +0800427 SELCacheMap::const_iterator iter;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530428 uint16_t delRecordID = 0;
429
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000430 if (selRecordID == ipmi::sel::firstEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530431 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800432 delRecordID = selCacheMap.begin()->first;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530433 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000434 else if (selRecordID == ipmi::sel::lastEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530435 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800436 delRecordID = selCacheMap.rbegin()->first;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530437 }
438 else
439 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000440 delRecordID = selRecordID;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530441 }
442
Jian7d5f4812022-02-23 19:30:27 +0800443 iter = selCacheMap.find(delRecordID);
444 if (iter == selCacheMap.end())
445 {
446 return ipmi::responseSensorInvalid();
447 }
448
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530449 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
450 std::string service;
451
Lei YUeba8e9a2021-09-15 13:16:17 +0800452 auto objPath = getLoggingObjPath(iter->first);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530453 try
454 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800455 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, objPath);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530456 }
457 catch (const std::runtime_error& e)
458 {
459 log<level::ERR>(e.what());
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000460 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530461 }
462
Lei YUeba8e9a2021-09-15 13:16:17 +0800463 auto methodCall = bus.new_method_call(service.c_str(), objPath.c_str(),
Patrick Venture0b02be92018-08-31 11:55:55 -0700464 ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530465 auto reply = bus.call(methodCall);
466 if (reply.is_method_error())
467 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000468 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530469 }
470
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000471 return ipmi::responseSuccess(delRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530472}
473
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000474/** @brief implements the Clear SEL command
475 * @request
476 * - reservationID // Reservation ID.
477 * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) }
478 * - eraseOperation; // requested operation.
479 *
480 * @returns ipmi completion code plus response data
481 * - erase status
482 */
483
484ipmi::RspType<uint8_t // erase status
485 >
486 clearSEL(uint16_t reservationID, const std::array<char, 3>& clr,
487 uint8_t eraseOperation)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530488{
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000489 static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'};
490 if (clr != clrOk)
Jason M. Bills851acb12019-02-04 14:06:57 -0800491 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000492 return ipmi::responseInvalidFieldRequest();
Jason M. Bills851acb12019-02-04 14:06:57 -0800493 }
494
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000495 if (!checkSELReservation(reservationID))
Tom Joseph2f05bb52017-06-30 19:14:49 +0530496 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000497 return ipmi::responseInvalidReservationId();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530498 }
499
Tom Joseph2f05bb52017-06-30 19:14:49 +0530500 /*
501 * Erasure status cannot be fetched from DBUS, so always return erasure
502 * status as `erase completed`.
503 */
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000504 if (eraseOperation == ipmi::sel::getEraseStatus)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530505 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000506 return ipmi::responseSuccess(
507 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530508 }
509
Jason M. Bills13e67c82018-09-10 14:12:16 -0700510 // Per the IPMI spec, need to cancel any reservation when the SEL is cleared
511 cancelSELReservation();
512
Tom Joseph2f05bb52017-06-30 19:14:49 +0530513 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Lotus Xu78fe1b12021-05-23 17:26:56 +0800514 auto service = ipmi::getService(bus, ipmi::sel::logIntf, ipmi::sel::logObj);
515 auto method =
516 bus.new_method_call(service.c_str(), ipmi::sel::logObj,
517 ipmi::sel::logIntf, ipmi::sel::logDeleteAllMethod);
Tom Josephe59abfb2018-08-06 18:46:27 +0530518 try
Tom Joseph2f05bb52017-06-30 19:14:49 +0530519 {
Lotus Xu78fe1b12021-05-23 17:26:56 +0800520 bus.call_noreply(method);
Tom Josephe59abfb2018-08-06 18:46:27 +0530521 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500522 catch (const sdbusplus::exception::exception& e)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530523 {
Lotus Xu78fe1b12021-05-23 17:26:56 +0800524 log<level::ERR>("Error eraseAll ", entry("ERROR=%s", e.what()));
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000525 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530526 }
527
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000528 return ipmi::responseSuccess(
529 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530530}
531
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000532/** @brief implements the get SEL time command
533 * @returns IPMI completion code plus response data
534 * -current time
535 */
536ipmi::RspType<uint32_t> // current time
537 ipmiStorageGetSelTime()
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500538{
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530539 using namespace std::chrono;
George Liu4d623e92020-05-25 16:51:57 +0800540 uint64_t bmc_time_usec = 0;
541 std::stringstream bmcTime;
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500542
Lei YUe8939392017-06-15 10:45:05 +0800543 try
544 {
545 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800546 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Vernon Mauery16b86932019-05-01 08:36:11 -0700547 std::variant<uint64_t> value;
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530548
George Liu4d623e92020-05-25 16:51:57 +0800549 // Get bmc time
550 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700551 DBUS_PROPERTIES, "Get");
Lei YUe8939392017-06-15 10:45:05 +0800552
553 method.append(TIME_INTERFACE, PROPERTY_ELAPSED);
554 auto reply = bus.call(method);
555 if (reply.is_method_error())
556 {
557 log<level::ERR>("Error getting time",
558 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800559 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000560 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800561 }
562 reply.read(value);
George Liu4d623e92020-05-25 16:51:57 +0800563 bmc_time_usec = std::get<uint64_t>(value);
Lei YUe8939392017-06-15 10:45:05 +0800564 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500565 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800566 {
567 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000568 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800569 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530570 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800571 {
572 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000573 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530574 }
575
George Liu4d623e92020-05-25 16:51:57 +0800576 bmcTime << "BMC time:"
577 << duration_cast<seconds>(microseconds(bmc_time_usec)).count();
578 log<level::DEBUG>(bmcTime.str().c_str());
Nagaraju Goruganti8960b7c2018-04-29 22:38:40 -0500579
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530580 // Time is really long int but IPMI wants just uint32. This works okay until
581 // the number of seconds since 1970 overflows uint32 size.. Still a whole
582 // lot of time here to even think about that.
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000583 return ipmi::responseSuccess(
George Liu4d623e92020-05-25 16:51:57 +0800584 duration_cast<seconds>(microseconds(bmc_time_usec)).count());
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500585}
586
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000587/** @brief implements the set SEL time command
588 * @param selDeviceTime - epoch time
589 * -local time as the number of seconds from 00:00:00, January 1, 1970
590 * @returns IPMI completion code
591 */
592ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime)
Chris Austenb4f5b922015-10-13 12:44:43 -0500593{
Lei YUe8939392017-06-15 10:45:05 +0800594 using namespace std::chrono;
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000595 microseconds usec{seconds(selDeviceTime)};
Norman James82330442015-11-19 16:53:26 -0600596
Lei YUe8939392017-06-15 10:45:05 +0800597 try
598 {
599 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800600 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Andrew Geissler6467ed22020-05-16 16:03:53 -0500601 std::variant<uint64_t> value{(uint64_t)usec.count()};
Lei YUe8939392017-06-15 10:45:05 +0800602
George Liu4d623e92020-05-25 16:51:57 +0800603 // Set bmc time
604 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700605 DBUS_PROPERTIES, "Set");
Lei YUe8939392017-06-15 10:45:05 +0800606
607 method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value);
608 auto reply = bus.call(method);
609 if (reply.is_method_error())
610 {
611 log<level::ERR>("Error setting time",
612 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800613 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000614 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800615 }
Norman James82330442015-11-19 16:53:26 -0600616 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500617 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800618 {
619 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000620 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530621 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530622 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800623 {
624 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000625 return ipmi::responseUnspecifiedError();
Norman James82330442015-11-19 16:53:26 -0600626 }
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530627
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000628 return ipmi::responseSuccess();
Chris Austenb4f5b922015-10-13 12:44:43 -0500629}
630
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000631/** @brief implements the reserve SEL command
632 * @returns IPMI completion code plus response data
633 * - SEL reservation ID.
634 */
635ipmi::RspType<uint16_t> ipmiStorageReserveSel()
Chris Austenb4f5b922015-10-13 12:44:43 -0500636{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000637 return ipmi::responseSuccess(reserveSel());
Chris Austenb4f5b922015-10-13 12:44:43 -0500638}
639
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000640/** @brief implements the Add SEL entry command
641 * @request
642 *
643 * - recordID ID used for SEL Record access
644 * - recordType Record Type
645 * - timeStamp Time when event was logged. LS byte first
646 * - generatorID software ID if event was generated from
647 * system software
648 * - evmRev event message format version
649 * - sensorType sensor type code for service that generated
650 * the event
651 * - sensorNumber number of sensors that generated the event
652 * - eventDir event dir
653 * - eventData event data field contents
654 *
655 * @returns ipmi completion code plus response data
656 * - RecordID of the Added SEL entry
657 */
658ipmi::RspType<uint16_t // recordID of the Added SEL entry
659 >
660 ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, uint32_t timeStamp,
661 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType,
662 uint8_t sensorNumber, uint8_t eventDir,
663 std::array<uint8_t, eventDataSize> eventData)
Chris Austenb4f5b922015-10-13 12:44:43 -0500664{
Lotus Xu57d35572021-01-24 11:13:13 +0800665 std::string objpath;
666 static constexpr auto systemRecordType = 0x02;
Tom Josephb647d5b2017-10-31 17:25:33 +0530667 // Hostboot sends SEL with OEM record type 0xDE to indicate that there is
668 // a maintenance procedure associated with eSEL record.
669 static constexpr auto procedureType = 0xDE;
Lotus Xu57d35572021-01-24 11:13:13 +0800670 cancelSELReservation();
671 if (recordType == systemRecordType)
672 {
673
674 for (const auto& it : invSensors)
675 {
676 if (it.second.sensorID == sensorNumber)
677 {
678 objpath = it.first;
679 break;
680 }
681 }
682 auto selDataStr = ipmi::sel::toHexStr(eventData);
683
684 bool assert = (eventDir & 0x80) ? false : true;
685
686 recordID = report<SELCreated>(Created::RECORD_TYPE(recordType),
687 Created::GENERATOR_ID(generatorID),
688 Created::SENSOR_DATA(selDataStr.c_str()),
689 Created::EVENT_DIR(assert),
690 Created::SENSOR_PATH(objpath.c_str()));
691 }
692 else if (recordType == procedureType)
Tom Josephb647d5b2017-10-31 17:25:33 +0530693 {
694 // In the OEM record type 0xDE, byte 11 in the SEL record indicate the
695 // procedure number.
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000696 createProcedureLogEntry(sensorType);
Tom Josephb647d5b2017-10-31 17:25:33 +0530697 }
Chris Austenb4f5b922015-10-13 12:44:43 -0500698
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000699 return ipmi::responseSuccess(recordID);
Chris Austenb4f5b922015-10-13 12:44:43 -0500700}
701
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300702bool isFruPresent(ipmi::Context::ptr& ctx, const std::string& fruPath)
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300703{
704 using namespace ipmi::fru;
705
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300706 std::string service;
707 boost::system::error_code ec =
708 getService(ctx, invItemInterface, invObjPath + fruPath, service);
709 if (!ec)
710 {
711 bool result;
712 ec = ipmi::getDbusProperty(ctx, service, invObjPath + fruPath,
713 invItemInterface, itemPresentProp, result);
714 if (!ec)
715 {
716 return result;
717 }
718 }
Konstantin Aladyshevc7e4b042021-12-24 15:30:47 +0300719
720 ipmi::ObjectValueTree managedObjects;
721 ec = getManagedObjects(ctx, "xyz.openbmc_project.EntityManager", "/",
722 managedObjects);
723 if (!ec)
724 {
725 auto connection = managedObjects.find(fruPath);
726 if (connection != managedObjects.end())
727 {
728 return true;
729 }
730 }
731
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300732 return false;
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300733}
734
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000735/** @brief implements the get FRU Inventory Area Info command
736 *
737 * @returns IPMI completion code plus response data
738 * - FRU Inventory area size in bytes,
739 * - access bit
740 **/
741ipmi::RspType<uint16_t, // FRU Inventory area size in bytes,
742 uint8_t // access size (bytes / words)
743 >
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300744 ipmiStorageGetFruInvAreaInfo(ipmi::Context::ptr ctx, uint8_t fruID)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500745{
Tom Joseph187f5642018-03-29 13:49:06 +0530746
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000747 auto iter = frus.find(fruID);
Tom Joseph187f5642018-03-29 13:49:06 +0530748 if (iter == frus.end())
749 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000750 return ipmi::responseSensorInvalid();
Tom Joseph187f5642018-03-29 13:49:06 +0530751 }
752
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300753 auto path = iter->second[0].path;
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300754 if (!isFruPresent(ctx, path))
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300755 {
756 return ipmi::responseSensorInvalid();
757 }
758
Marri Devender Raocac383b2017-07-03 13:24:27 -0500759 try
760 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000761 return ipmi::responseSuccess(
762 static_cast<uint16_t>(getFruAreaData(fruID).size()),
763 static_cast<uint8_t>(AccessMode::bytes));
Marri Devender Raocac383b2017-07-03 13:24:27 -0500764 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700765 catch (const InternalFailure& e)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500766 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500767 log<level::ERR>(e.what());
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000768 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500769 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500770}
771
anil kumar appana5b7c3262019-05-27 18:10:23 +0000772/**@brief implements the Read FRU Data command
773 * @param fruDeviceId - FRU device ID. FFh = reserved
774 * @param offset - FRU inventory offset to read
775 * @param readCount - count to read
776 *
777 * @return IPMI completion code plus response data
778 * - returnCount - response data count.
779 * - data - response data
780 */
781ipmi::RspType<uint8_t, // count returned
782 std::vector<uint8_t>> // FRU data
783 ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset,
784 uint8_t readCount)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500785{
anil kumar appana5b7c3262019-05-27 18:10:23 +0000786 if (fruDeviceId == 0xFF)
Tom Joseph187f5642018-03-29 13:49:06 +0530787 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000788 return ipmi::responseInvalidFieldRequest();
Tom Joseph187f5642018-03-29 13:49:06 +0530789 }
790
anil kumar appana5b7c3262019-05-27 18:10:23 +0000791 auto iter = frus.find(fruDeviceId);
792 if (iter == frus.end())
793 {
794 return ipmi::responseSensorInvalid();
795 }
796
Marri Devender Raocac383b2017-07-03 13:24:27 -0500797 try
798 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000799 const auto& fruArea = getFruAreaData(fruDeviceId);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500800 auto size = fruArea.size();
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500801
Tom Josephefcd68b2018-04-26 18:46:27 +0530802 if (offset >= size)
803 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000804 return ipmi::responseParmOutOfRange();
Tom Josephefcd68b2018-04-26 18:46:27 +0530805 }
806
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500807 // Write the count of response data.
anil kumar appana5b7c3262019-05-27 18:10:23 +0000808 uint8_t returnCount;
809 if ((offset + readCount) <= size)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500810 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000811 returnCount = readCount;
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500812 }
813 else
814 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000815 returnCount = size - offset;
Marri Devender Raocac383b2017-07-03 13:24:27 -0500816 }
Ratan Gupta2848d602018-01-31 20:39:20 +0530817
anil kumar appana5b7c3262019-05-27 18:10:23 +0000818 std::vector<uint8_t> fruData((fruArea.begin() + offset),
819 (fruArea.begin() + offset + returnCount));
Ratan Gupta2848d602018-01-31 20:39:20 +0530820
anil kumar appana5b7c3262019-05-27 18:10:23 +0000821 return ipmi::responseSuccess(returnCount, fruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500822 }
823 catch (const InternalFailure& e)
824 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500825 log<level::ERR>(e.what());
anil kumar appana5b7c3262019-05-27 18:10:23 +0000826 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500827 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500828}
829
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000830ipmi::RspType<uint8_t, // SDR version
831 uint16_t, // record count LS first
832 uint16_t, // free space in bytes, LS first
833 uint32_t, // addition timestamp LS first
834 uint32_t, // deletion timestamp LS first
835 uint8_t> // operation Support
836 ipmiGetRepositoryInfo()
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600837{
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600838
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000839 constexpr uint8_t sdrVersion = 0x51;
840 constexpr uint16_t freeSpace = 0xFFFF;
841 constexpr uint32_t additionTimestamp = 0x0;
842 constexpr uint32_t deletionTimestamp = 0x0;
843 constexpr uint8_t operationSupport = 0;
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600844
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700845 uint16_t records = frus.size() + ipmi::sensor::sensors.size();
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600846
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000847 return ipmi::responseSuccess(sdrVersion, records, freeSpace,
848 additionTimestamp, deletionTimestamp,
849 operationSupport);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600850}
Chris Austenb4f5b922015-10-13 12:44:43 -0500851
Chris Austenb4f5b922015-10-13 12:44:43 -0500852void register_netfn_storage_functions()
853{
Lei YU3df36612021-09-15 11:41:11 +0800854 selCacheMapInitialized = false;
Lei YUd9e57662021-09-14 18:06:28 +0800855 initSELCache();
Willy Tud351a722021-08-12 14:33:40 -0700856 // Handlers with dbus-sdr handler implementation.
857 // Do not register the hander if it dynamic sensors stack is used.
858
859#ifndef FEATURE_DYNAMIC_SENSORS
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530860 // <Get SEL Info>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000861 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
862 ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
863 ipmiStorageGetSelInfo);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530864
Tom05732372016-09-06 17:21:23 +0530865 // <Get SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000866 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
867 ipmi::storage::cmdGetSelTime, ipmi::Privilege::User,
868 ipmiStorageGetSelTime);
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500869
Tom05732372016-09-06 17:21:23 +0530870 // <Set SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000871 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
872 ipmi::storage::cmdSetSelTime,
873 ipmi::Privilege::Operator, ipmiStorageSetSelTime);
Chris Austenb4f5b922015-10-13 12:44:43 -0500874
Tom Josepha4953392017-06-30 19:09:47 +0530875 // <Get SEL Entry>
Patrick Venture0b02be92018-08-31 11:55:55 -0700876 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL,
877 getSELEntry, PRIVILEGE_USER);
Tom Josepha4953392017-06-30 19:09:47 +0530878
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530879 // <Delete SEL Entry>
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000880 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
881 ipmi::storage::cmdDeleteSelEntry,
882 ipmi::Privilege::Operator, deleteSELEntry);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530883
Tom05732372016-09-06 17:21:23 +0530884 // <Add SEL Entry>
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000885 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
886 ipmi::storage::cmdAddSelEntry,
887 ipmi::Privilege::Operator, ipmiStorageAddSEL);
888
Tom Joseph2f05bb52017-06-30 19:14:49 +0530889 // <Clear SEL>
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000890 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
891 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
892 clearSEL);
893
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500894 // <Get FRU Inventory Area Info>
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000895 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
896 ipmi::storage::cmdGetFruInventoryAreaInfo,
897 ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500898
Jason M. Billsb5248c92019-06-24 15:53:08 -0700899 // <READ FRU Data>
anil kumar appana5b7c3262019-05-27 18:10:23 +0000900 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
901 ipmi::storage::cmdReadFruData,
902 ipmi::Privilege::Operator, ipmiStorageReadFruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500903
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600904 // <Get Repository Info>
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000905 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
906 ipmi::storage::cmdGetSdrRepositoryInfo,
907 ipmi::Privilege::User, ipmiGetRepositoryInfo);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600908
Tom Joseph5ca50952018-02-22 00:33:38 +0530909 // <Reserve SDR Repository>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000910 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
911 ipmi::storage::cmdReserveSdrRepository,
912 ipmi::Privilege::User, ipmiSensorReserveSdr);
Tom Joseph5ca50952018-02-22 00:33:38 +0530913
914 // <Get SDR>
Patrick Venture0b02be92018-08-31 11:55:55 -0700915 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr,
916 ipmi_sen_get_sdr, PRIVILEGE_USER);
Tom Joseph5ca50952018-02-22 00:33:38 +0530917
Willy Tud351a722021-08-12 14:33:40 -0700918#endif
919
920 // Common Handers used by both implementation.
921
922 // <Reserve SEL>
923 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
924 ipmi::storage::cmdReserveSel, ipmi::Privilege::User,
925 ipmiStorageReserveSel);
926
Marri Devender Rao908f7502017-07-10 01:49:54 -0500927 ipmi::fru::registerCallbackHandler();
Chris Austenb4f5b922015-10-13 12:44:43 -0500928 return;
929}