blob: 9608dcc1124ef198578416938013406df7ba3954 [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>
22#include <phosphor-logging/log.hpp>
23#include <sdbusplus/server.hpp>
24#include <string>
Vernon Mauery16b86932019-05-01 08:36:11 -070025#include <variant>
Patrick Venture3a5071a2018-09-12 13:27:42 -070026#include <xyz/openbmc_project/Common/error.hpp>
27
Chris Austenb4f5b922015-10-13 12:44:43 -050028void register_netfn_storage_functions() __attribute__((constructor));
29
Patrick Venture0b02be92018-08-31 11:55:55 -070030unsigned int g_sel_time = 0xFFFFFFFF;
Patrick Venturedb0cbe62019-09-09 14:47:22 -070031namespace ipmi
32{
33namespace sensor
34{
35extern const IdInfoMap sensors;
36} // namespace sensor
37} // namespace ipmi
38
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -060039extern const FruMap frus;
anil kumar appana2c7db1d2019-05-28 11:20:19 +000040constexpr uint8_t eventDataSize = 3;
Patrick Venture0b02be92018-08-31 11:55:55 -070041namespace
42{
Lei YUe8939392017-06-15 10:45:05 +080043constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime";
George Liu4d623e92020-05-25 16:51:57 +080044constexpr auto BMC_TIME_PATH = "/xyz/openbmc_project/time/bmc";
Lei YUe8939392017-06-15 10:45:05 +080045constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties";
Patrick Venture0b02be92018-08-31 11:55:55 -070046constexpr auto PROPERTY_ELAPSED = "Elapsed";
Lei YUe8939392017-06-15 10:45:05 +080047
Lei YUd9555252021-09-14 20:30:41 +080048constexpr auto logWatchPath = "/xyz/openbmc_project/logging";
Lei YUd9e57662021-09-14 18:06:28 +080049constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
50constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
51constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
Patrick Venture0b02be92018-08-31 11:55:55 -070052} // namespace
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +053053
Tom Joseph6f7deaa2017-06-30 19:03:54 +053054using InternalFailure =
Patrick Venture0b02be92018-08-31 11:55:55 -070055 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053056using namespace phosphor::logging;
Marri Devender Raocac383b2017-07-03 13:24:27 -050057using namespace ipmi::fru;
58
Lei YUd9e57662021-09-14 18:06:28 +080059using SELRecordID = uint16_t;
60using SELEntry = ipmi::sel::SELEventRecordFormat;
61using SELCacheMap = std::map<SELRecordID, SELEntry>;
62
63SELCacheMap selCacheMap __attribute__((init_priority(101)));
Lei YU3df36612021-09-15 11:41:11 +080064bool selCacheMapInitialized;
Lei YUd9555252021-09-14 20:30:41 +080065std::unique_ptr<sdbusplus::bus::match::match> selAddedMatch
66 __attribute__((init_priority(101)));
Lei YUb6b72b02021-09-14 21:06:05 +080067std::unique_ptr<sdbusplus::bus::match::match> selRemovedMatch
68 __attribute__((init_priority(101)));
Lei YU4106e422021-09-15 10:55:51 +080069std::unique_ptr<sdbusplus::bus::match::match> selUpdatedMatch
70 __attribute__((init_priority(101)));
Lei YUd9e57662021-09-14 18:06:28 +080071
Lei YUb6b72b02021-09-14 21:06:05 +080072static inline uint16_t getLoggingId(const std::string& p)
Lei YUd9e57662021-09-14 18:06:28 +080073{
74 namespace fs = std::filesystem;
75 fs::path entryPath(p);
Lei YUb6b72b02021-09-14 21:06:05 +080076 return std::stoul(entryPath.filename().string());
77}
78
Lei YUeba8e9a2021-09-15 13:16:17 +080079static inline std::string getLoggingObjPath(uint16_t id)
80{
81 return std::string(ipmi::sel::logBasePath) + "/" + std::to_string(id);
82}
83
Lei YUa0bb2a32021-09-24 11:03:56 +080084std::optional<std::pair<uint16_t, SELEntry>>
85 parseLoggingEntry(const std::string& p)
Lei YUb6b72b02021-09-14 21:06:05 +080086{
Lei YU3df36612021-09-15 11:41:11 +080087 try
88 {
Lei YUa0bb2a32021-09-24 11:03:56 +080089 auto id = getLoggingId(p);
90 ipmi::sel::GetSELEntryResponse record{};
Lei YU3df36612021-09-15 11:41:11 +080091 record = ipmi::sel::convertLogEntrytoSEL(p);
Lei YUa0bb2a32021-09-24 11:03:56 +080092 return std::pair<uint16_t, SELEntry>({id, std::move(record.event)});
Lei YU3df36612021-09-15 11:41:11 +080093 }
94 catch (const std::exception& e)
95 {
96 fprintf(stderr, "Failed to convert %s to SEL: %s\n", p.c_str(),
97 e.what());
98 }
Lei YUa0bb2a32021-09-24 11:03:56 +080099 return std::nullopt;
Lei YUd9e57662021-09-14 18:06:28 +0800100}
101
Lei YUd9555252021-09-14 20:30:41 +0800102static void selAddedCallback(sdbusplus::message::message& m)
103{
104 sdbusplus::message::object_path objPath;
105 try
106 {
107 m.read(objPath);
108 }
109 catch (const sdbusplus::exception::exception& e)
110 {
111 log<level::ERR>("Failed to read object path");
112 return;
113 }
114 std::string p = objPath;
Lei YUa0bb2a32021-09-24 11:03:56 +0800115 auto entry = parseLoggingEntry(p);
116 if (entry)
117 {
118 selCacheMap.insert(std::move(*entry));
119 }
Lei YUd9555252021-09-14 20:30:41 +0800120}
121
Lei YUb6b72b02021-09-14 21:06:05 +0800122static void selRemovedCallback(sdbusplus::message::message& m)
123{
124 sdbusplus::message::object_path objPath;
125 try
126 {
127 m.read(objPath);
128 }
129 catch (const sdbusplus::exception::exception& e)
130 {
131 log<level::ERR>("Failed to read object path");
Lei YUb6b72b02021-09-14 21:06:05 +0800132 }
Lei YUa0bb2a32021-09-24 11:03:56 +0800133 try
134 {
135 std::string p = objPath;
136 selCacheMap.erase(getLoggingId(p));
137 }
138 catch (const std::invalid_argument& e)
139 {
140 log<level::ERR>("Invalid logging entry ID");
141 }
Lei YUb6b72b02021-09-14 21:06:05 +0800142}
143
Lei YU4106e422021-09-15 10:55:51 +0800144static void selUpdatedCallback(sdbusplus::message::message& m)
145{
146 std::string p = m.get_path();
147 auto entry = parseLoggingEntry(p);
Lei YUa0bb2a32021-09-24 11:03:56 +0800148 if (entry)
149 {
150 selCacheMap.insert_or_assign(entry->first, std::move(entry->second));
151 }
Lei YU4106e422021-09-15 10:55:51 +0800152}
153
Lei YUd9555252021-09-14 20:30:41 +0800154void registerSelCallbackHandler()
155{
156 using namespace sdbusplus::bus::match::rules;
157 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
158 if (!selAddedMatch)
159 {
160 selAddedMatch = std::make_unique<sdbusplus::bus::match::match>(
161 bus, interfacesAdded(logWatchPath),
162 std::bind(selAddedCallback, std::placeholders::_1));
163 }
Lei YUb6b72b02021-09-14 21:06:05 +0800164 if (!selRemovedMatch)
165 {
166 selRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
167 bus, interfacesRemoved(logWatchPath),
168 std::bind(selRemovedCallback, std::placeholders::_1));
169 }
Lei YU4106e422021-09-15 10:55:51 +0800170 if (!selUpdatedMatch)
171 {
172 selUpdatedMatch = std::make_unique<sdbusplus::bus::match::match>(
173 bus,
174 type::signal() + member("PropertiesChanged"s) +
175 interface("org.freedesktop.DBus.Properties"s) +
176 argN(0, logEntryIntf),
177 std::bind(selUpdatedCallback, std::placeholders::_1));
178 }
Lei YUd9555252021-09-14 20:30:41 +0800179}
180
Lei YUd9e57662021-09-14 18:06:28 +0800181void initSELCache()
182{
Lei YUeba8e9a2021-09-15 13:16:17 +0800183 ipmi::sel::ObjectPaths paths;
Lei YUd9e57662021-09-14 18:06:28 +0800184 try
185 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800186 ipmi::sel::readLoggingObjectPaths(paths);
Lei YUd9e57662021-09-14 18:06:28 +0800187 }
188 catch (const sdbusplus::exception::exception& e)
189 {
190 log<level::ERR>("Failed to get logging object paths");
191 return;
192 }
Lei YUeba8e9a2021-09-15 13:16:17 +0800193 for (const auto& p : paths)
Lei YUd9e57662021-09-14 18:06:28 +0800194 {
Lei YUa0bb2a32021-09-24 11:03:56 +0800195 auto entry = parseLoggingEntry(p);
196 if (entry)
197 {
198 selCacheMap.insert(std::move(*entry));
199 }
Lei YUd9e57662021-09-14 18:06:28 +0800200 }
Lei YUd9555252021-09-14 20:30:41 +0800201 registerSelCallbackHandler();
Lei YU3df36612021-09-15 11:41:11 +0800202 selCacheMapInitialized = true;
Lei YUd9e57662021-09-14 18:06:28 +0800203}
204
Marri Devender Raocac383b2017-07-03 13:24:27 -0500205/**
206 * @enum Device access mode
207 */
208enum class AccessMode
209{
210 bytes, ///< Device is accessed by bytes
211 words ///< Device is accessed by words
212};
213
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000214/** @brief implements the get SEL Info command
215 * @returns IPMI completion code plus response data
216 * - selVersion - SEL revision
217 * - entries - Number of log entries in SEL.
218 * - freeSpace - Free Space in bytes.
219 * - addTimeStamp - Most recent addition timestamp
220 * - eraseTimeStamp - Most recent erase timestamp
221 * - operationSupport - Reserve & Delete SEL operations supported
222 */
223
224ipmi::RspType<uint8_t, // SEL revision.
225 uint16_t, // number of log entries in SEL.
226 uint16_t, // free Space in bytes.
227 uint32_t, // most recent addition timestamp
228 uint32_t, // most recent erase timestamp.
229
230 bool, // SEL allocation info supported
231 bool, // reserve SEL supported
232 bool, // partial Add SEL Entry supported
233 bool, // delete SEL supported
234 uint3_t, // reserved
235 bool // overflow flag
236 >
237 ipmiStorageGetSelInfo()
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530238{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000239 uint16_t entries = 0;
240 // Most recent addition timestamp.
241 uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp;
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530242
Lei YUeba8e9a2021-09-15 13:16:17 +0800243 if (!selCacheMapInitialized)
Tom Josephe59abfb2018-08-06 18:46:27 +0530244 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800245 // In case the initSELCache() fails, try it again
246 initSELCache();
Tom Josephe59abfb2018-08-06 18:46:27 +0530247 }
Lei YUeba8e9a2021-09-15 13:16:17 +0800248 if (!selCacheMap.empty())
Tom Josephe59abfb2018-08-06 18:46:27 +0530249 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800250 entries = static_cast<uint16_t>(selCacheMap.size());
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530251
252 try
253 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800254 auto objPath = getLoggingObjPath(selCacheMap.rbegin()->first);
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000255 addTimeStamp = static_cast<uint32_t>(
Lei YUeba8e9a2021-09-15 13:16:17 +0800256 (ipmi::sel::getEntryTimeStamp(objPath).count()));
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530257 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500258 catch (const InternalFailure& e)
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530259 {
260 }
261 catch (const std::runtime_error& e)
262 {
263 log<level::ERR>(e.what());
264 }
265 }
266
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000267 constexpr uint8_t selVersion = ipmi::sel::selVersion;
268 constexpr uint16_t freeSpace = 0xFFFF;
269 constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp;
270 constexpr uint3_t reserved{0};
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530271
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000272 return ipmi::responseSuccess(
273 selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp,
274 ipmi::sel::operationSupport::getSelAllocationInfo,
275 ipmi::sel::operationSupport::reserveSel,
276 ipmi::sel::operationSupport::partialAddSelEntry,
277 ipmi::sel::operationSupport::deleteSel, reserved,
278 ipmi::sel::operationSupport::overflow);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530279}
280
Tom Josepha4953392017-06-30 19:09:47 +0530281ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
282 ipmi_request_t request, ipmi_response_t response,
283 ipmi_data_len_t data_len, ipmi_context_t context)
284{
Jason M. Bills851acb12019-02-04 14:06:57 -0800285 if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest))
286 {
287 *data_len = 0;
288 return IPMI_CC_REQ_DATA_LEN_INVALID;
289 }
290
Patrick Venture0b02be92018-08-31 11:55:55 -0700291 auto requestData =
292 reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request);
Tom Josepha4953392017-06-30 19:09:47 +0530293
294 if (requestData->reservationID != 0)
295 {
Jason M. Bills13e67c82018-09-10 14:12:16 -0700296 if (!checkSELReservation(requestData->reservationID))
Tom Josepha4953392017-06-30 19:09:47 +0530297 {
298 *data_len = 0;
299 return IPMI_CC_INVALID_RESERVATION_ID;
300 }
301 }
302
Lei YU3df36612021-09-15 11:41:11 +0800303 if (!selCacheMapInitialized)
304 {
305 // In case the initSELCache() fails, try it again
306 initSELCache();
307 }
308
309 if (selCacheMap.empty())
Tom Josepha4953392017-06-30 19:09:47 +0530310 {
311 *data_len = 0;
312 return IPMI_CC_SENSOR_INVALID;
313 }
314
Lei YU3df36612021-09-15 11:41:11 +0800315 SELCacheMap::const_iterator iter;
Tom Josepha4953392017-06-30 19:09:47 +0530316
317 // Check for the requested SEL Entry.
318 if (requestData->selRecordID == ipmi::sel::firstEntry)
319 {
Lei YU3df36612021-09-15 11:41:11 +0800320 iter = selCacheMap.begin();
Tom Josepha4953392017-06-30 19:09:47 +0530321 }
322 else if (requestData->selRecordID == ipmi::sel::lastEntry)
323 {
Lei YU3df36612021-09-15 11:41:11 +0800324 if (selCacheMap.size() > 1)
325 {
326 iter = selCacheMap.end();
327 --iter;
328 }
329 else
330 {
331 // Only one entry exists, return the first
332 iter = selCacheMap.begin();
333 }
Tom Josepha4953392017-06-30 19:09:47 +0530334 }
335 else
336 {
Lei YU3df36612021-09-15 11:41:11 +0800337 iter = selCacheMap.find(requestData->selRecordID);
338 if (iter == selCacheMap.end())
Tom Josepha4953392017-06-30 19:09:47 +0530339 {
340 *data_len = 0;
341 return IPMI_CC_SENSOR_INVALID;
342 }
343 }
344
Lei YU3df36612021-09-15 11:41:11 +0800345 ipmi::sel::GetSELEntryResponse record{0, iter->second};
Tom Josepha4953392017-06-30 19:09:47 +0530346 // Identify the next SEL record ID
Lei YU3df36612021-09-15 11:41:11 +0800347 ++iter;
348 if (iter == selCacheMap.end())
Tom Josepha4953392017-06-30 19:09:47 +0530349 {
Lei YU3df36612021-09-15 11:41:11 +0800350 record.nextRecordID = ipmi::sel::lastEntry;
Tom Josepha4953392017-06-30 19:09:47 +0530351 }
352 else
353 {
Lei YU3df36612021-09-15 11:41:11 +0800354 record.nextRecordID = iter->first;
Tom Josepha4953392017-06-30 19:09:47 +0530355 }
356
357 if (requestData->readLength == ipmi::sel::entireRecord)
358 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700359 std::memcpy(response, &record, sizeof(record));
Tom Josepha4953392017-06-30 19:09:47 +0530360 *data_len = sizeof(record);
361 }
362 else
363 {
364 if (requestData->offset >= ipmi::sel::selRecordSize ||
365 requestData->readLength > ipmi::sel::selRecordSize)
366 {
367 *data_len = 0;
368 return IPMI_CC_INVALID_FIELD_REQUEST;
369 }
370
371 auto diff = ipmi::sel::selRecordSize - requestData->offset;
Patrick Venture0b02be92018-08-31 11:55:55 -0700372 auto readLength =
373 std::min(diff, static_cast<int>(requestData->readLength));
Tom Josepha4953392017-06-30 19:09:47 +0530374
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700375 std::memcpy(response, &record.nextRecordID,
376 sizeof(record.nextRecordID));
377 std::memcpy(static_cast<uint8_t*>(response) +
378 sizeof(record.nextRecordID),
Lei YUaf378fa2020-12-02 16:28:57 +0800379 &record.event.eventRecord.recordID + requestData->offset,
380 readLength);
Tom Josepha4953392017-06-30 19:09:47 +0530381 *data_len = sizeof(record.nextRecordID) + readLength;
382 }
383
384 return IPMI_CC_OK;
385}
386
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000387/** @brief implements the delete SEL entry command
388 * @request
389 * - reservationID; // reservation ID.
390 * - selRecordID; // SEL record ID.
391 *
392 * @returns ipmi completion code plus response data
393 * - Record ID of the deleted record
394 */
395ipmi::RspType<uint16_t // deleted record ID
396 >
397 deleteSELEntry(uint16_t reservationID, uint16_t selRecordID)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530398{
Jason M. Bills851acb12019-02-04 14:06:57 -0800399
Brad Bishop1a4117b2018-11-21 15:48:18 -0500400 namespace fs = std::filesystem;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530401
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000402 if (!checkSELReservation(reservationID))
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530403 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000404 return ipmi::responseInvalidReservationId();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530405 }
406
Jason M. Bills13e67c82018-09-10 14:12:16 -0700407 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
408 // deleted
409 cancelSELReservation();
410
Lei YUeba8e9a2021-09-15 13:16:17 +0800411 if (!selCacheMapInitialized)
Tom Josephe59abfb2018-08-06 18:46:27 +0530412 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800413 // In case the initSELCache() fails, try it again
414 initSELCache();
Tom Josephe59abfb2018-08-06 18:46:27 +0530415 }
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530416
Lei YUeba8e9a2021-09-15 13:16:17 +0800417 if (selCacheMap.empty())
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530418 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000419 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530420 }
421
Lei YUeba8e9a2021-09-15 13:16:17 +0800422 SELCacheMap::const_iterator iter;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530423 uint16_t delRecordID = 0;
424
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000425 if (selRecordID == ipmi::sel::firstEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530426 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800427 delRecordID = selCacheMap.begin()->first;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530428 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000429 else if (selRecordID == ipmi::sel::lastEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530430 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800431 delRecordID = selCacheMap.rbegin()->first;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530432 }
433 else
434 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800435 iter = selCacheMap.find(selRecordID);
436 if (iter == selCacheMap.end())
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530437 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000438 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530439 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000440 delRecordID = selRecordID;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530441 }
442
443 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
444 std::string service;
445
Lei YUeba8e9a2021-09-15 13:16:17 +0800446 auto objPath = getLoggingObjPath(iter->first);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530447 try
448 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800449 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, objPath);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530450 }
451 catch (const std::runtime_error& e)
452 {
453 log<level::ERR>(e.what());
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000454 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530455 }
456
Lei YUeba8e9a2021-09-15 13:16:17 +0800457 auto methodCall = bus.new_method_call(service.c_str(), objPath.c_str(),
Patrick Venture0b02be92018-08-31 11:55:55 -0700458 ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530459 auto reply = bus.call(methodCall);
460 if (reply.is_method_error())
461 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000462 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530463 }
464
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000465 return ipmi::responseSuccess(delRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530466}
467
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000468/** @brief implements the Clear SEL command
469 * @request
470 * - reservationID // Reservation ID.
471 * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) }
472 * - eraseOperation; // requested operation.
473 *
474 * @returns ipmi completion code plus response data
475 * - erase status
476 */
477
478ipmi::RspType<uint8_t // erase status
479 >
480 clearSEL(uint16_t reservationID, const std::array<char, 3>& clr,
481 uint8_t eraseOperation)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530482{
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000483 static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'};
484 if (clr != clrOk)
Jason M. Bills851acb12019-02-04 14:06:57 -0800485 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000486 return ipmi::responseInvalidFieldRequest();
Jason M. Bills851acb12019-02-04 14:06:57 -0800487 }
488
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000489 if (!checkSELReservation(reservationID))
Tom Joseph2f05bb52017-06-30 19:14:49 +0530490 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000491 return ipmi::responseInvalidReservationId();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530492 }
493
Tom Joseph2f05bb52017-06-30 19:14:49 +0530494 /*
495 * Erasure status cannot be fetched from DBUS, so always return erasure
496 * status as `erase completed`.
497 */
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000498 if (eraseOperation == ipmi::sel::getEraseStatus)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530499 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000500 return ipmi::responseSuccess(
501 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530502 }
503
Jason M. Bills13e67c82018-09-10 14:12:16 -0700504 // Per the IPMI spec, need to cancel any reservation when the SEL is cleared
505 cancelSELReservation();
506
Tom Joseph2f05bb52017-06-30 19:14:49 +0530507 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Tom Josephe59abfb2018-08-06 18:46:27 +0530508 ipmi::sel::ObjectPaths objectPaths;
Tom Joseph2f05bb52017-06-30 19:14:49 +0530509 auto depth = 0;
510
Patrick Venture0b02be92018-08-31 11:55:55 -0700511 auto mapperCall =
512 bus.new_method_call(ipmi::sel::mapperBusName, ipmi::sel::mapperObjPath,
513 ipmi::sel::mapperIntf, "GetSubTreePaths");
Tom Joseph2f05bb52017-06-30 19:14:49 +0530514 mapperCall.append(ipmi::sel::logBasePath);
515 mapperCall.append(depth);
516 mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf}));
517
Tom Josephe59abfb2018-08-06 18:46:27 +0530518 try
Tom Joseph2f05bb52017-06-30 19:14:49 +0530519 {
Tom Josephe59abfb2018-08-06 18:46:27 +0530520 auto reply = bus.call(mapperCall);
521 if (reply.is_method_error())
522 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000523 return ipmi::responseSuccess(
524 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Josephe59abfb2018-08-06 18:46:27 +0530525 }
Tom Joseph2f05bb52017-06-30 19:14:49 +0530526
Tom Josephe59abfb2018-08-06 18:46:27 +0530527 reply.read(objectPaths);
528 if (objectPaths.empty())
529 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000530 return ipmi::responseSuccess(
531 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Josephe59abfb2018-08-06 18:46:27 +0530532 }
533 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500534 catch (const sdbusplus::exception::exception& e)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530535 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000536 return ipmi::responseSuccess(
537 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530538 }
539
540 std::string service;
541
542 try
543 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700544 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf,
Tom Joseph2f05bb52017-06-30 19:14:49 +0530545 objectPaths.front());
546 }
547 catch (const std::runtime_error& e)
548 {
549 log<level::ERR>(e.what());
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000550 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530551 }
552
553 for (const auto& iter : objectPaths)
554 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700555 auto methodCall = bus.new_method_call(
556 service.c_str(), iter.c_str(), ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph2f05bb52017-06-30 19:14:49 +0530557
558 auto reply = bus.call(methodCall);
559 if (reply.is_method_error())
560 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000561 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530562 }
563 }
564
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000565 return ipmi::responseSuccess(
566 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530567}
568
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000569/** @brief implements the get SEL time command
570 * @returns IPMI completion code plus response data
571 * -current time
572 */
573ipmi::RspType<uint32_t> // current time
574 ipmiStorageGetSelTime()
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500575{
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530576 using namespace std::chrono;
George Liu4d623e92020-05-25 16:51:57 +0800577 uint64_t bmc_time_usec = 0;
578 std::stringstream bmcTime;
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500579
Lei YUe8939392017-06-15 10:45:05 +0800580 try
581 {
582 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800583 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Vernon Mauery16b86932019-05-01 08:36:11 -0700584 std::variant<uint64_t> value;
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530585
George Liu4d623e92020-05-25 16:51:57 +0800586 // Get bmc time
587 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700588 DBUS_PROPERTIES, "Get");
Lei YUe8939392017-06-15 10:45:05 +0800589
590 method.append(TIME_INTERFACE, PROPERTY_ELAPSED);
591 auto reply = bus.call(method);
592 if (reply.is_method_error())
593 {
594 log<level::ERR>("Error getting time",
595 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800596 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000597 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800598 }
599 reply.read(value);
George Liu4d623e92020-05-25 16:51:57 +0800600 bmc_time_usec = std::get<uint64_t>(value);
Lei YUe8939392017-06-15 10:45:05 +0800601 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500602 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800603 {
604 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000605 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800606 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530607 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800608 {
609 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000610 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530611 }
612
George Liu4d623e92020-05-25 16:51:57 +0800613 bmcTime << "BMC time:"
614 << duration_cast<seconds>(microseconds(bmc_time_usec)).count();
615 log<level::DEBUG>(bmcTime.str().c_str());
Nagaraju Goruganti8960b7c2018-04-29 22:38:40 -0500616
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530617 // Time is really long int but IPMI wants just uint32. This works okay until
618 // the number of seconds since 1970 overflows uint32 size.. Still a whole
619 // lot of time here to even think about that.
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000620 return ipmi::responseSuccess(
George Liu4d623e92020-05-25 16:51:57 +0800621 duration_cast<seconds>(microseconds(bmc_time_usec)).count());
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500622}
623
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000624/** @brief implements the set SEL time command
625 * @param selDeviceTime - epoch time
626 * -local time as the number of seconds from 00:00:00, January 1, 1970
627 * @returns IPMI completion code
628 */
629ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime)
Chris Austenb4f5b922015-10-13 12:44:43 -0500630{
Lei YUe8939392017-06-15 10:45:05 +0800631 using namespace std::chrono;
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000632 microseconds usec{seconds(selDeviceTime)};
Norman James82330442015-11-19 16:53:26 -0600633
Lei YUe8939392017-06-15 10:45:05 +0800634 try
635 {
636 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800637 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Andrew Geissler6467ed22020-05-16 16:03:53 -0500638 std::variant<uint64_t> value{(uint64_t)usec.count()};
Lei YUe8939392017-06-15 10:45:05 +0800639
George Liu4d623e92020-05-25 16:51:57 +0800640 // Set bmc time
641 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700642 DBUS_PROPERTIES, "Set");
Lei YUe8939392017-06-15 10:45:05 +0800643
644 method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value);
645 auto reply = bus.call(method);
646 if (reply.is_method_error())
647 {
648 log<level::ERR>("Error setting time",
649 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800650 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000651 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800652 }
Norman James82330442015-11-19 16:53:26 -0600653 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500654 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800655 {
656 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000657 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530658 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530659 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800660 {
661 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000662 return ipmi::responseUnspecifiedError();
Norman James82330442015-11-19 16:53:26 -0600663 }
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530664
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000665 return ipmi::responseSuccess();
Chris Austenb4f5b922015-10-13 12:44:43 -0500666}
667
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000668/** @brief implements the reserve SEL command
669 * @returns IPMI completion code plus response data
670 * - SEL reservation ID.
671 */
672ipmi::RspType<uint16_t> ipmiStorageReserveSel()
Chris Austenb4f5b922015-10-13 12:44:43 -0500673{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000674 return ipmi::responseSuccess(reserveSel());
Chris Austenb4f5b922015-10-13 12:44:43 -0500675}
676
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000677/** @brief implements the Add SEL entry command
678 * @request
679 *
680 * - recordID ID used for SEL Record access
681 * - recordType Record Type
682 * - timeStamp Time when event was logged. LS byte first
683 * - generatorID software ID if event was generated from
684 * system software
685 * - evmRev event message format version
686 * - sensorType sensor type code for service that generated
687 * the event
688 * - sensorNumber number of sensors that generated the event
689 * - eventDir event dir
690 * - eventData event data field contents
691 *
692 * @returns ipmi completion code plus response data
693 * - RecordID of the Added SEL entry
694 */
695ipmi::RspType<uint16_t // recordID of the Added SEL entry
696 >
697 ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, uint32_t timeStamp,
698 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType,
699 uint8_t sensorNumber, uint8_t eventDir,
700 std::array<uint8_t, eventDataSize> eventData)
Chris Austenb4f5b922015-10-13 12:44:43 -0500701{
Jason M. Bills13e67c82018-09-10 14:12:16 -0700702 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
703 // added
704 cancelSELReservation();
Tom Josephb647d5b2017-10-31 17:25:33 +0530705 // Hostboot sends SEL with OEM record type 0xDE to indicate that there is
706 // a maintenance procedure associated with eSEL record.
707 static constexpr auto procedureType = 0xDE;
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000708 if (recordType == procedureType)
Tom Josephb647d5b2017-10-31 17:25:33 +0530709 {
710 // In the OEM record type 0xDE, byte 11 in the SEL record indicate the
711 // procedure number.
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000712 createProcedureLogEntry(sensorType);
Tom Josephb647d5b2017-10-31 17:25:33 +0530713 }
Chris Austenb4f5b922015-10-13 12:44:43 -0500714
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000715 return ipmi::responseSuccess(recordID);
Chris Austenb4f5b922015-10-13 12:44:43 -0500716}
717
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300718bool isFruPresent(const std::string& fruPath)
719{
720 using namespace ipmi::fru;
721
722 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
723
724 auto propValue =
725 ipmi::getDbusProperty(bus, invMgrInterface, invObjPath + fruPath,
726 invItemInterface, itemPresentProp);
727
728 return std::get<bool>(propValue);
729}
730
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000731/** @brief implements the get FRU Inventory Area Info command
732 *
733 * @returns IPMI completion code plus response data
734 * - FRU Inventory area size in bytes,
735 * - access bit
736 **/
737ipmi::RspType<uint16_t, // FRU Inventory area size in bytes,
738 uint8_t // access size (bytes / words)
739 >
740 ipmiStorageGetFruInvAreaInfo(uint8_t fruID)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500741{
Tom Joseph187f5642018-03-29 13:49:06 +0530742
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000743 auto iter = frus.find(fruID);
Tom Joseph187f5642018-03-29 13:49:06 +0530744 if (iter == frus.end())
745 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000746 return ipmi::responseSensorInvalid();
Tom Joseph187f5642018-03-29 13:49:06 +0530747 }
748
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300749 auto path = iter->second[0].path;
750 if (!isFruPresent(path))
751 {
752 return ipmi::responseSensorInvalid();
753 }
754
Marri Devender Raocac383b2017-07-03 13:24:27 -0500755 try
756 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000757 return ipmi::responseSuccess(
758 static_cast<uint16_t>(getFruAreaData(fruID).size()),
759 static_cast<uint8_t>(AccessMode::bytes));
Marri Devender Raocac383b2017-07-03 13:24:27 -0500760 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700761 catch (const InternalFailure& e)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500762 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500763 log<level::ERR>(e.what());
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000764 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500765 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500766}
767
anil kumar appana5b7c3262019-05-27 18:10:23 +0000768/**@brief implements the Read FRU Data command
769 * @param fruDeviceId - FRU device ID. FFh = reserved
770 * @param offset - FRU inventory offset to read
771 * @param readCount - count to read
772 *
773 * @return IPMI completion code plus response data
774 * - returnCount - response data count.
775 * - data - response data
776 */
777ipmi::RspType<uint8_t, // count returned
778 std::vector<uint8_t>> // FRU data
779 ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset,
780 uint8_t readCount)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500781{
anil kumar appana5b7c3262019-05-27 18:10:23 +0000782 if (fruDeviceId == 0xFF)
Tom Joseph187f5642018-03-29 13:49:06 +0530783 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000784 return ipmi::responseInvalidFieldRequest();
Tom Joseph187f5642018-03-29 13:49:06 +0530785 }
786
anil kumar appana5b7c3262019-05-27 18:10:23 +0000787 auto iter = frus.find(fruDeviceId);
788 if (iter == frus.end())
789 {
790 return ipmi::responseSensorInvalid();
791 }
792
Marri Devender Raocac383b2017-07-03 13:24:27 -0500793 try
794 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000795 const auto& fruArea = getFruAreaData(fruDeviceId);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500796 auto size = fruArea.size();
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500797
Tom Josephefcd68b2018-04-26 18:46:27 +0530798 if (offset >= size)
799 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000800 return ipmi::responseParmOutOfRange();
Tom Josephefcd68b2018-04-26 18:46:27 +0530801 }
802
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500803 // Write the count of response data.
anil kumar appana5b7c3262019-05-27 18:10:23 +0000804 uint8_t returnCount;
805 if ((offset + readCount) <= size)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500806 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000807 returnCount = readCount;
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500808 }
809 else
810 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000811 returnCount = size - offset;
Marri Devender Raocac383b2017-07-03 13:24:27 -0500812 }
Ratan Gupta2848d602018-01-31 20:39:20 +0530813
anil kumar appana5b7c3262019-05-27 18:10:23 +0000814 std::vector<uint8_t> fruData((fruArea.begin() + offset),
815 (fruArea.begin() + offset + returnCount));
Ratan Gupta2848d602018-01-31 20:39:20 +0530816
anil kumar appana5b7c3262019-05-27 18:10:23 +0000817 return ipmi::responseSuccess(returnCount, fruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500818 }
819 catch (const InternalFailure& e)
820 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500821 log<level::ERR>(e.what());
anil kumar appana5b7c3262019-05-27 18:10:23 +0000822 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500823 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500824}
825
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000826ipmi::RspType<uint8_t, // SDR version
827 uint16_t, // record count LS first
828 uint16_t, // free space in bytes, LS first
829 uint32_t, // addition timestamp LS first
830 uint32_t, // deletion timestamp LS first
831 uint8_t> // operation Support
832 ipmiGetRepositoryInfo()
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600833{
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600834
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000835 constexpr uint8_t sdrVersion = 0x51;
836 constexpr uint16_t freeSpace = 0xFFFF;
837 constexpr uint32_t additionTimestamp = 0x0;
838 constexpr uint32_t deletionTimestamp = 0x0;
839 constexpr uint8_t operationSupport = 0;
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600840
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700841 uint16_t records = frus.size() + ipmi::sensor::sensors.size();
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600842
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000843 return ipmi::responseSuccess(sdrVersion, records, freeSpace,
844 additionTimestamp, deletionTimestamp,
845 operationSupport);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600846}
Chris Austenb4f5b922015-10-13 12:44:43 -0500847
Chris Austenb4f5b922015-10-13 12:44:43 -0500848void register_netfn_storage_functions()
849{
Lei YU3df36612021-09-15 11:41:11 +0800850 selCacheMapInitialized = false;
Lei YUd9e57662021-09-14 18:06:28 +0800851 initSELCache();
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530852 // <Get SEL Info>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000853 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
854 ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
855 ipmiStorageGetSelInfo);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530856
Tom05732372016-09-06 17:21:23 +0530857 // <Get SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000858 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
859 ipmi::storage::cmdGetSelTime, ipmi::Privilege::User,
860 ipmiStorageGetSelTime);
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500861
Tom05732372016-09-06 17:21:23 +0530862 // <Set SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000863 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
864 ipmi::storage::cmdSetSelTime,
865 ipmi::Privilege::Operator, ipmiStorageSetSelTime);
Chris Austenb4f5b922015-10-13 12:44:43 -0500866
Tom05732372016-09-06 17:21:23 +0530867 // <Reserve SEL>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000868 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
869 ipmi::storage::cmdReserveSel, ipmi::Privilege::User,
870 ipmiStorageReserveSel);
Tom Josepha4953392017-06-30 19:09:47 +0530871 // <Get SEL Entry>
Patrick Venture0b02be92018-08-31 11:55:55 -0700872 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL,
873 getSELEntry, PRIVILEGE_USER);
Tom Josepha4953392017-06-30 19:09:47 +0530874
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530875 // <Delete SEL Entry>
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000876 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
877 ipmi::storage::cmdDeleteSelEntry,
878 ipmi::Privilege::Operator, deleteSELEntry);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530879
Tom05732372016-09-06 17:21:23 +0530880 // <Add SEL Entry>
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000881 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
882 ipmi::storage::cmdAddSelEntry,
883 ipmi::Privilege::Operator, ipmiStorageAddSEL);
884
Tom Joseph2f05bb52017-06-30 19:14:49 +0530885 // <Clear SEL>
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000886 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
887 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
888 clearSEL);
889
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500890 // <Get FRU Inventory Area Info>
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000891 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
892 ipmi::storage::cmdGetFruInventoryAreaInfo,
893 ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500894
Jason M. Billsb5248c92019-06-24 15:53:08 -0700895 // <READ FRU Data>
anil kumar appana5b7c3262019-05-27 18:10:23 +0000896 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
897 ipmi::storage::cmdReadFruData,
898 ipmi::Privilege::Operator, ipmiStorageReadFruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500899
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600900 // <Get Repository Info>
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000901 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
902 ipmi::storage::cmdGetSdrRepositoryInfo,
903 ipmi::Privilege::User, ipmiGetRepositoryInfo);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600904
Tom Joseph5ca50952018-02-22 00:33:38 +0530905 // <Reserve SDR Repository>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000906 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
907 ipmi::storage::cmdReserveSdrRepository,
908 ipmi::Privilege::User, ipmiSensorReserveSdr);
Tom Joseph5ca50952018-02-22 00:33:38 +0530909
910 // <Get SDR>
Patrick Venture0b02be92018-08-31 11:55:55 -0700911 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr,
912 ipmi_sen_get_sdr, PRIVILEGE_USER);
Tom Joseph5ca50952018-02-22 00:33:38 +0530913
Marri Devender Rao908f7502017-07-10 01:49:54 -0500914 ipmi::fru::registerCallbackHandler();
Chris Austenb4f5b922015-10-13 12:44:43 -0500915 return;
916}