blob: a67fe4195f3440285f457e9e42388572174be46f [file] [log] [blame]
Jason M. Bills3f7c5e42018-10-03 14:00:41 -07001/*
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07002// Copyright (c) 2017-2019 Intel Corporation
Jason M. Bills3f7c5e42018-10-03 14:00:41 -07003//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
Patrick Ventureca99ef52019-10-20 14:00:50 -070017#include "storagecommands.hpp"
18
19#include "commandutils.hpp"
20#include "ipmi_to_redfish_hooks.hpp"
21#include "sdrutils.hpp"
Patrick Venturec2a07d42020-05-30 16:35:03 -070022#include "types.hpp"
Patrick Ventureca99ef52019-10-20 14:00:50 -070023
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070024#include <boost/algorithm/string.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070025#include <boost/container/flat_map.hpp>
James Feist2a265d52019-04-08 11:16:27 -070026#include <ipmid/api.hpp>
James Feist25690252019-12-23 12:25:49 -080027#include <ipmid/message.hpp>
Jason M. Billsc04e2e72018-11-28 15:15:56 -080028#include <phosphor-ipmi-host/selutility.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070029#include <phosphor-logging/log.hpp>
30#include <sdbusplus/message/types.hpp>
31#include <sdbusplus/timer.hpp>
James Feistfcd2d3a2020-05-28 10:38:15 -070032
33#include <filesystem>
Archana Kakanif23fd542021-09-16 05:05:10 +000034#include <fstream>
James Feistfcd2d3a2020-05-28 10:38:15 -070035#include <iostream>
Jason M. Billsc04e2e72018-11-28 15:15:56 -080036#include <stdexcept>
Archana Kakanif23fd542021-09-16 05:05:10 +000037#include <unordered_set>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070038
Patrick Venture9ce789f2019-10-17 09:09:39 -070039static constexpr bool DEBUG = false;
40
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070041namespace intel_oem::ipmi::sel
42{
43static const std::filesystem::path selLogDir = "/var/log";
44static const std::string selLogFilename = "ipmi_sel";
45
46static int getFileTimestamp(const std::filesystem::path& file)
47{
48 struct stat st;
49
50 if (stat(file.c_str(), &st) >= 0)
51 {
52 return st.st_mtime;
53 }
54 return ::ipmi::sel::invalidTimeStamp;
55}
56
57namespace erase_time
Jason M. Bills7944c302019-03-20 15:24:05 -070058{
59static constexpr const char* selEraseTimestamp = "/var/lib/ipmi/sel_erase_time";
60
61void save()
62{
63 // open the file, creating it if necessary
64 int fd = open(selEraseTimestamp, O_WRONLY | O_CREAT | O_CLOEXEC, 0644);
65 if (fd < 0)
66 {
67 std::cerr << "Failed to open file\n";
68 return;
69 }
70
71 // update the file timestamp to the current time
72 if (futimens(fd, NULL) < 0)
73 {
74 std::cerr << "Failed to update timestamp: "
75 << std::string(strerror(errno));
76 }
77 close(fd);
78}
79
80int get()
81{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070082 return getFileTimestamp(selEraseTimestamp);
Jason M. Bills7944c302019-03-20 15:24:05 -070083}
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070084} // namespace erase_time
85} // namespace intel_oem::ipmi::sel
Jason M. Bills7944c302019-03-20 15:24:05 -070086
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070087namespace ipmi
88{
89
90namespace storage
91{
92
Jason M. Billse2d1aee2018-10-03 15:57:18 -070093constexpr static const size_t maxMessageSize = 64;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070094constexpr static const size_t maxFruSdrNameSize = 16;
James Feiste4f710d2020-05-20 15:50:30 -070095using ObjectType = boost::container::flat_map<
96 std::string, boost::container::flat_map<std::string, DbusVariant>>;
97using ManagedObjectType =
98 boost::container::flat_map<sdbusplus::message::object_path, ObjectType>;
99using ManagedEntry = std::pair<sdbusplus::message::object_path, ObjectType>;
Archana Kakanif23fd542021-09-16 05:05:10 +0000100using GetObjectType =
101 std::vector<std::pair<std::string, std::vector<std::string>>>;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700102
James Feist3bcba452018-12-20 12:31:03 -0800103constexpr static const char* fruDeviceServiceName =
104 "xyz.openbmc_project.FruDevice";
Patrick Venture9ce789f2019-10-17 09:09:39 -0700105constexpr static const char* entityManagerServiceName =
106 "xyz.openbmc_project.EntityManager";
James Feist25690252019-12-23 12:25:49 -0800107constexpr static const size_t writeTimeoutSeconds = 10;
Anoop S358e7df2020-05-05 16:43:34 +0000108constexpr static const char* chassisTypeRackMount = "23";
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700109
Jason M. Bills4ed6f2c2019-04-02 12:21:25 -0700110// event direction is bit[7] of eventType where 1b = Deassertion event
111constexpr static const uint8_t deassertionEvent = 0x80;
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800112
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700113static std::vector<uint8_t> fruCache;
114static uint8_t cacheBus = 0xFF;
115static uint8_t cacheAddr = 0XFF;
James Feiste4f710d2020-05-20 15:50:30 -0700116static uint8_t lastDevId = 0xFF;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700117
James Feist25690252019-12-23 12:25:49 -0800118static uint8_t writeBus = 0xFF;
119static uint8_t writeAddr = 0XFF;
120
121std::unique_ptr<phosphor::Timer> writeTimer = nullptr;
James Feiste4f710d2020-05-20 15:50:30 -0700122static std::vector<sdbusplus::bus::match::match> fruMatches;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700123
James Feist25690252019-12-23 12:25:49 -0800124ManagedObjectType frus;
125
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700126// we unfortunately have to build a map of hashes in case there is a
127// collision to verify our dev-id
128boost::container::flat_map<uint8_t, std::pair<uint8_t, uint8_t>> deviceHashes;
Archana Kakanif23fd542021-09-16 05:05:10 +0000129// Map devId to Object Path
130boost::container::flat_map<uint8_t, std::string> devicePath;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700131
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700132void registerStorageFunctions() __attribute__((constructor));
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700133
134bool writeFru()
135{
James Feist25690252019-12-23 12:25:49 -0800136 if (writeBus == 0xFF && writeAddr == 0xFF)
137 {
138 return true;
139 }
Vernon Mauery15419dd2019-05-24 09:40:30 -0700140 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
141 sdbusplus::message::message writeFru = dbus->new_method_call(
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700142 fruDeviceServiceName, "/xyz/openbmc_project/FruDevice",
143 "xyz.openbmc_project.FruDeviceManager", "WriteFru");
James Feist25690252019-12-23 12:25:49 -0800144 writeFru.append(writeBus, writeAddr, fruCache);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700145 try
146 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700147 sdbusplus::message::message writeFruResp = dbus->call(writeFru);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700148 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500149 catch (const sdbusplus::exception_t&)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700150 {
151 // todo: log sel?
152 phosphor::logging::log<phosphor::logging::level::ERR>(
153 "error writing fru");
154 return false;
155 }
James Feist25690252019-12-23 12:25:49 -0800156 writeBus = 0xFF;
157 writeAddr = 0xFF;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700158 return true;
159}
160
James Feist25690252019-12-23 12:25:49 -0800161void createTimers()
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700162{
James Feist25690252019-12-23 12:25:49 -0800163 writeTimer = std::make_unique<phosphor::Timer>(writeFru);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700164}
165
James Feiste4f710d2020-05-20 15:50:30 -0700166void recalculateHashes()
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700167{
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700168
169 deviceHashes.clear();
Archana Kakanif23fd542021-09-16 05:05:10 +0000170 devicePath.clear();
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700171 // hash the object paths to create unique device id's. increment on
172 // collision
173 std::hash<std::string> hasher;
174 for (const auto& fru : frus)
175 {
176 auto fruIface = fru.second.find("xyz.openbmc_project.FruDevice");
177 if (fruIface == fru.second.end())
178 {
179 continue;
180 }
181
182 auto busFind = fruIface->second.find("BUS");
183 auto addrFind = fruIface->second.find("ADDRESS");
184 if (busFind == fruIface->second.end() ||
185 addrFind == fruIface->second.end())
186 {
187 phosphor::logging::log<phosphor::logging::level::INFO>(
188 "fru device missing Bus or Address",
189 phosphor::logging::entry("FRU=%s", fru.first.str.c_str()));
190 continue;
191 }
192
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700193 uint8_t fruBus = std::get<uint32_t>(busFind->second);
194 uint8_t fruAddr = std::get<uint32_t>(addrFind->second);
Anoop S358e7df2020-05-05 16:43:34 +0000195 auto chassisFind = fruIface->second.find("CHASSIS_TYPE");
196 std::string chassisType;
197 if (chassisFind != fruIface->second.end())
198 {
199 chassisType = std::get<std::string>(chassisFind->second);
200 }
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700201
202 uint8_t fruHash = 0;
Anoop S358e7df2020-05-05 16:43:34 +0000203 if (chassisType.compare(chassisTypeRackMount) != 0)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700204 {
205 fruHash = hasher(fru.first.str);
206 // can't be 0xFF based on spec, and 0 is reserved for baseboard
207 if (fruHash == 0 || fruHash == 0xFF)
208 {
209 fruHash = 1;
210 }
211 }
212 std::pair<uint8_t, uint8_t> newDev(fruBus, fruAddr);
213
214 bool emplacePassed = false;
215 while (!emplacePassed)
216 {
217 auto resp = deviceHashes.emplace(fruHash, newDev);
Archana Kakanif23fd542021-09-16 05:05:10 +0000218
219 devicePath.emplace(fruHash, fru.first);
220
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700221 emplacePassed = resp.second;
222 if (!emplacePassed)
223 {
224 fruHash++;
225 // can't be 0xFF based on spec, and 0 is reserved for
226 // baseboard
227 if (fruHash == 0XFF)
228 {
229 fruHash = 0x1;
230 }
231 }
232 }
233 }
James Feiste4f710d2020-05-20 15:50:30 -0700234}
235
236void replaceCacheFru(const std::shared_ptr<sdbusplus::asio::connection>& bus,
Archana Kakanif23fd542021-09-16 05:05:10 +0000237 boost::asio::yield_context& yield)
James Feiste4f710d2020-05-20 15:50:30 -0700238{
239 boost::system::error_code ec;
Archana Kakanif23fd542021-09-16 05:05:10 +0000240 // ObjectPaths and Services which implements "xyz.openbmc_project.FruDevice"
241 // interface
242 GetSubTreeType fruServices = bus->yield_method_call<GetSubTreeType>(
243 yield, ec, "xyz.openbmc_project.ObjectMapper",
244 "/xyz/openbmc_project/object_mapper",
245 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
246 std::array<const char*, 1>{"xyz.openbmc_project.FruDevice"});
James Feiste4f710d2020-05-20 15:50:30 -0700247
James Feiste4f710d2020-05-20 15:50:30 -0700248 if (ec)
249 {
250 phosphor::logging::log<phosphor::logging::level::ERR>(
Archana Kakanif23fd542021-09-16 05:05:10 +0000251 "GetSubTree failed for FruDevice Interface ",
James Feiste4f710d2020-05-20 15:50:30 -0700252 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
253
254 return;
255 }
Archana Kakanif23fd542021-09-16 05:05:10 +0000256 // Get List of services which have implemented FruDevice interface
257 std::unordered_set<std::string> services;
258 for (const auto& [path, serviceMap] : fruServices)
259 {
260 for (const auto& [service, interfaces] : serviceMap)
261 {
262 services.insert(service);
263 }
264 }
265
266 // GetAll the objects under services which implement FruDevice interface
267 for (const std::string& service : services)
268 {
269 ec = boost::system::errc::make_error_code(boost::system::errc::success);
270 ManagedObjectType obj = bus->yield_method_call<ManagedObjectType>(
271 yield, ec, service, "/", "org.freedesktop.DBus.ObjectManager",
272 "GetManagedObjects");
273 if (ec)
274 {
275 phosphor::logging::log<phosphor::logging::level::ERR>(
276 "GetMangagedObjects failed",
277 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
278 continue;
279 }
280 // Save the object path which has FruDevice interface
281 for (const auto& [path, serviceMap] : fruServices)
282 {
283 for (const auto& serv : serviceMap)
284 {
285 if (serv.first == service)
286 {
287 auto fru = obj.find(path);
288 if (fru == obj.end())
289 {
290 continue;
291 }
292 frus.emplace(fru->first, fru->second);
293 }
294 }
295 }
296 }
297
James Feiste4f710d2020-05-20 15:50:30 -0700298 recalculateHashes();
299}
300
301ipmi::Cc getFru(ipmi::Context::ptr ctx, uint8_t devId)
302{
303 if (lastDevId == devId && devId != 0xFF)
304 {
305 return ipmi::ccSuccess;
306 }
307
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700308 auto deviceFind = deviceHashes.find(devId);
Archana Kakanif23fd542021-09-16 05:05:10 +0000309 auto devPath = devicePath.find(devId);
310 if (deviceFind == deviceHashes.end() || devPath == devicePath.end())
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700311 {
312 return IPMI_CC_SENSOR_INVALID;
313 }
314
315 fruCache.clear();
James Feist25690252019-12-23 12:25:49 -0800316
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700317 cacheBus = deviceFind->second.first;
318 cacheAddr = deviceFind->second.second;
James Feist25690252019-12-23 12:25:49 -0800319
James Feiste4f710d2020-05-20 15:50:30 -0700320 boost::system::error_code ec;
Archana Kakanif23fd542021-09-16 05:05:10 +0000321 GetObjectType fruService = ctx->bus->yield_method_call<GetObjectType>(
322 ctx->yield, ec, "xyz.openbmc_project.ObjectMapper",
323 "/xyz/openbmc_project/object_mapper",
324 "xyz.openbmc_project.ObjectMapper", "GetObject", devPath->second,
325 std::array<const char*, 1>{"xyz.openbmc_project.FruDevice"});
James Feiste4f710d2020-05-20 15:50:30 -0700326
James Feist25690252019-12-23 12:25:49 -0800327 if (ec)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700328 {
James Feist25690252019-12-23 12:25:49 -0800329 phosphor::logging::log<phosphor::logging::level::ERR>(
Archana Kakanif23fd542021-09-16 05:05:10 +0000330 "Couldn't get raw fru because of service",
331 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
332 return ipmi::ccResponseError;
333 }
334
335 bool foundFru = false;
336 for (auto& service : fruService)
337 {
338 fruCache = ctx->bus->yield_method_call<std::vector<uint8_t>>(
339 ctx->yield, ec, service.first, "/xyz/openbmc_project/FruDevice",
340 "xyz.openbmc_project.FruDeviceManager", "GetRawFru", cacheBus,
341 cacheAddr);
342
343 if (!ec)
344 {
345 foundFru = true;
346 break;
347 }
348 }
349
350 if (!foundFru)
351 {
352 phosphor::logging::log<phosphor::logging::level::ERR>(
James Feist25690252019-12-23 12:25:49 -0800353 "Couldn't get raw fru",
354 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700355 cacheBus = 0xFF;
356 cacheAddr = 0xFF;
James Feist25690252019-12-23 12:25:49 -0800357 return ipmi::ccResponseError;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700358 }
359
360 lastDevId = devId;
James Feist25690252019-12-23 12:25:49 -0800361 return ipmi::ccSuccess;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700362}
363
James Feiste4f710d2020-05-20 15:50:30 -0700364void writeFruIfRunning()
365{
366 if (!writeTimer->isRunning())
367 {
368 return;
369 }
370 writeTimer->stop();
371 writeFru();
372}
373
374void startMatch(void)
375{
376 if (fruMatches.size())
377 {
378 return;
379 }
380
381 fruMatches.reserve(2);
382
383 auto bus = getSdBus();
384 fruMatches.emplace_back(*bus,
385 "type='signal',arg0path='/xyz/openbmc_project/"
386 "FruDevice/',member='InterfacesAdded'",
387 [](sdbusplus::message::message& message) {
388 sdbusplus::message::object_path path;
389 ObjectType object;
390 try
391 {
392 message.read(path, object);
393 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500394 catch (const sdbusplus::exception_t&)
James Feiste4f710d2020-05-20 15:50:30 -0700395 {
396 return;
397 }
398 auto findType = object.find(
399 "xyz.openbmc_project.FruDevice");
400 if (findType == object.end())
401 {
402 return;
403 }
404 writeFruIfRunning();
405 frus[path] = object;
406 recalculateHashes();
407 lastDevId = 0xFF;
408 });
409
410 fruMatches.emplace_back(*bus,
411 "type='signal',arg0path='/xyz/openbmc_project/"
412 "FruDevice/',member='InterfacesRemoved'",
413 [](sdbusplus::message::message& message) {
414 sdbusplus::message::object_path path;
415 std::set<std::string> interfaces;
416 try
417 {
418 message.read(path, interfaces);
419 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500420 catch (const sdbusplus::exception_t&)
James Feiste4f710d2020-05-20 15:50:30 -0700421 {
422 return;
423 }
424 auto findType = interfaces.find(
425 "xyz.openbmc_project.FruDevice");
426 if (findType == interfaces.end())
427 {
428 return;
429 }
430 writeFruIfRunning();
431 frus.erase(path);
432 recalculateHashes();
433 lastDevId = 0xFF;
434 });
435
436 // call once to populate
437 boost::asio::spawn(*getIoContext(), [](boost::asio::yield_context yield) {
438 replaceCacheFru(getSdBus(), yield);
439 });
440}
441
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000442/** @brief implements the read FRU data command
443 * @param fruDeviceId - FRU Device ID
444 * @param fruInventoryOffset - FRU Inventory Offset to write
445 * @param countToRead - Count to read
446 *
447 * @returns ipmi completion code plus response data
448 * - countWritten - Count written
449 */
450ipmi::RspType<uint8_t, // Count
451 std::vector<uint8_t> // Requested data
452 >
James Feist25690252019-12-23 12:25:49 -0800453 ipmiStorageReadFruData(ipmi::Context::ptr ctx, uint8_t fruDeviceId,
454 uint16_t fruInventoryOffset, uint8_t countToRead)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700455{
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000456 if (fruDeviceId == 0xFF)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700457 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000458 return ipmi::responseInvalidFieldRequest();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700459 }
460
James Feiste4f710d2020-05-20 15:50:30 -0700461 ipmi::Cc status = getFru(ctx, fruDeviceId);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700462
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000463 if (status != ipmi::ccSuccess)
464 {
465 return ipmi::response(status);
466 }
467
468 size_t fromFruByteLen = 0;
469 if (countToRead + fruInventoryOffset < fruCache.size())
470 {
471 fromFruByteLen = countToRead;
472 }
473 else if (fruCache.size() > fruInventoryOffset)
474 {
475 fromFruByteLen = fruCache.size() - fruInventoryOffset;
476 }
477 else
478 {
srikanta mondal92108382020-02-27 18:53:20 +0000479 return ipmi::responseReqDataLenExceeded();
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000480 }
481
482 std::vector<uint8_t> requestedData;
483
484 requestedData.insert(
485 requestedData.begin(), fruCache.begin() + fruInventoryOffset,
486 fruCache.begin() + fruInventoryOffset + fromFruByteLen);
487
Patrick Venture70b17f92019-10-28 20:01:53 -0700488 return ipmi::responseSuccess(static_cast<uint8_t>(requestedData.size()),
489 requestedData);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700490}
491
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000492/** @brief implements the write FRU data command
493 * @param fruDeviceId - FRU Device ID
494 * @param fruInventoryOffset - FRU Inventory Offset to write
495 * @param dataToWrite - Data to write
496 *
497 * @returns ipmi completion code plus response data
498 * - countWritten - Count written
499 */
500ipmi::RspType<uint8_t>
James Feist25690252019-12-23 12:25:49 -0800501 ipmiStorageWriteFruData(ipmi::Context::ptr ctx, uint8_t fruDeviceId,
502 uint16_t fruInventoryOffset,
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000503 std::vector<uint8_t>& dataToWrite)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700504{
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000505 if (fruDeviceId == 0xFF)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700506 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000507 return ipmi::responseInvalidFieldRequest();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700508 }
509
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000510 size_t writeLen = dataToWrite.size();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700511
James Feiste4f710d2020-05-20 15:50:30 -0700512 ipmi::Cc status = getFru(ctx, fruDeviceId);
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000513 if (status != ipmi::ccSuccess)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700514 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000515 return ipmi::response(status);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700516 }
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000517 int lastWriteAddr = fruInventoryOffset + writeLen;
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700518 if (fruCache.size() < lastWriteAddr)
519 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000520 fruCache.resize(fruInventoryOffset + writeLen);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700521 }
522
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000523 std::copy(dataToWrite.begin(), dataToWrite.begin() + writeLen,
524 fruCache.begin() + fruInventoryOffset);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700525
526 bool atEnd = false;
527
528 if (fruCache.size() >= sizeof(FRUHeader))
529 {
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700530 FRUHeader* header = reinterpret_cast<FRUHeader*>(fruCache.data());
531
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800532 int areaLength = 0;
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700533 int lastRecordStart = std::max(
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800534 {header->internalOffset, header->chassisOffset, header->boardOffset,
535 header->productOffset, header->multiRecordOffset});
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700536 lastRecordStart *= 8; // header starts in are multiples of 8 bytes
537
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800538 if (header->multiRecordOffset)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700539 {
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800540 // This FRU has a MultiRecord Area
541 uint8_t endOfList = 0;
542 // Walk the MultiRecord headers until the last record
543 while (!endOfList)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700544 {
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800545 // The MSB in the second byte of the MultiRecord header signals
546 // "End of list"
547 endOfList = fruCache[lastRecordStart + 1] & 0x80;
548 // Third byte in the MultiRecord header is the length
549 areaLength = fruCache[lastRecordStart + 2];
550 // This length is in bytes (not 8 bytes like other headers)
551 areaLength += 5; // The length omits the 5 byte header
552 if (!endOfList)
553 {
554 // Next MultiRecord header
555 lastRecordStart += areaLength;
556 }
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700557 }
558 }
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800559 else
560 {
561 // This FRU does not have a MultiRecord Area
562 // Get the length of the area in multiples of 8 bytes
563 if (lastWriteAddr > (lastRecordStart + 1))
564 {
565 // second byte in record area is the length
566 areaLength = fruCache[lastRecordStart + 1];
567 areaLength *= 8; // it is in multiples of 8 bytes
568 }
569 }
570 if (lastWriteAddr >= (areaLength + lastRecordStart))
571 {
572 atEnd = true;
573 }
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700574 }
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000575 uint8_t countWritten = 0;
James Feist25690252019-12-23 12:25:49 -0800576
577 writeBus = cacheBus;
578 writeAddr = cacheAddr;
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700579 if (atEnd)
580 {
581 // cancel timer, we're at the end so might as well send it
James Feist25690252019-12-23 12:25:49 -0800582 writeTimer->stop();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700583 if (!writeFru())
584 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000585 return ipmi::responseInvalidFieldRequest();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700586 }
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000587 countWritten = std::min(fruCache.size(), static_cast<size_t>(0xFF));
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700588 }
589 else
590 {
James Feist25690252019-12-23 12:25:49 -0800591 // start a timer, if no further data is sent to check to see if it is
592 // valid
593 writeTimer->start(std::chrono::duration_cast<std::chrono::microseconds>(
594 std::chrono::seconds(writeTimeoutSeconds)));
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000595 countWritten = 0;
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700596 }
597
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000598 return ipmi::responseSuccess(countWritten);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700599}
600
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000601/** @brief implements the get FRU inventory area info command
602 * @param fruDeviceId - FRU Device ID
603 *
604 * @returns IPMI completion code plus response data
605 * - inventorySize - Number of possible allocation units
606 * - accessType - Allocation unit size in bytes.
607 */
608ipmi::RspType<uint16_t, // inventorySize
609 uint8_t> // accessType
James Feist25690252019-12-23 12:25:49 -0800610 ipmiStorageGetFruInvAreaInfo(ipmi::Context::ptr ctx, uint8_t fruDeviceId)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700611{
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000612 if (fruDeviceId == 0xFF)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700613 {
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000614 return ipmi::responseInvalidFieldRequest();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700615 }
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700616
Jayaprakash Mutyala1e2ab062020-08-03 16:57:00 +0000617 ipmi::Cc ret = getFru(ctx, fruDeviceId);
618 if (ret != ipmi::ccSuccess)
619 {
620 return ipmi::response(ret);
621 }
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700622
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000623 constexpr uint8_t accessType =
624 static_cast<uint8_t>(GetFRUAreaAccessType::byte);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700625
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000626 return ipmi::responseSuccess(fruCache.size(), accessType);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700627}
628
James Feist25690252019-12-23 12:25:49 -0800629ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700630{
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700631 count = deviceHashes.size();
632 return IPMI_CC_OK;
633}
634
James Feist25690252019-12-23 12:25:49 -0800635ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index,
636 get_sdr::SensorDataFruRecord& resp)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700637{
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700638 if (deviceHashes.size() < index)
639 {
640 return IPMI_CC_INVALID_FIELD_REQUEST;
641 }
642 auto device = deviceHashes.begin() + index;
643 uint8_t& bus = device->second.first;
644 uint8_t& address = device->second.second;
645
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700646 boost::container::flat_map<std::string, DbusVariant>* fruData = nullptr;
647 auto fru =
648 std::find_if(frus.begin(), frus.end(),
649 [bus, address, &fruData](ManagedEntry& entry) {
650 auto findFruDevice =
651 entry.second.find("xyz.openbmc_project.FruDevice");
652 if (findFruDevice == entry.second.end())
653 {
654 return false;
655 }
656 fruData = &(findFruDevice->second);
657 auto findBus = findFruDevice->second.find("BUS");
658 auto findAddress =
659 findFruDevice->second.find("ADDRESS");
660 if (findBus == findFruDevice->second.end() ||
661 findAddress == findFruDevice->second.end())
662 {
663 return false;
664 }
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700665 if (std::get<uint32_t>(findBus->second) != bus)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700666 {
667 return false;
668 }
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700669 if (std::get<uint32_t>(findAddress->second) != address)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700670 {
671 return false;
672 }
673 return true;
674 });
675 if (fru == frus.end())
676 {
677 return IPMI_CC_RESPONSE_ERROR;
678 }
Patrick Venture9ce789f2019-10-17 09:09:39 -0700679
James Feist25690252019-12-23 12:25:49 -0800680#ifdef USING_ENTITY_MANAGER_DECORATORS
681
Patrick Venture9ce789f2019-10-17 09:09:39 -0700682 boost::container::flat_map<std::string, DbusVariant>* entityData = nullptr;
Patrick Venture9ce789f2019-10-17 09:09:39 -0700683
James Feist25690252019-12-23 12:25:49 -0800684 // todo: this should really use caching, this is a very inefficient lookup
685 boost::system::error_code ec;
686 ManagedObjectType entities = ctx->bus->yield_method_call<ManagedObjectType>(
687 ctx->yield, ec, entityManagerServiceName, "/",
688 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
689
690 if (ec)
Patrick Venture9ce789f2019-10-17 09:09:39 -0700691 {
James Feist25690252019-12-23 12:25:49 -0800692 phosphor::logging::log<phosphor::logging::level::ERR>(
693 "GetMangagedObjects for getSensorMap failed",
694 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
Patrick Venture9ce789f2019-10-17 09:09:39 -0700695
James Feist25690252019-12-23 12:25:49 -0800696 return ipmi::ccResponseError;
697 }
Patrick Venture9ce789f2019-10-17 09:09:39 -0700698
James Feist25690252019-12-23 12:25:49 -0800699 auto entity = std::find_if(
700 entities.begin(), entities.end(),
701 [bus, address, &entityData](ManagedEntry& entry) {
702 auto findFruDevice = entry.second.find(
703 "xyz.openbmc_project.Inventory.Decorator.FruDevice");
704 if (findFruDevice == entry.second.end())
Patrick Venture9ce789f2019-10-17 09:09:39 -0700705 {
James Feist25690252019-12-23 12:25:49 -0800706 return false;
Patrick Venture9ce789f2019-10-17 09:09:39 -0700707 }
James Feist25690252019-12-23 12:25:49 -0800708
709 // Integer fields added via Entity-Manager json are uint64_ts by
710 // default.
711 auto findBus = findFruDevice->second.find("Bus");
712 auto findAddress = findFruDevice->second.find("Address");
713
714 if (findBus == findFruDevice->second.end() ||
715 findAddress == findFruDevice->second.end())
716 {
717 return false;
718 }
719 if ((std::get<uint64_t>(findBus->second) != bus) ||
720 (std::get<uint64_t>(findAddress->second) != address))
721 {
722 return false;
723 }
724
725 // At this point we found the device entry and should return
726 // true.
727 auto findIpmiDevice = entry.second.find(
728 "xyz.openbmc_project.Inventory.Decorator.Ipmi");
729 if (findIpmiDevice != entry.second.end())
730 {
731 entityData = &(findIpmiDevice->second);
732 }
733
734 return true;
735 });
736
737 if (entity == entities.end())
738 {
739 if constexpr (DEBUG)
740 {
741 std::fprintf(stderr, "Ipmi or FruDevice Decorator interface "
742 "not found for Fru\n");
Patrick Venture9ce789f2019-10-17 09:09:39 -0700743 }
744 }
James Feist25690252019-12-23 12:25:49 -0800745
746#endif
Patrick Venture9ce789f2019-10-17 09:09:39 -0700747
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700748 std::string name;
749 auto findProductName = fruData->find("BOARD_PRODUCT_NAME");
750 auto findBoardName = fruData->find("PRODUCT_PRODUCT_NAME");
751 if (findProductName != fruData->end())
752 {
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700753 name = std::get<std::string>(findProductName->second);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700754 }
755 else if (findBoardName != fruData->end())
756 {
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700757 name = std::get<std::string>(findBoardName->second);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700758 }
759 else
760 {
761 name = "UNKNOWN";
762 }
763 if (name.size() > maxFruSdrNameSize)
764 {
765 name = name.substr(0, maxFruSdrNameSize);
766 }
767 size_t sizeDiff = maxFruSdrNameSize - name.size();
768
769 resp.header.record_id_lsb = 0x0; // calling code is to implement these
770 resp.header.record_id_msb = 0x0;
771 resp.header.sdr_version = ipmiSdrVersion;
Patrick Venture73d01352019-10-11 18:32:59 -0700772 resp.header.record_type = get_sdr::SENSOR_DATA_FRU_RECORD;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700773 resp.header.record_length = sizeof(resp.body) + sizeof(resp.key) - sizeDiff;
774 resp.key.deviceAddress = 0x20;
775 resp.key.fruID = device->first;
776 resp.key.accessLun = 0x80; // logical / physical fru device
777 resp.key.channelNumber = 0x0;
778 resp.body.reserved = 0x0;
779 resp.body.deviceType = 0x10;
James Feist4f86d1f2019-04-03 10:30:26 -0700780 resp.body.deviceTypeModifier = 0x0;
Patrick Venture9ce789f2019-10-17 09:09:39 -0700781
782 uint8_t entityID = 0;
783 uint8_t entityInstance = 0x1;
784
James Feist25690252019-12-23 12:25:49 -0800785#ifdef USING_ENTITY_MANAGER_DECORATORS
Patrick Venture9ce789f2019-10-17 09:09:39 -0700786 if (entityData)
787 {
788 auto entityIdProperty = entityData->find("EntityId");
789 auto entityInstanceProperty = entityData->find("EntityInstance");
790
791 if (entityIdProperty != entityData->end())
792 {
793 entityID = static_cast<uint8_t>(
794 std::get<uint64_t>(entityIdProperty->second));
795 }
796 if (entityInstanceProperty != entityData->end())
797 {
798 entityInstance = static_cast<uint8_t>(
799 std::get<uint64_t>(entityInstanceProperty->second));
800 }
801 }
James Feist25690252019-12-23 12:25:49 -0800802#endif
Patrick Venture9ce789f2019-10-17 09:09:39 -0700803
804 resp.body.entityID = entityID;
805 resp.body.entityInstance = entityInstance;
806
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700807 resp.body.oem = 0x0;
808 resp.body.deviceIDLen = name.size();
809 name.copy(resp.body.deviceID, name.size());
810
811 return IPMI_CC_OK;
812}
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700813
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700814static bool getSELLogFiles(std::vector<std::filesystem::path>& selLogFiles)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800815{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700816 // Loop through the directory looking for ipmi_sel log files
817 for (const std::filesystem::directory_entry& dirEnt :
818 std::filesystem::directory_iterator(intel_oem::ipmi::sel::selLogDir))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800819 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700820 std::string filename = dirEnt.path().filename();
821 if (boost::starts_with(filename, intel_oem::ipmi::sel::selLogFilename))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800822 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700823 // If we find an ipmi_sel log file, save the path
824 selLogFiles.emplace_back(intel_oem::ipmi::sel::selLogDir /
825 filename);
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800826 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800827 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700828 // As the log files rotate, they are appended with a ".#" that is higher for
829 // the older logs. Since we don't expect more than 10 log files, we
830 // can just sort the list to get them in order from newest to oldest
831 std::sort(selLogFiles.begin(), selLogFiles.end());
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800832
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700833 return !selLogFiles.empty();
834}
835
836static int countSELEntries()
837{
838 // Get the list of ipmi_sel log files
839 std::vector<std::filesystem::path> selLogFiles;
840 if (!getSELLogFiles(selLogFiles))
841 {
842 return 0;
843 }
844 int numSELEntries = 0;
845 // Loop through each log file and count the number of logs
846 for (const std::filesystem::path& file : selLogFiles)
847 {
848 std::ifstream logStream(file);
849 if (!logStream.is_open())
850 {
851 continue;
852 }
853
854 std::string line;
855 while (std::getline(logStream, line))
856 {
857 numSELEntries++;
858 }
859 }
860 return numSELEntries;
861}
862
863static bool findSELEntry(const int recordID,
Patrick Ventureff7e15b2019-09-25 16:48:26 -0700864 const std::vector<std::filesystem::path>& selLogFiles,
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700865 std::string& entry)
866{
867 // Record ID is the first entry field following the timestamp. It is
868 // preceded by a space and followed by a comma
869 std::string search = " " + std::to_string(recordID) + ",";
870
871 // Loop through the ipmi_sel log entries
872 for (const std::filesystem::path& file : selLogFiles)
873 {
874 std::ifstream logStream(file);
875 if (!logStream.is_open())
876 {
877 continue;
878 }
879
880 while (std::getline(logStream, entry))
881 {
882 // Check if the record ID matches
883 if (entry.find(search) != std::string::npos)
884 {
885 return true;
886 }
887 }
888 }
889 return false;
890}
891
892static uint16_t
893 getNextRecordID(const uint16_t recordID,
Patrick Ventureff7e15b2019-09-25 16:48:26 -0700894 const std::vector<std::filesystem::path>& selLogFiles)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700895{
896 uint16_t nextRecordID = recordID + 1;
897 std::string entry;
898 if (findSELEntry(nextRecordID, selLogFiles, entry))
899 {
900 return nextRecordID;
901 }
902 else
903 {
904 return ipmi::sel::lastEntry;
905 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800906}
907
Patrick Ventureff7e15b2019-09-25 16:48:26 -0700908static int fromHexStr(const std::string& hexStr, std::vector<uint8_t>& data)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800909{
910 for (unsigned int i = 0; i < hexStr.size(); i += 2)
911 {
912 try
913 {
914 data.push_back(static_cast<uint8_t>(
915 std::stoul(hexStr.substr(i, 2), nullptr, 16)));
916 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500917 catch (const std::invalid_argument& e)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800918 {
919 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
920 return -1;
921 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500922 catch (const std::out_of_range& e)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800923 {
924 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
925 return -1;
926 }
927 }
928 return 0;
929}
930
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700931ipmi::RspType<uint8_t, // SEL version
932 uint16_t, // SEL entry count
933 uint16_t, // free space
934 uint32_t, // last add timestamp
935 uint32_t, // last erase timestamp
936 uint8_t> // operation support
937 ipmiStorageGetSELInfo()
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800938{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700939 constexpr uint8_t selVersion = ipmi::sel::selVersion;
940 uint16_t entries = countSELEntries();
941 uint32_t addTimeStamp = intel_oem::ipmi::sel::getFileTimestamp(
942 intel_oem::ipmi::sel::selLogDir / intel_oem::ipmi::sel::selLogFilename);
943 uint32_t eraseTimeStamp = intel_oem::ipmi::sel::erase_time::get();
944 constexpr uint8_t operationSupport =
945 intel_oem::ipmi::sel::selOperationSupport;
946 constexpr uint16_t freeSpace =
947 0xffff; // Spec indicates that more than 64kB is free
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800948
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700949 return ipmi::responseSuccess(selVersion, entries, freeSpace, addTimeStamp,
950 eraseTimeStamp, operationSupport);
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800951}
952
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700953using systemEventType = std::tuple<
954 uint32_t, // Timestamp
955 uint16_t, // Generator ID
956 uint8_t, // EvM Rev
957 uint8_t, // Sensor Type
958 uint8_t, // Sensor Number
959 uint7_t, // Event Type
960 bool, // Event Direction
961 std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize>>; // Event Data
962using oemTsEventType = std::tuple<
963 uint32_t, // Timestamp
964 std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize>>; // Event Data
965using oemEventType =
966 std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize>; // Event Data
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800967
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700968ipmi::RspType<uint16_t, // Next Record ID
969 uint16_t, // Record ID
970 uint8_t, // Record Type
971 std::variant<systemEventType, oemTsEventType,
972 oemEventType>> // Record Content
973 ipmiStorageGetSELEntry(uint16_t reservationID, uint16_t targetID,
974 uint8_t offset, uint8_t size)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800975{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700976 // Only support getting the entire SEL record. If a partial size or non-zero
977 // offset is requested, return an error
978 if (offset != 0 || size != ipmi::sel::entireRecord)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800979 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700980 return ipmi::responseRetBytesUnavailable();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800981 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800982
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700983 // Check the reservation ID if one is provided or required (only if the
984 // offset is non-zero)
985 if (reservationID != 0 || offset != 0)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800986 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700987 if (!checkSELReservation(reservationID))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800988 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700989 return ipmi::responseInvalidReservationId();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800990 }
991 }
992
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700993 // Get the ipmi_sel log files
994 std::vector<std::filesystem::path> selLogFiles;
995 if (!getSELLogFiles(selLogFiles))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800996 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700997 return ipmi::responseSensorInvalid();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800998 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800999
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001000 std::string targetEntry;
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001001
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001002 if (targetID == ipmi::sel::firstEntry)
1003 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001004 // The first entry will be at the top of the oldest log file
1005 std::ifstream logStream(selLogFiles.back());
1006 if (!logStream.is_open())
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001007 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001008 return ipmi::responseUnspecifiedError();
1009 }
1010
1011 if (!std::getline(logStream, targetEntry))
1012 {
1013 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001014 }
1015 }
1016 else if (targetID == ipmi::sel::lastEntry)
1017 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001018 // The last entry will be at the bottom of the newest log file
1019 std::ifstream logStream(selLogFiles.front());
1020 if (!logStream.is_open())
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001021 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001022 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001023 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001024
1025 std::string line;
1026 while (std::getline(logStream, line))
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001027 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001028 targetEntry = line;
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001029 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001030 }
1031 else
1032 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001033 if (!findSELEntry(targetID, selLogFiles, targetEntry))
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001034 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001035 return ipmi::responseSensorInvalid();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001036 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001037 }
1038
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001039 // The format of the ipmi_sel message is "<Timestamp>
1040 // <ID>,<Type>,<EventData>,[<Generator ID>,<Path>,<Direction>]".
1041 // First get the Timestamp
1042 size_t space = targetEntry.find_first_of(" ");
1043 if (space == std::string::npos)
1044 {
1045 return ipmi::responseUnspecifiedError();
1046 }
1047 std::string entryTimestamp = targetEntry.substr(0, space);
1048 // Then get the log contents
1049 size_t entryStart = targetEntry.find_first_not_of(" ", space);
1050 if (entryStart == std::string::npos)
1051 {
1052 return ipmi::responseUnspecifiedError();
1053 }
1054 std::string_view entry(targetEntry);
1055 entry.remove_prefix(entryStart);
1056 // Use split to separate the entry into its fields
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001057 std::vector<std::string> targetEntryFields;
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001058 boost::split(targetEntryFields, entry, boost::is_any_of(","),
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001059 boost::token_compress_on);
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001060 if (targetEntryFields.size() < 3)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001061 {
1062 return ipmi::responseUnspecifiedError();
1063 }
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001064 std::string& recordIDStr = targetEntryFields[0];
1065 std::string& recordTypeStr = targetEntryFields[1];
1066 std::string& eventDataStr = targetEntryFields[2];
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001067
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001068 uint16_t recordID;
1069 uint8_t recordType;
1070 try
1071 {
1072 recordID = std::stoul(recordIDStr);
1073 recordType = std::stoul(recordTypeStr, nullptr, 16);
1074 }
1075 catch (const std::invalid_argument&)
1076 {
1077 return ipmi::responseUnspecifiedError();
1078 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001079 uint16_t nextRecordID = getNextRecordID(recordID, selLogFiles);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001080 std::vector<uint8_t> eventDataBytes;
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001081 if (fromHexStr(eventDataStr, eventDataBytes) < 0)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001082 {
1083 return ipmi::responseUnspecifiedError();
1084 }
1085
1086 if (recordType == intel_oem::ipmi::sel::systemEvent)
1087 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001088 // Get the timestamp
1089 std::tm timeStruct = {};
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001090 std::istringstream entryStream(entryTimestamp);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001091
1092 uint32_t timestamp = ipmi::sel::invalidTimeStamp;
1093 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
1094 {
1095 timestamp = std::mktime(&timeStruct);
1096 }
1097
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001098 // Set the event message revision
1099 uint8_t evmRev = intel_oem::ipmi::sel::eventMsgRev;
1100
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001101 uint16_t generatorID = 0;
1102 uint8_t sensorType = 0;
Johnathan Mantey308c3a82020-07-22 11:50:54 -07001103 uint16_t sensorAndLun = 0;
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001104 uint8_t sensorNum = 0xFF;
1105 uint7_t eventType = 0;
1106 bool eventDir = 0;
1107 // System type events should have six fields
1108 if (targetEntryFields.size() >= 6)
1109 {
1110 std::string& generatorIDStr = targetEntryFields[3];
1111 std::string& sensorPath = targetEntryFields[4];
1112 std::string& eventDirStr = targetEntryFields[5];
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001113
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001114 // Get the generator ID
1115 try
1116 {
1117 generatorID = std::stoul(generatorIDStr, nullptr, 16);
1118 }
1119 catch (const std::invalid_argument&)
1120 {
1121 std::cerr << "Invalid Generator ID\n";
1122 }
1123
1124 // Get the sensor type, sensor number, and event type for the sensor
1125 sensorType = getSensorTypeFromPath(sensorPath);
Johnathan Mantey308c3a82020-07-22 11:50:54 -07001126 sensorAndLun = getSensorNumberFromPath(sensorPath);
1127 sensorNum = static_cast<uint8_t>(sensorAndLun);
1128 generatorID |= sensorAndLun >> 8;
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001129 eventType = getSensorEventTypeFromPath(sensorPath);
1130
1131 // Get the event direction
1132 try
1133 {
1134 eventDir = std::stoul(eventDirStr) ? 0 : 1;
1135 }
1136 catch (const std::invalid_argument&)
1137 {
1138 std::cerr << "Invalid Event Direction\n";
1139 }
1140 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001141
1142 // Only keep the eventData bytes that fit in the record
1143 std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize> eventData{};
1144 std::copy_n(eventDataBytes.begin(),
1145 std::min(eventDataBytes.size(), eventData.size()),
1146 eventData.begin());
1147
1148 return ipmi::responseSuccess(
1149 nextRecordID, recordID, recordType,
1150 systemEventType{timestamp, generatorID, evmRev, sensorType,
1151 sensorNum, eventType, eventDir, eventData});
1152 }
1153 else if (recordType >= intel_oem::ipmi::sel::oemTsEventFirst &&
1154 recordType <= intel_oem::ipmi::sel::oemTsEventLast)
1155 {
1156 // Get the timestamp
1157 std::tm timeStruct = {};
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001158 std::istringstream entryStream(entryTimestamp);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001159
1160 uint32_t timestamp = ipmi::sel::invalidTimeStamp;
1161 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
1162 {
1163 timestamp = std::mktime(&timeStruct);
1164 }
1165
1166 // Only keep the bytes that fit in the record
1167 std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize> eventData{};
1168 std::copy_n(eventDataBytes.begin(),
1169 std::min(eventDataBytes.size(), eventData.size()),
1170 eventData.begin());
1171
1172 return ipmi::responseSuccess(nextRecordID, recordID, recordType,
1173 oemTsEventType{timestamp, eventData});
1174 }
Patrick Venturec5136aa2019-10-04 20:39:31 -07001175 else if (recordType >= intel_oem::ipmi::sel::oemEventFirst)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001176 {
1177 // Only keep the bytes that fit in the record
1178 std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize> eventData{};
1179 std::copy_n(eventDataBytes.begin(),
1180 std::min(eventDataBytes.size(), eventData.size()),
1181 eventData.begin());
1182
1183 return ipmi::responseSuccess(nextRecordID, recordID, recordType,
1184 eventData);
1185 }
1186
1187 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001188}
1189
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001190ipmi::RspType<uint16_t> ipmiStorageAddSELEntry(
1191 uint16_t recordID, uint8_t recordType, uint32_t timestamp,
1192 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType, uint8_t sensorNum,
1193 uint8_t eventType, uint8_t eventData1, uint8_t eventData2,
1194 uint8_t eventData3)
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001195{
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001196 // Per the IPMI spec, need to cancel any reservation when a SEL entry is
1197 // added
1198 cancelSELReservation();
1199
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001200 // Send this request to the Redfish hooks to log it as a Redfish message
1201 // instead. There is no need to add it to the SEL, so just return success.
1202 intel_oem::ipmi::sel::checkRedfishHooks(
1203 recordID, recordType, timestamp, generatorID, evmRev, sensorType,
1204 sensorNum, eventType, eventData1, eventData2, eventData3);
Jason M. Bills99b78ec2019-01-18 10:42:18 -08001205
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001206 uint16_t responseID = 0xFFFF;
1207 return ipmi::responseSuccess(responseID);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001208}
1209
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001210ipmi::RspType<uint8_t> ipmiStorageClearSEL(ipmi::Context::ptr ctx,
1211 uint16_t reservationID,
1212 const std::array<uint8_t, 3>& clr,
1213 uint8_t eraseOperation)
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001214{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001215 if (!checkSELReservation(reservationID))
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001216 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001217 return ipmi::responseInvalidReservationId();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001218 }
1219
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001220 static constexpr std::array<uint8_t, 3> clrExpected = {'C', 'L', 'R'};
1221 if (clr != clrExpected)
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001222 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001223 return ipmi::responseInvalidFieldRequest();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001224 }
1225
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001226 // Erasure status cannot be fetched, so always return erasure status as
1227 // `erase completed`.
1228 if (eraseOperation == ipmi::sel::getEraseStatus)
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001229 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001230 return ipmi::responseSuccess(ipmi::sel::eraseComplete);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001231 }
1232
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001233 // Check that initiate erase is correct
1234 if (eraseOperation != ipmi::sel::initiateErase)
1235 {
1236 return ipmi::responseInvalidFieldRequest();
1237 }
1238
1239 // Per the IPMI spec, need to cancel any reservation when the SEL is
1240 // cleared
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001241 cancelSELReservation();
1242
Jason M. Bills7944c302019-03-20 15:24:05 -07001243 // Save the erase time
1244 intel_oem::ipmi::sel::erase_time::save();
1245
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001246 // Clear the SEL by deleting the log files
1247 std::vector<std::filesystem::path> selLogFiles;
1248 if (getSELLogFiles(selLogFiles))
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001249 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001250 for (const std::filesystem::path& file : selLogFiles)
1251 {
1252 std::error_code ec;
1253 std::filesystem::remove(file, ec);
1254 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001255 }
1256
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001257 // Reload rsyslog so it knows to start new log files
Vernon Mauery15419dd2019-05-24 09:40:30 -07001258 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1259 sdbusplus::message::message rsyslogReload = dbus->new_method_call(
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001260 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1261 "org.freedesktop.systemd1.Manager", "ReloadUnit");
1262 rsyslogReload.append("rsyslog.service", "replace");
1263 try
1264 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001265 sdbusplus::message::message reloadResponse = dbus->call(rsyslogReload);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001266 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001267 catch (const sdbusplus::exception_t& e)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001268 {
1269 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1270 }
1271
1272 return ipmi::responseSuccess(ipmi::sel::eraseComplete);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001273}
1274
Jason M. Bills1a474622019-06-14 14:51:33 -07001275ipmi::RspType<uint32_t> ipmiStorageGetSELTime()
1276{
1277 struct timespec selTime = {};
1278
1279 if (clock_gettime(CLOCK_REALTIME, &selTime) < 0)
1280 {
1281 return ipmi::responseUnspecifiedError();
1282 }
1283
1284 return ipmi::responseSuccess(selTime.tv_sec);
1285}
1286
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001287ipmi::RspType<> ipmiStorageSetSELTime(uint32_t selTime)
Jason M. Billscac97a52019-01-30 14:43:46 -08001288{
1289 // Set SEL Time is not supported
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001290 return ipmi::responseInvalidCommand();
Jason M. Billscac97a52019-01-30 14:43:46 -08001291}
1292
James Feist74c50c62019-08-14 14:18:41 -07001293std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId)
1294{
1295 std::vector<uint8_t> resp;
1296 if (index == 0)
1297 {
James Feist74c50c62019-08-14 14:18:41 -07001298 std::string bmcName = "Basbrd Mgmt Ctlr";
Johnathan Manteyf4d5e052021-09-22 12:58:08 -07001299 Type12Record bmc(recordId, 0x20, 0, 0, 0xbf, 0x2e, 1, 0, bmcName);
James Feist74c50c62019-08-14 14:18:41 -07001300 uint8_t* bmcPtr = reinterpret_cast<uint8_t*>(&bmc);
1301 resp.insert(resp.end(), bmcPtr, bmcPtr + sizeof(Type12Record));
1302 }
1303 else if (index == 1)
1304 {
James Feist74c50c62019-08-14 14:18:41 -07001305 std::string meName = "Mgmt Engine";
Johnathan Manteyf4d5e052021-09-22 12:58:08 -07001306 Type12Record me(recordId, 0x2c, 6, 0x24, 0x21, 0x2e, 2, 0, meName);
James Feist74c50c62019-08-14 14:18:41 -07001307 uint8_t* mePtr = reinterpret_cast<uint8_t*>(&me);
1308 resp.insert(resp.end(), mePtr, mePtr + sizeof(Type12Record));
1309 }
1310 else
1311 {
1312 throw std::runtime_error("getType12SDRs:: Illegal index " +
1313 std::to_string(index));
1314 }
1315
1316 return resp;
1317}
1318
Yong Lifee5e4c2020-01-17 19:36:29 +08001319std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId)
1320{
1321 std::vector<uint8_t> resp;
1322 if (index == 0)
1323 {
1324 NMDiscoveryRecord nm = {};
1325 nm.header.record_id_lsb = recordId;
1326 nm.header.record_id_msb = recordId >> 8;
1327 nm.header.sdr_version = ipmiSdrVersion;
1328 nm.header.record_type = 0xC0;
1329 nm.header.record_length = 0xB;
1330 nm.oemID0 = 0x57;
1331 nm.oemID1 = 0x1;
1332 nm.oemID2 = 0x0;
1333 nm.subType = 0x0D;
1334 nm.version = 0x1;
1335 nm.slaveAddress = 0x2C;
1336 nm.channelNumber = 0x60;
1337 nm.healthEventSensor = 0x19;
1338 nm.exceptionEventSensor = 0x18;
1339 nm.operationalCapSensor = 0x1A;
1340 nm.thresholdExceededSensor = 0x1B;
1341
1342 uint8_t* nmPtr = reinterpret_cast<uint8_t*>(&nm);
1343 resp.insert(resp.end(), nmPtr, nmPtr + sizeof(NMDiscoveryRecord));
1344 }
1345 else
1346 {
1347 throw std::runtime_error("getNMDiscoverySDR:: Illegal index " +
1348 std::to_string(index));
1349 }
1350
1351 return resp;
1352}
1353
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001354void registerStorageFunctions()
1355{
James Feist25690252019-12-23 12:25:49 -08001356 createTimers();
James Feiste4f710d2020-05-20 15:50:30 -07001357 startMatch();
1358
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001359 // <Get FRU Inventory Area Info>
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +00001360 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage,
1361 ipmi::storage::cmdGetFruInventoryAreaInfo,
1362 ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001363 // <READ FRU Data>
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +00001364 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1365 ipmi::storage::cmdReadFruData, ipmi::Privilege::User,
1366 ipmiStorageReadFruData);
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001367
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001368 // <WRITE FRU Data>
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +00001369 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1370 ipmi::storage::cmdWriteFruData,
1371 ipmi::Privilege::Operator, ipmiStorageWriteFruData);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001372
1373 // <Get SEL Info>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001374 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
Jason M. Bills542498e2019-06-24 16:57:42 -07001375 ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
1376 ipmiStorageGetSELInfo);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001377
1378 // <Get SEL Entry>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001379 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
Jason M. Bills542498e2019-06-24 16:57:42 -07001380 ipmi::storage::cmdGetSelEntry, ipmi::Privilege::User,
1381 ipmiStorageGetSELEntry);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001382
1383 // <Add SEL Entry>
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001384 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
Vernon Mauery98bbf692019-09-16 11:14:59 -07001385 ipmi::storage::cmdAddSelEntry,
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001386 ipmi::Privilege::Operator, ipmiStorageAddSELEntry);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001387
1388 // <Clear SEL>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001389 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1390 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
1391 ipmiStorageClearSEL);
Jason M. Billscac97a52019-01-30 14:43:46 -08001392
Jason M. Bills1a474622019-06-14 14:51:33 -07001393 // <Get SEL Time>
1394 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
Jason M. Bills542498e2019-06-24 16:57:42 -07001395 ipmi::storage::cmdGetSelTime, ipmi::Privilege::User,
1396 ipmiStorageGetSELTime);
Jason M. Bills1a474622019-06-14 14:51:33 -07001397
Jason M. Billscac97a52019-01-30 14:43:46 -08001398 // <Set SEL Time>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001399 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1400 ipmi::storage::cmdSetSelTime,
1401 ipmi::Privilege::Operator, ipmiStorageSetSELTime);
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001402}
Jason M. Bills3f7c5e42018-10-03 14:00:41 -07001403} // namespace storage
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001404} // namespace ipmi