blob: bd313148bf63b97acbc5eb22eb38bc83b912145c [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{
shamim ali071d00c2022-03-02 15:42:46 +053045constexpr auto SystemdTimeService = "org.freedesktop.timedate1";
46constexpr auto SystemdTimePath = "/org/freedesktop/timedate1";
47constexpr auto SystemdTimeInterface = "org.freedesktop.timedate1";
48
Lei YUe8939392017-06-15 10:45:05 +080049constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime";
George Liu4d623e92020-05-25 16:51:57 +080050constexpr auto BMC_TIME_PATH = "/xyz/openbmc_project/time/bmc";
Lei YUe8939392017-06-15 10:45:05 +080051constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties";
Patrick Venture0b02be92018-08-31 11:55:55 -070052constexpr auto PROPERTY_ELAPSED = "Elapsed";
Lei YUe8939392017-06-15 10:45:05 +080053
Lei YUd9555252021-09-14 20:30:41 +080054constexpr auto logWatchPath = "/xyz/openbmc_project/logging";
Lei YUd9e57662021-09-14 18:06:28 +080055constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
56constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
57constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
Patrick Venture0b02be92018-08-31 11:55:55 -070058} // namespace
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +053059
Tom Joseph6f7deaa2017-06-30 19:03:54 +053060using InternalFailure =
Patrick Venture0b02be92018-08-31 11:55:55 -070061 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Tom Joseph6f7deaa2017-06-30 19:03:54 +053062using namespace phosphor::logging;
Marri Devender Raocac383b2017-07-03 13:24:27 -050063using namespace ipmi::fru;
Lotus Xu57d35572021-01-24 11:13:13 +080064using namespace xyz::openbmc_project::Logging::SEL;
65using SELCreated =
66 sdbusplus::xyz::openbmc_project::Logging::SEL::Error::Created;
Marri Devender Raocac383b2017-07-03 13:24:27 -050067
Lei YUd9e57662021-09-14 18:06:28 +080068using SELRecordID = uint16_t;
69using SELEntry = ipmi::sel::SELEventRecordFormat;
70using SELCacheMap = std::map<SELRecordID, SELEntry>;
71
72SELCacheMap selCacheMap __attribute__((init_priority(101)));
Lei YU3df36612021-09-15 11:41:11 +080073bool selCacheMapInitialized;
Lei YUd9555252021-09-14 20:30:41 +080074std::unique_ptr<sdbusplus::bus::match::match> selAddedMatch
75 __attribute__((init_priority(101)));
Lei YUb6b72b02021-09-14 21:06:05 +080076std::unique_ptr<sdbusplus::bus::match::match> selRemovedMatch
77 __attribute__((init_priority(101)));
Lei YU4106e422021-09-15 10:55:51 +080078std::unique_ptr<sdbusplus::bus::match::match> selUpdatedMatch
79 __attribute__((init_priority(101)));
Lei YUd9e57662021-09-14 18:06:28 +080080
Lei YUb6b72b02021-09-14 21:06:05 +080081static inline uint16_t getLoggingId(const std::string& p)
Lei YUd9e57662021-09-14 18:06:28 +080082{
83 namespace fs = std::filesystem;
84 fs::path entryPath(p);
Lei YUb6b72b02021-09-14 21:06:05 +080085 return std::stoul(entryPath.filename().string());
86}
87
Lei YUeba8e9a2021-09-15 13:16:17 +080088static inline std::string getLoggingObjPath(uint16_t id)
89{
90 return std::string(ipmi::sel::logBasePath) + "/" + std::to_string(id);
91}
92
Lei YUa0bb2a32021-09-24 11:03:56 +080093std::optional<std::pair<uint16_t, SELEntry>>
94 parseLoggingEntry(const std::string& p)
Lei YUb6b72b02021-09-14 21:06:05 +080095{
Lei YU3df36612021-09-15 11:41:11 +080096 try
97 {
Lei YUa0bb2a32021-09-24 11:03:56 +080098 auto id = getLoggingId(p);
99 ipmi::sel::GetSELEntryResponse record{};
Lei YU3df36612021-09-15 11:41:11 +0800100 record = ipmi::sel::convertLogEntrytoSEL(p);
Lei YUa0bb2a32021-09-24 11:03:56 +0800101 return std::pair<uint16_t, SELEntry>({id, std::move(record.event)});
Lei YU3df36612021-09-15 11:41:11 +0800102 }
103 catch (const std::exception& e)
104 {
105 fprintf(stderr, "Failed to convert %s to SEL: %s\n", p.c_str(),
106 e.what());
107 }
Lei YUa0bb2a32021-09-24 11:03:56 +0800108 return std::nullopt;
Lei YUd9e57662021-09-14 18:06:28 +0800109}
110
Lei YUd9555252021-09-14 20:30:41 +0800111static void selAddedCallback(sdbusplus::message::message& m)
112{
113 sdbusplus::message::object_path objPath;
114 try
115 {
116 m.read(objPath);
117 }
118 catch (const sdbusplus::exception::exception& e)
119 {
120 log<level::ERR>("Failed to read object path");
121 return;
122 }
123 std::string p = objPath;
Lei YUa0bb2a32021-09-24 11:03:56 +0800124 auto entry = parseLoggingEntry(p);
125 if (entry)
126 {
127 selCacheMap.insert(std::move(*entry));
128 }
Lei YUd9555252021-09-14 20:30:41 +0800129}
130
Lei YUb6b72b02021-09-14 21:06:05 +0800131static void selRemovedCallback(sdbusplus::message::message& m)
132{
133 sdbusplus::message::object_path objPath;
134 try
135 {
136 m.read(objPath);
137 }
138 catch (const sdbusplus::exception::exception& e)
139 {
140 log<level::ERR>("Failed to read object path");
Lei YUb6b72b02021-09-14 21:06:05 +0800141 }
Lei YUa0bb2a32021-09-24 11:03:56 +0800142 try
143 {
144 std::string p = objPath;
145 selCacheMap.erase(getLoggingId(p));
146 }
147 catch (const std::invalid_argument& e)
148 {
149 log<level::ERR>("Invalid logging entry ID");
150 }
Lei YUb6b72b02021-09-14 21:06:05 +0800151}
152
Lei YU4106e422021-09-15 10:55:51 +0800153static void selUpdatedCallback(sdbusplus::message::message& m)
154{
155 std::string p = m.get_path();
156 auto entry = parseLoggingEntry(p);
Lei YUa0bb2a32021-09-24 11:03:56 +0800157 if (entry)
158 {
159 selCacheMap.insert_or_assign(entry->first, std::move(entry->second));
160 }
Lei YU4106e422021-09-15 10:55:51 +0800161}
162
Lei YUd9555252021-09-14 20:30:41 +0800163void registerSelCallbackHandler()
164{
165 using namespace sdbusplus::bus::match::rules;
166 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
167 if (!selAddedMatch)
168 {
169 selAddedMatch = std::make_unique<sdbusplus::bus::match::match>(
170 bus, interfacesAdded(logWatchPath),
171 std::bind(selAddedCallback, std::placeholders::_1));
172 }
Lei YUb6b72b02021-09-14 21:06:05 +0800173 if (!selRemovedMatch)
174 {
175 selRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
176 bus, interfacesRemoved(logWatchPath),
177 std::bind(selRemovedCallback, std::placeholders::_1));
178 }
Lei YU4106e422021-09-15 10:55:51 +0800179 if (!selUpdatedMatch)
180 {
181 selUpdatedMatch = std::make_unique<sdbusplus::bus::match::match>(
182 bus,
183 type::signal() + member("PropertiesChanged"s) +
184 interface("org.freedesktop.DBus.Properties"s) +
185 argN(0, logEntryIntf),
186 std::bind(selUpdatedCallback, std::placeholders::_1));
187 }
Lei YUd9555252021-09-14 20:30:41 +0800188}
189
Lei YUd9e57662021-09-14 18:06:28 +0800190void initSELCache()
191{
Lei YUc10cda12022-01-06 16:01:57 +0800192 registerSelCallbackHandler();
Lei YUeba8e9a2021-09-15 13:16:17 +0800193 ipmi::sel::ObjectPaths paths;
Lei YUd9e57662021-09-14 18:06:28 +0800194 try
195 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800196 ipmi::sel::readLoggingObjectPaths(paths);
Lei YUd9e57662021-09-14 18:06:28 +0800197 }
198 catch (const sdbusplus::exception::exception& e)
199 {
200 log<level::ERR>("Failed to get logging object paths");
201 return;
202 }
Lei YUeba8e9a2021-09-15 13:16:17 +0800203 for (const auto& p : paths)
Lei YUd9e57662021-09-14 18:06:28 +0800204 {
Lei YUa0bb2a32021-09-24 11:03:56 +0800205 auto entry = parseLoggingEntry(p);
206 if (entry)
207 {
208 selCacheMap.insert(std::move(*entry));
209 }
Lei YUd9e57662021-09-14 18:06:28 +0800210 }
Lei YU3df36612021-09-15 11:41:11 +0800211 selCacheMapInitialized = true;
Lei YUd9e57662021-09-14 18:06:28 +0800212}
213
Marri Devender Raocac383b2017-07-03 13:24:27 -0500214/**
215 * @enum Device access mode
216 */
217enum class AccessMode
218{
219 bytes, ///< Device is accessed by bytes
220 words ///< Device is accessed by words
221};
222
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000223/** @brief implements the get SEL Info command
224 * @returns IPMI completion code plus response data
225 * - selVersion - SEL revision
226 * - entries - Number of log entries in SEL.
227 * - freeSpace - Free Space in bytes.
228 * - addTimeStamp - Most recent addition timestamp
229 * - eraseTimeStamp - Most recent erase timestamp
230 * - operationSupport - Reserve & Delete SEL operations supported
231 */
232
233ipmi::RspType<uint8_t, // SEL revision.
234 uint16_t, // number of log entries in SEL.
235 uint16_t, // free Space in bytes.
236 uint32_t, // most recent addition timestamp
237 uint32_t, // most recent erase timestamp.
238
239 bool, // SEL allocation info supported
240 bool, // reserve SEL supported
241 bool, // partial Add SEL Entry supported
242 bool, // delete SEL supported
243 uint3_t, // reserved
244 bool // overflow flag
245 >
246 ipmiStorageGetSelInfo()
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530247{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000248 uint16_t entries = 0;
249 // Most recent addition timestamp.
250 uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp;
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530251
Lei YUeba8e9a2021-09-15 13:16:17 +0800252 if (!selCacheMapInitialized)
Tom Josephe59abfb2018-08-06 18:46:27 +0530253 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800254 // In case the initSELCache() fails, try it again
255 initSELCache();
Tom Josephe59abfb2018-08-06 18:46:27 +0530256 }
Lei YUeba8e9a2021-09-15 13:16:17 +0800257 if (!selCacheMap.empty())
Tom Josephe59abfb2018-08-06 18:46:27 +0530258 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800259 entries = static_cast<uint16_t>(selCacheMap.size());
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530260
261 try
262 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800263 auto objPath = getLoggingObjPath(selCacheMap.rbegin()->first);
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000264 addTimeStamp = static_cast<uint32_t>(
Lei YUeba8e9a2021-09-15 13:16:17 +0800265 (ipmi::sel::getEntryTimeStamp(objPath).count()));
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530266 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500267 catch (const InternalFailure& e)
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530268 {
269 }
270 catch (const std::runtime_error& e)
271 {
272 log<level::ERR>(e.what());
273 }
274 }
275
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000276 constexpr uint8_t selVersion = ipmi::sel::selVersion;
277 constexpr uint16_t freeSpace = 0xFFFF;
278 constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp;
279 constexpr uint3_t reserved{0};
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530280
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000281 return ipmi::responseSuccess(
282 selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp,
283 ipmi::sel::operationSupport::getSelAllocationInfo,
284 ipmi::sel::operationSupport::reserveSel,
285 ipmi::sel::operationSupport::partialAddSelEntry,
286 ipmi::sel::operationSupport::deleteSel, reserved,
287 ipmi::sel::operationSupport::overflow);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530288}
289
Tom Josepha4953392017-06-30 19:09:47 +0530290ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
291 ipmi_request_t request, ipmi_response_t response,
292 ipmi_data_len_t data_len, ipmi_context_t context)
293{
Jason M. Bills851acb12019-02-04 14:06:57 -0800294 if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest))
295 {
296 *data_len = 0;
297 return IPMI_CC_REQ_DATA_LEN_INVALID;
298 }
299
Patrick Venture0b02be92018-08-31 11:55:55 -0700300 auto requestData =
301 reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request);
Tom Josepha4953392017-06-30 19:09:47 +0530302
303 if (requestData->reservationID != 0)
304 {
Jason M. Bills13e67c82018-09-10 14:12:16 -0700305 if (!checkSELReservation(requestData->reservationID))
Tom Josepha4953392017-06-30 19:09:47 +0530306 {
307 *data_len = 0;
308 return IPMI_CC_INVALID_RESERVATION_ID;
309 }
310 }
311
Lei YU3df36612021-09-15 11:41:11 +0800312 if (!selCacheMapInitialized)
313 {
314 // In case the initSELCache() fails, try it again
315 initSELCache();
316 }
317
318 if (selCacheMap.empty())
Tom Josepha4953392017-06-30 19:09:47 +0530319 {
320 *data_len = 0;
321 return IPMI_CC_SENSOR_INVALID;
322 }
323
Lei YU3df36612021-09-15 11:41:11 +0800324 SELCacheMap::const_iterator iter;
Tom Josepha4953392017-06-30 19:09:47 +0530325
326 // Check for the requested SEL Entry.
327 if (requestData->selRecordID == ipmi::sel::firstEntry)
328 {
Lei YU3df36612021-09-15 11:41:11 +0800329 iter = selCacheMap.begin();
Tom Josepha4953392017-06-30 19:09:47 +0530330 }
331 else if (requestData->selRecordID == ipmi::sel::lastEntry)
332 {
Lei YU3df36612021-09-15 11:41:11 +0800333 if (selCacheMap.size() > 1)
334 {
335 iter = selCacheMap.end();
336 --iter;
337 }
338 else
339 {
340 // Only one entry exists, return the first
341 iter = selCacheMap.begin();
342 }
Tom Josepha4953392017-06-30 19:09:47 +0530343 }
344 else
345 {
Lei YU3df36612021-09-15 11:41:11 +0800346 iter = selCacheMap.find(requestData->selRecordID);
347 if (iter == selCacheMap.end())
Tom Josepha4953392017-06-30 19:09:47 +0530348 {
349 *data_len = 0;
350 return IPMI_CC_SENSOR_INVALID;
351 }
352 }
353
Lei YU3df36612021-09-15 11:41:11 +0800354 ipmi::sel::GetSELEntryResponse record{0, iter->second};
Tom Josepha4953392017-06-30 19:09:47 +0530355 // Identify the next SEL record ID
Lei YU3df36612021-09-15 11:41:11 +0800356 ++iter;
357 if (iter == selCacheMap.end())
Tom Josepha4953392017-06-30 19:09:47 +0530358 {
Lei YU3df36612021-09-15 11:41:11 +0800359 record.nextRecordID = ipmi::sel::lastEntry;
Tom Josepha4953392017-06-30 19:09:47 +0530360 }
361 else
362 {
Lei YU3df36612021-09-15 11:41:11 +0800363 record.nextRecordID = iter->first;
Tom Josepha4953392017-06-30 19:09:47 +0530364 }
365
366 if (requestData->readLength == ipmi::sel::entireRecord)
367 {
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700368 std::memcpy(response, &record, sizeof(record));
Tom Josepha4953392017-06-30 19:09:47 +0530369 *data_len = sizeof(record);
370 }
371 else
372 {
373 if (requestData->offset >= ipmi::sel::selRecordSize ||
374 requestData->readLength > ipmi::sel::selRecordSize)
375 {
376 *data_len = 0;
377 return IPMI_CC_INVALID_FIELD_REQUEST;
378 }
379
380 auto diff = ipmi::sel::selRecordSize - requestData->offset;
Patrick Venture0b02be92018-08-31 11:55:55 -0700381 auto readLength =
382 std::min(diff, static_cast<int>(requestData->readLength));
Tom Josepha4953392017-06-30 19:09:47 +0530383
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700384 std::memcpy(response, &record.nextRecordID,
385 sizeof(record.nextRecordID));
386 std::memcpy(static_cast<uint8_t*>(response) +
387 sizeof(record.nextRecordID),
Lei YUaf378fa2020-12-02 16:28:57 +0800388 &record.event.eventRecord.recordID + requestData->offset,
389 readLength);
Tom Josepha4953392017-06-30 19:09:47 +0530390 *data_len = sizeof(record.nextRecordID) + readLength;
391 }
392
393 return IPMI_CC_OK;
394}
395
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000396/** @brief implements the delete SEL entry command
397 * @request
398 * - reservationID; // reservation ID.
399 * - selRecordID; // SEL record ID.
400 *
401 * @returns ipmi completion code plus response data
402 * - Record ID of the deleted record
403 */
404ipmi::RspType<uint16_t // deleted record ID
405 >
406 deleteSELEntry(uint16_t reservationID, uint16_t selRecordID)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530407{
Jason M. Bills851acb12019-02-04 14:06:57 -0800408
Brad Bishop1a4117b2018-11-21 15:48:18 -0500409 namespace fs = std::filesystem;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530410
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000411 if (!checkSELReservation(reservationID))
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530412 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000413 return ipmi::responseInvalidReservationId();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530414 }
415
Jason M. Bills13e67c82018-09-10 14:12:16 -0700416 // Per the IPMI spec, need to cancel the reservation when a SEL entry is
417 // deleted
418 cancelSELReservation();
419
Lei YUeba8e9a2021-09-15 13:16:17 +0800420 if (!selCacheMapInitialized)
Tom Josephe59abfb2018-08-06 18:46:27 +0530421 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800422 // In case the initSELCache() fails, try it again
423 initSELCache();
Tom Josephe59abfb2018-08-06 18:46:27 +0530424 }
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530425
Lei YUeba8e9a2021-09-15 13:16:17 +0800426 if (selCacheMap.empty())
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530427 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000428 return ipmi::responseSensorInvalid();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530429 }
430
Lei YUeba8e9a2021-09-15 13:16:17 +0800431 SELCacheMap::const_iterator iter;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530432 uint16_t delRecordID = 0;
433
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000434 if (selRecordID == ipmi::sel::firstEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530435 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800436 delRecordID = selCacheMap.begin()->first;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530437 }
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000438 else if (selRecordID == ipmi::sel::lastEntry)
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530439 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800440 delRecordID = selCacheMap.rbegin()->first;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530441 }
442 else
443 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000444 delRecordID = selRecordID;
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530445 }
446
Jian7d5f4812022-02-23 19:30:27 +0800447 iter = selCacheMap.find(delRecordID);
448 if (iter == selCacheMap.end())
449 {
450 return ipmi::responseSensorInvalid();
451 }
452
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530453 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
454 std::string service;
455
Lei YUeba8e9a2021-09-15 13:16:17 +0800456 auto objPath = getLoggingObjPath(iter->first);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530457 try
458 {
Lei YUeba8e9a2021-09-15 13:16:17 +0800459 service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, objPath);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530460 }
461 catch (const std::runtime_error& e)
462 {
463 log<level::ERR>(e.what());
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000464 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530465 }
466
Lei YUeba8e9a2021-09-15 13:16:17 +0800467 auto methodCall = bus.new_method_call(service.c_str(), objPath.c_str(),
Patrick Venture0b02be92018-08-31 11:55:55 -0700468 ipmi::sel::logDeleteIntf, "Delete");
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530469 auto reply = bus.call(methodCall);
470 if (reply.is_method_error())
471 {
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000472 return ipmi::responseUnspecifiedError();
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530473 }
474
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000475 return ipmi::responseSuccess(delRecordID);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530476}
477
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000478/** @brief implements the Clear SEL command
479 * @request
480 * - reservationID // Reservation ID.
481 * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) }
482 * - eraseOperation; // requested operation.
483 *
484 * @returns ipmi completion code plus response data
485 * - erase status
486 */
487
488ipmi::RspType<uint8_t // erase status
489 >
490 clearSEL(uint16_t reservationID, const std::array<char, 3>& clr,
491 uint8_t eraseOperation)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530492{
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000493 static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'};
494 if (clr != clrOk)
Jason M. Bills851acb12019-02-04 14:06:57 -0800495 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000496 return ipmi::responseInvalidFieldRequest();
Jason M. Bills851acb12019-02-04 14:06:57 -0800497 }
498
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000499 if (!checkSELReservation(reservationID))
Tom Joseph2f05bb52017-06-30 19:14:49 +0530500 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000501 return ipmi::responseInvalidReservationId();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530502 }
503
Tom Joseph2f05bb52017-06-30 19:14:49 +0530504 /*
505 * Erasure status cannot be fetched from DBUS, so always return erasure
506 * status as `erase completed`.
507 */
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000508 if (eraseOperation == ipmi::sel::getEraseStatus)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530509 {
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000510 return ipmi::responseSuccess(
511 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530512 }
513
Jason M. Bills13e67c82018-09-10 14:12:16 -0700514 // Per the IPMI spec, need to cancel any reservation when the SEL is cleared
515 cancelSELReservation();
516
Tom Joseph2f05bb52017-06-30 19:14:49 +0530517 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Lotus Xu78fe1b12021-05-23 17:26:56 +0800518 auto service = ipmi::getService(bus, ipmi::sel::logIntf, ipmi::sel::logObj);
519 auto method =
520 bus.new_method_call(service.c_str(), ipmi::sel::logObj,
521 ipmi::sel::logIntf, ipmi::sel::logDeleteAllMethod);
Tom Josephe59abfb2018-08-06 18:46:27 +0530522 try
Tom Joseph2f05bb52017-06-30 19:14:49 +0530523 {
Lotus Xu78fe1b12021-05-23 17:26:56 +0800524 bus.call_noreply(method);
Tom Josephe59abfb2018-08-06 18:46:27 +0530525 }
Patrick Williamsef1259b2021-09-02 09:12:33 -0500526 catch (const sdbusplus::exception::exception& e)
Tom Joseph2f05bb52017-06-30 19:14:49 +0530527 {
Lotus Xu78fe1b12021-05-23 17:26:56 +0800528 log<level::ERR>("Error eraseAll ", entry("ERROR=%s", e.what()));
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000529 return ipmi::responseUnspecifiedError();
Tom Joseph2f05bb52017-06-30 19:14:49 +0530530 }
531
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000532 return ipmi::responseSuccess(
533 static_cast<uint8_t>(ipmi::sel::eraseComplete));
Tom Joseph2f05bb52017-06-30 19:14:49 +0530534}
535
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000536/** @brief implements the get SEL time command
537 * @returns IPMI completion code plus response data
538 * -current time
539 */
540ipmi::RspType<uint32_t> // current time
541 ipmiStorageGetSelTime()
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500542{
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530543 using namespace std::chrono;
George Liu4d623e92020-05-25 16:51:57 +0800544 uint64_t bmc_time_usec = 0;
545 std::stringstream bmcTime;
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500546
Lei YUe8939392017-06-15 10:45:05 +0800547 try
548 {
549 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
George Liu4d623e92020-05-25 16:51:57 +0800550 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Vernon Mauery16b86932019-05-01 08:36:11 -0700551 std::variant<uint64_t> value;
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530552
George Liu4d623e92020-05-25 16:51:57 +0800553 // Get bmc time
554 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700555 DBUS_PROPERTIES, "Get");
Lei YUe8939392017-06-15 10:45:05 +0800556
557 method.append(TIME_INTERFACE, PROPERTY_ELAPSED);
558 auto reply = bus.call(method);
559 if (reply.is_method_error())
560 {
561 log<level::ERR>("Error getting time",
562 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800563 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000564 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800565 }
566 reply.read(value);
George Liu4d623e92020-05-25 16:51:57 +0800567 bmc_time_usec = std::get<uint64_t>(value);
Lei YUe8939392017-06-15 10:45:05 +0800568 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500569 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800570 {
571 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000572 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800573 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530574 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800575 {
576 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000577 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530578 }
579
George Liu4d623e92020-05-25 16:51:57 +0800580 bmcTime << "BMC time:"
581 << duration_cast<seconds>(microseconds(bmc_time_usec)).count();
582 log<level::DEBUG>(bmcTime.str().c_str());
Nagaraju Goruganti8960b7c2018-04-29 22:38:40 -0500583
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530584 // Time is really long int but IPMI wants just uint32. This works okay until
585 // the number of seconds since 1970 overflows uint32 size.. Still a whole
586 // lot of time here to even think about that.
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000587 return ipmi::responseSuccess(
George Liu4d623e92020-05-25 16:51:57 +0800588 duration_cast<seconds>(microseconds(bmc_time_usec)).count());
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500589}
590
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000591/** @brief implements the set SEL time command
592 * @param selDeviceTime - epoch time
593 * -local time as the number of seconds from 00:00:00, January 1, 1970
594 * @returns IPMI completion code
595 */
596ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime)
Chris Austenb4f5b922015-10-13 12:44:43 -0500597{
Lei YUe8939392017-06-15 10:45:05 +0800598 using namespace std::chrono;
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000599 microseconds usec{seconds(selDeviceTime)};
Norman James82330442015-11-19 16:53:26 -0600600
Lei YUe8939392017-06-15 10:45:05 +0800601 try
602 {
603 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
shamim ali071d00c2022-03-02 15:42:46 +0530604 bool ntp = std::get<bool>(
605 ipmi::getDbusProperty(bus, SystemdTimeService, SystemdTimePath,
606 SystemdTimeInterface, "NTP"));
607 if (ntp)
608 {
609 return ipmi::responseCommandNotAvailable();
610 }
611
George Liu4d623e92020-05-25 16:51:57 +0800612 auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH);
Andrew Geissler6467ed22020-05-16 16:03:53 -0500613 std::variant<uint64_t> value{(uint64_t)usec.count()};
Lei YUe8939392017-06-15 10:45:05 +0800614
George Liu4d623e92020-05-25 16:51:57 +0800615 // Set bmc time
616 auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH,
Patrick Venture0b02be92018-08-31 11:55:55 -0700617 DBUS_PROPERTIES, "Set");
Lei YUe8939392017-06-15 10:45:05 +0800618
619 method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value);
620 auto reply = bus.call(method);
621 if (reply.is_method_error())
622 {
623 log<level::ERR>("Error setting time",
624 entry("SERVICE=%s", service.c_str()),
George Liu4d623e92020-05-25 16:51:57 +0800625 entry("PATH=%s", BMC_TIME_PATH));
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000626 return ipmi::responseUnspecifiedError();
Lei YUe8939392017-06-15 10:45:05 +0800627 }
Norman James82330442015-11-19 16:53:26 -0600628 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500629 catch (const InternalFailure& e)
Lei YUe8939392017-06-15 10:45:05 +0800630 {
631 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000632 return ipmi::responseUnspecifiedError();
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530633 }
Tom Joseph30fd0a12019-09-24 06:53:22 +0530634 catch (const std::exception& e)
Lei YUe8939392017-06-15 10:45:05 +0800635 {
636 log<level::ERR>(e.what());
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000637 return ipmi::responseUnspecifiedError();
Norman James82330442015-11-19 16:53:26 -0600638 }
Vishwanatha Subbanna5fba7a62016-09-01 14:06:07 +0530639
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000640 return ipmi::responseSuccess();
Chris Austenb4f5b922015-10-13 12:44:43 -0500641}
642
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000643/** @brief implements the reserve SEL command
644 * @returns IPMI completion code plus response data
645 * - SEL reservation ID.
646 */
647ipmi::RspType<uint16_t> ipmiStorageReserveSel()
Chris Austenb4f5b922015-10-13 12:44:43 -0500648{
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000649 return ipmi::responseSuccess(reserveSel());
Chris Austenb4f5b922015-10-13 12:44:43 -0500650}
651
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000652/** @brief implements the Add SEL entry command
653 * @request
654 *
655 * - recordID ID used for SEL Record access
656 * - recordType Record Type
657 * - timeStamp Time when event was logged. LS byte first
658 * - generatorID software ID if event was generated from
659 * system software
660 * - evmRev event message format version
661 * - sensorType sensor type code for service that generated
662 * the event
663 * - sensorNumber number of sensors that generated the event
664 * - eventDir event dir
665 * - eventData event data field contents
666 *
667 * @returns ipmi completion code plus response data
668 * - RecordID of the Added SEL entry
669 */
670ipmi::RspType<uint16_t // recordID of the Added SEL entry
671 >
672 ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, uint32_t timeStamp,
673 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType,
674 uint8_t sensorNumber, uint8_t eventDir,
675 std::array<uint8_t, eventDataSize> eventData)
Chris Austenb4f5b922015-10-13 12:44:43 -0500676{
Lotus Xu57d35572021-01-24 11:13:13 +0800677 std::string objpath;
678 static constexpr auto systemRecordType = 0x02;
Tom Josephb647d5b2017-10-31 17:25:33 +0530679 // Hostboot sends SEL with OEM record type 0xDE to indicate that there is
680 // a maintenance procedure associated with eSEL record.
681 static constexpr auto procedureType = 0xDE;
Lotus Xu57d35572021-01-24 11:13:13 +0800682 cancelSELReservation();
683 if (recordType == systemRecordType)
684 {
685
686 for (const auto& it : invSensors)
687 {
688 if (it.second.sensorID == sensorNumber)
689 {
690 objpath = it.first;
691 break;
692 }
693 }
694 auto selDataStr = ipmi::sel::toHexStr(eventData);
695
696 bool assert = (eventDir & 0x80) ? false : true;
697
698 recordID = report<SELCreated>(Created::RECORD_TYPE(recordType),
699 Created::GENERATOR_ID(generatorID),
700 Created::SENSOR_DATA(selDataStr.c_str()),
701 Created::EVENT_DIR(assert),
702 Created::SENSOR_PATH(objpath.c_str()));
703 }
704 else if (recordType == procedureType)
Tom Josephb647d5b2017-10-31 17:25:33 +0530705 {
706 // In the OEM record type 0xDE, byte 11 in the SEL record indicate the
707 // procedure number.
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000708 createProcedureLogEntry(sensorType);
Tom Josephb647d5b2017-10-31 17:25:33 +0530709 }
Chris Austenb4f5b922015-10-13 12:44:43 -0500710
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000711 return ipmi::responseSuccess(recordID);
Chris Austenb4f5b922015-10-13 12:44:43 -0500712}
713
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300714bool isFruPresent(ipmi::Context::ptr& ctx, const std::string& fruPath)
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300715{
716 using namespace ipmi::fru;
717
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300718 std::string service;
719 boost::system::error_code ec =
720 getService(ctx, invItemInterface, invObjPath + fruPath, service);
721 if (!ec)
722 {
723 bool result;
724 ec = ipmi::getDbusProperty(ctx, service, invObjPath + fruPath,
725 invItemInterface, itemPresentProp, result);
726 if (!ec)
727 {
728 return result;
729 }
730 }
Konstantin Aladyshevc7e4b042021-12-24 15:30:47 +0300731
732 ipmi::ObjectValueTree managedObjects;
733 ec = getManagedObjects(ctx, "xyz.openbmc_project.EntityManager", "/",
734 managedObjects);
735 if (!ec)
736 {
737 auto connection = managedObjects.find(fruPath);
738 if (connection != managedObjects.end())
739 {
740 return true;
741 }
742 }
743
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300744 return false;
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300745}
746
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000747/** @brief implements the get FRU Inventory Area Info command
748 *
749 * @returns IPMI completion code plus response data
750 * - FRU Inventory area size in bytes,
751 * - access bit
752 **/
753ipmi::RspType<uint16_t, // FRU Inventory area size in bytes,
754 uint8_t // access size (bytes / words)
755 >
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300756 ipmiStorageGetFruInvAreaInfo(ipmi::Context::ptr ctx, uint8_t fruID)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500757{
Tom Joseph187f5642018-03-29 13:49:06 +0530758
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000759 auto iter = frus.find(fruID);
Tom Joseph187f5642018-03-29 13:49:06 +0530760 if (iter == frus.end())
761 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000762 return ipmi::responseSensorInvalid();
Tom Joseph187f5642018-03-29 13:49:06 +0530763 }
764
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300765 auto path = iter->second[0].path;
Konstantin Aladyshev69e3cd42021-11-26 16:46:17 +0300766 if (!isFruPresent(ctx, path))
Kirill Pakhomovfa6e2092020-04-24 18:57:15 +0300767 {
768 return ipmi::responseSensorInvalid();
769 }
770
Marri Devender Raocac383b2017-07-03 13:24:27 -0500771 try
772 {
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000773 return ipmi::responseSuccess(
774 static_cast<uint16_t>(getFruAreaData(fruID).size()),
775 static_cast<uint8_t>(AccessMode::bytes));
Marri Devender Raocac383b2017-07-03 13:24:27 -0500776 }
Patrick Venture0b02be92018-08-31 11:55:55 -0700777 catch (const InternalFailure& e)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500778 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500779 log<level::ERR>(e.what());
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000780 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500781 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500782}
783
anil kumar appana5b7c3262019-05-27 18:10:23 +0000784/**@brief implements the Read FRU Data command
785 * @param fruDeviceId - FRU device ID. FFh = reserved
786 * @param offset - FRU inventory offset to read
787 * @param readCount - count to read
788 *
789 * @return IPMI completion code plus response data
790 * - returnCount - response data count.
791 * - data - response data
792 */
793ipmi::RspType<uint8_t, // count returned
794 std::vector<uint8_t>> // FRU data
795 ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset,
796 uint8_t readCount)
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500797{
anil kumar appana5b7c3262019-05-27 18:10:23 +0000798 if (fruDeviceId == 0xFF)
Tom Joseph187f5642018-03-29 13:49:06 +0530799 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000800 return ipmi::responseInvalidFieldRequest();
Tom Joseph187f5642018-03-29 13:49:06 +0530801 }
802
anil kumar appana5b7c3262019-05-27 18:10:23 +0000803 auto iter = frus.find(fruDeviceId);
804 if (iter == frus.end())
805 {
806 return ipmi::responseSensorInvalid();
807 }
808
Marri Devender Raocac383b2017-07-03 13:24:27 -0500809 try
810 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000811 const auto& fruArea = getFruAreaData(fruDeviceId);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500812 auto size = fruArea.size();
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500813
Tom Josephefcd68b2018-04-26 18:46:27 +0530814 if (offset >= size)
815 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000816 return ipmi::responseParmOutOfRange();
Tom Josephefcd68b2018-04-26 18:46:27 +0530817 }
818
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500819 // Write the count of response data.
anil kumar appana5b7c3262019-05-27 18:10:23 +0000820 uint8_t returnCount;
821 if ((offset + readCount) <= size)
Marri Devender Raocac383b2017-07-03 13:24:27 -0500822 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000823 returnCount = readCount;
Nagaraju Goruganti7f2d7c92018-03-21 11:18:30 -0500824 }
825 else
826 {
anil kumar appana5b7c3262019-05-27 18:10:23 +0000827 returnCount = size - offset;
Marri Devender Raocac383b2017-07-03 13:24:27 -0500828 }
Ratan Gupta2848d602018-01-31 20:39:20 +0530829
anil kumar appana5b7c3262019-05-27 18:10:23 +0000830 std::vector<uint8_t> fruData((fruArea.begin() + offset),
831 (fruArea.begin() + offset + returnCount));
Ratan Gupta2848d602018-01-31 20:39:20 +0530832
anil kumar appana5b7c3262019-05-27 18:10:23 +0000833 return ipmi::responseSuccess(returnCount, fruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500834 }
835 catch (const InternalFailure& e)
836 {
Marri Devender Raocac383b2017-07-03 13:24:27 -0500837 log<level::ERR>(e.what());
anil kumar appana5b7c3262019-05-27 18:10:23 +0000838 return ipmi::responseUnspecifiedError();
Marri Devender Raocac383b2017-07-03 13:24:27 -0500839 }
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500840}
841
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000842ipmi::RspType<uint8_t, // SDR version
843 uint16_t, // record count LS first
844 uint16_t, // free space in bytes, LS first
845 uint32_t, // addition timestamp LS first
846 uint32_t, // deletion timestamp LS first
847 uint8_t> // operation Support
848 ipmiGetRepositoryInfo()
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600849{
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600850
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000851 constexpr uint8_t sdrVersion = 0x51;
852 constexpr uint16_t freeSpace = 0xFFFF;
853 constexpr uint32_t additionTimestamp = 0x0;
854 constexpr uint32_t deletionTimestamp = 0x0;
855 constexpr uint8_t operationSupport = 0;
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600856
Patrick Venturedb0cbe62019-09-09 14:47:22 -0700857 uint16_t records = frus.size() + ipmi::sensor::sensors.size();
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600858
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000859 return ipmi::responseSuccess(sdrVersion, records, freeSpace,
860 additionTimestamp, deletionTimestamp,
861 operationSupport);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600862}
Chris Austenb4f5b922015-10-13 12:44:43 -0500863
Chris Austenb4f5b922015-10-13 12:44:43 -0500864void register_netfn_storage_functions()
865{
Lei YU3df36612021-09-15 11:41:11 +0800866 selCacheMapInitialized = false;
Lei YUd9e57662021-09-14 18:06:28 +0800867 initSELCache();
Willy Tud351a722021-08-12 14:33:40 -0700868 // Handlers with dbus-sdr handler implementation.
869 // Do not register the hander if it dynamic sensors stack is used.
870
871#ifndef FEATURE_DYNAMIC_SENSORS
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530872 // <Get SEL Info>
jayaprakash Mutyalab7557722019-05-02 21:13:30 +0000873 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
874 ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
875 ipmiStorageGetSelInfo);
Tom Joseph6f7deaa2017-06-30 19:03:54 +0530876
Tom05732372016-09-06 17:21:23 +0530877 // <Get SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000878 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
879 ipmi::storage::cmdGetSelTime, ipmi::Privilege::User,
880 ipmiStorageGetSelTime);
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500881
Tom05732372016-09-06 17:21:23 +0530882 // <Set SEL Time>
jayaprakash Mutyaladb2e8c42019-05-03 01:38:01 +0000883 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
884 ipmi::storage::cmdSetSelTime,
885 ipmi::Privilege::Operator, ipmiStorageSetSelTime);
Chris Austenb4f5b922015-10-13 12:44:43 -0500886
Tom Josepha4953392017-06-30 19:09:47 +0530887 // <Get SEL Entry>
Patrick Venture0b02be92018-08-31 11:55:55 -0700888 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL,
889 getSELEntry, PRIVILEGE_USER);
Tom Josepha4953392017-06-30 19:09:47 +0530890
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530891 // <Delete SEL Entry>
Pradeep Kumar00a18d02019-04-26 17:04:28 +0000892 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
893 ipmi::storage::cmdDeleteSelEntry,
894 ipmi::Privilege::Operator, deleteSELEntry);
Tom Joseph8f4a2aa2017-06-30 19:12:49 +0530895
Tom05732372016-09-06 17:21:23 +0530896 // <Add SEL Entry>
anil kumar appana2c7db1d2019-05-28 11:20:19 +0000897 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
898 ipmi::storage::cmdAddSelEntry,
899 ipmi::Privilege::Operator, ipmiStorageAddSEL);
900
Tom Joseph2f05bb52017-06-30 19:14:49 +0530901 // <Clear SEL>
Pradeep Kumar4a5a99a2019-04-26 15:22:39 +0000902 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
903 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
904 clearSEL);
905
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500906 // <Get FRU Inventory Area Info>
Pradeep Kumarb0c794d2019-05-02 13:09:14 +0000907 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
908 ipmi::storage::cmdGetFruInventoryAreaInfo,
909 ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
Marri Devender Raofa7b4e22017-07-03 00:52:20 -0500910
Jason M. Billsb5248c92019-06-24 15:53:08 -0700911 // <READ FRU Data>
anil kumar appana5b7c3262019-05-27 18:10:23 +0000912 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
913 ipmi::storage::cmdReadFruData,
914 ipmi::Privilege::Operator, ipmiStorageReadFruData);
Marri Devender Raocac383b2017-07-03 13:24:27 -0500915
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600916 // <Get Repository Info>
Pradeep Kumarb60e8402019-05-06 15:17:01 +0000917 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
918 ipmi::storage::cmdGetSdrRepositoryInfo,
919 ipmi::Privilege::User, ipmiGetRepositoryInfo);
Dhruvaraj Subhashchandrane66c3b02018-02-07 01:21:56 -0600920
Tom Joseph5ca50952018-02-22 00:33:38 +0530921 // <Reserve SDR Repository>
jayaprakash Mutyalad9578232019-05-13 20:22:50 +0000922 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
923 ipmi::storage::cmdReserveSdrRepository,
924 ipmi::Privilege::User, ipmiSensorReserveSdr);
Tom Joseph5ca50952018-02-22 00:33:38 +0530925
926 // <Get SDR>
Patrick Venture0b02be92018-08-31 11:55:55 -0700927 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr,
928 ipmi_sen_get_sdr, PRIVILEGE_USER);
Tom Joseph5ca50952018-02-22 00:33:38 +0530929
Willy Tud351a722021-08-12 14:33:40 -0700930#endif
931
932 // Common Handers used by both implementation.
933
934 // <Reserve SEL>
935 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
936 ipmi::storage::cmdReserveSel, ipmi::Privilege::User,
937 ipmiStorageReserveSel);
938
Marri Devender Rao908f7502017-07-10 01:49:54 -0500939 ipmi::fru::registerCallbackHandler();
Chris Austenb4f5b922015-10-13 12:44:43 -0500940 return;
941}