blob: 2554174f6a27ba3f4816fab5ce6c005dd62e4cb6 [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";
James Feist25690252019-12-23 12:25:49 -0800105constexpr static const size_t writeTimeoutSeconds = 10;
Anoop S358e7df2020-05-05 16:43:34 +0000106constexpr static const char* chassisTypeRackMount = "23";
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700107
Jason M. Bills4ed6f2c2019-04-02 12:21:25 -0700108// event direction is bit[7] of eventType where 1b = Deassertion event
109constexpr static const uint8_t deassertionEvent = 0x80;
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800110
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700111static std::vector<uint8_t> fruCache;
Johnathan Mantey07574002022-12-13 14:52:54 -0800112static uint16_t cacheBus = 0xFFFF;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700113static uint8_t cacheAddr = 0XFF;
James Feiste4f710d2020-05-20 15:50:30 -0700114static uint8_t lastDevId = 0xFF;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700115
Johnathan Mantey07574002022-12-13 14:52:54 -0800116static uint16_t writeBus = 0xFFFF;
James Feist25690252019-12-23 12:25:49 -0800117static uint8_t writeAddr = 0XFF;
118
119std::unique_ptr<phosphor::Timer> writeTimer = nullptr;
Patrick Williamsf944d2e2022-07-22 19:26:52 -0500120static std::vector<sdbusplus::bus::match_t> fruMatches;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700121
James Feist25690252019-12-23 12:25:49 -0800122ManagedObjectType frus;
123
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700124// we unfortunately have to build a map of hashes in case there is a
125// collision to verify our dev-id
Johnathan Mantey07574002022-12-13 14:52:54 -0800126boost::container::flat_map<uint8_t, std::pair<uint16_t, uint8_t>> deviceHashes;
Archana Kakanif23fd542021-09-16 05:05:10 +0000127// Map devId to Object Path
128boost::container::flat_map<uint8_t, std::string> devicePath;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700129
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700130void registerStorageFunctions() __attribute__((constructor));
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700131
132bool writeFru()
133{
Johnathan Mantey07574002022-12-13 14:52:54 -0800134 if (writeBus == 0xFFFF && writeAddr == 0xFF)
James Feist25690252019-12-23 12:25:49 -0800135 {
136 return true;
137 }
Vernon Mauery15419dd2019-05-24 09:40:30 -0700138 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Patrick Williamsf944d2e2022-07-22 19:26:52 -0500139 sdbusplus::message_t writeFru = dbus->new_method_call(
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700140 fruDeviceServiceName, "/xyz/openbmc_project/FruDevice",
141 "xyz.openbmc_project.FruDeviceManager", "WriteFru");
James Feist25690252019-12-23 12:25:49 -0800142 writeFru.append(writeBus, writeAddr, fruCache);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700143 try
144 {
Patrick Williamsf944d2e2022-07-22 19:26:52 -0500145 sdbusplus::message_t writeFruResp = dbus->call(writeFru);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700146 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500147 catch (const sdbusplus::exception_t&)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700148 {
149 // todo: log sel?
150 phosphor::logging::log<phosphor::logging::level::ERR>(
151 "error writing fru");
152 return false;
153 }
Johnathan Mantey07574002022-12-13 14:52:54 -0800154 writeBus = 0xFFFF;
James Feist25690252019-12-23 12:25:49 -0800155 writeAddr = 0xFF;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700156 return true;
157}
158
James Feist25690252019-12-23 12:25:49 -0800159void createTimers()
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700160{
James Feist25690252019-12-23 12:25:49 -0800161 writeTimer = std::make_unique<phosphor::Timer>(writeFru);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700162}
163
James Feiste4f710d2020-05-20 15:50:30 -0700164void recalculateHashes()
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700165{
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700166 deviceHashes.clear();
Archana Kakanif23fd542021-09-16 05:05:10 +0000167 devicePath.clear();
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700168 // hash the object paths to create unique device id's. increment on
169 // collision
170 std::hash<std::string> hasher;
171 for (const auto& fru : frus)
172 {
173 auto fruIface = fru.second.find("xyz.openbmc_project.FruDevice");
174 if (fruIface == fru.second.end())
175 {
176 continue;
177 }
178
179 auto busFind = fruIface->second.find("BUS");
180 auto addrFind = fruIface->second.find("ADDRESS");
181 if (busFind == fruIface->second.end() ||
182 addrFind == fruIface->second.end())
183 {
184 phosphor::logging::log<phosphor::logging::level::INFO>(
185 "fru device missing Bus or Address",
186 phosphor::logging::entry("FRU=%s", fru.first.str.c_str()));
187 continue;
188 }
189
Johnathan Mantey07574002022-12-13 14:52:54 -0800190 uint16_t fruBus = std::get<uint32_t>(busFind->second);
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700191 uint8_t fruAddr = std::get<uint32_t>(addrFind->second);
Anoop S358e7df2020-05-05 16:43:34 +0000192 auto chassisFind = fruIface->second.find("CHASSIS_TYPE");
193 std::string chassisType;
194 if (chassisFind != fruIface->second.end())
195 {
196 chassisType = std::get<std::string>(chassisFind->second);
197 }
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700198
199 uint8_t fruHash = 0;
Anoop S358e7df2020-05-05 16:43:34 +0000200 if (chassisType.compare(chassisTypeRackMount) != 0)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700201 {
202 fruHash = hasher(fru.first.str);
203 // can't be 0xFF based on spec, and 0 is reserved for baseboard
204 if (fruHash == 0 || fruHash == 0xFF)
205 {
206 fruHash = 1;
207 }
208 }
Johnathan Mantey07574002022-12-13 14:52:54 -0800209 std::pair<uint16_t, uint8_t> newDev(fruBus, fruAddr);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700210
211 bool emplacePassed = false;
212 while (!emplacePassed)
213 {
214 auto resp = deviceHashes.emplace(fruHash, newDev);
Archana Kakanif23fd542021-09-16 05:05:10 +0000215
216 devicePath.emplace(fruHash, fru.first);
217
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700218 emplacePassed = resp.second;
219 if (!emplacePassed)
220 {
221 fruHash++;
222 // can't be 0xFF based on spec, and 0 is reserved for
223 // baseboard
224 if (fruHash == 0XFF)
225 {
226 fruHash = 0x1;
227 }
228 }
229 }
230 }
James Feiste4f710d2020-05-20 15:50:30 -0700231}
232
233void replaceCacheFru(const std::shared_ptr<sdbusplus::asio::connection>& bus,
Archana Kakanif23fd542021-09-16 05:05:10 +0000234 boost::asio::yield_context& yield)
James Feiste4f710d2020-05-20 15:50:30 -0700235{
236 boost::system::error_code ec;
Archana Kakanif23fd542021-09-16 05:05:10 +0000237 // ObjectPaths and Services which implements "xyz.openbmc_project.FruDevice"
238 // interface
239 GetSubTreeType fruServices = bus->yield_method_call<GetSubTreeType>(
240 yield, ec, "xyz.openbmc_project.ObjectMapper",
241 "/xyz/openbmc_project/object_mapper",
242 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
243 std::array<const char*, 1>{"xyz.openbmc_project.FruDevice"});
James Feiste4f710d2020-05-20 15:50:30 -0700244
James Feiste4f710d2020-05-20 15:50:30 -0700245 if (ec)
246 {
247 phosphor::logging::log<phosphor::logging::level::ERR>(
Archana Kakanif23fd542021-09-16 05:05:10 +0000248 "GetSubTree failed for FruDevice Interface ",
James Feiste4f710d2020-05-20 15:50:30 -0700249 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
250
251 return;
252 }
Archana Kakanif23fd542021-09-16 05:05:10 +0000253 // Get List of services which have implemented FruDevice interface
254 std::unordered_set<std::string> services;
255 for (const auto& [path, serviceMap] : fruServices)
256 {
257 for (const auto& [service, interfaces] : serviceMap)
258 {
259 services.insert(service);
260 }
261 }
262
263 // GetAll the objects under services which implement FruDevice interface
264 for (const std::string& service : services)
265 {
266 ec = boost::system::errc::make_error_code(boost::system::errc::success);
267 ManagedObjectType obj = bus->yield_method_call<ManagedObjectType>(
268 yield, ec, service, "/", "org.freedesktop.DBus.ObjectManager",
269 "GetManagedObjects");
270 if (ec)
271 {
272 phosphor::logging::log<phosphor::logging::level::ERR>(
273 "GetMangagedObjects failed",
274 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
275 continue;
276 }
277 // Save the object path which has FruDevice interface
278 for (const auto& [path, serviceMap] : fruServices)
279 {
280 for (const auto& serv : serviceMap)
281 {
282 if (serv.first == service)
283 {
284 auto fru = obj.find(path);
285 if (fru == obj.end())
286 {
287 continue;
288 }
289 frus.emplace(fru->first, fru->second);
290 }
291 }
292 }
293 }
294
James Feiste4f710d2020-05-20 15:50:30 -0700295 recalculateHashes();
296}
297
298ipmi::Cc getFru(ipmi::Context::ptr ctx, uint8_t devId)
299{
300 if (lastDevId == devId && devId != 0xFF)
301 {
302 return ipmi::ccSuccess;
303 }
304
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700305 auto deviceFind = deviceHashes.find(devId);
Archana Kakanif23fd542021-09-16 05:05:10 +0000306 auto devPath = devicePath.find(devId);
307 if (deviceFind == deviceHashes.end() || devPath == devicePath.end())
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700308 {
309 return IPMI_CC_SENSOR_INVALID;
310 }
311
312 fruCache.clear();
James Feist25690252019-12-23 12:25:49 -0800313
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700314 cacheBus = deviceFind->second.first;
315 cacheAddr = deviceFind->second.second;
James Feist25690252019-12-23 12:25:49 -0800316
James Feiste4f710d2020-05-20 15:50:30 -0700317 boost::system::error_code ec;
Archana Kakanif23fd542021-09-16 05:05:10 +0000318 GetObjectType fruService = ctx->bus->yield_method_call<GetObjectType>(
319 ctx->yield, ec, "xyz.openbmc_project.ObjectMapper",
320 "/xyz/openbmc_project/object_mapper",
321 "xyz.openbmc_project.ObjectMapper", "GetObject", devPath->second,
322 std::array<const char*, 1>{"xyz.openbmc_project.FruDevice"});
James Feiste4f710d2020-05-20 15:50:30 -0700323
James Feist25690252019-12-23 12:25:49 -0800324 if (ec)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700325 {
James Feist25690252019-12-23 12:25:49 -0800326 phosphor::logging::log<phosphor::logging::level::ERR>(
Archana Kakanif23fd542021-09-16 05:05:10 +0000327 "Couldn't get raw fru because of service",
328 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
329 return ipmi::ccResponseError;
330 }
331
332 bool foundFru = false;
333 for (auto& service : fruService)
334 {
335 fruCache = ctx->bus->yield_method_call<std::vector<uint8_t>>(
336 ctx->yield, ec, service.first, "/xyz/openbmc_project/FruDevice",
337 "xyz.openbmc_project.FruDeviceManager", "GetRawFru", cacheBus,
338 cacheAddr);
339
340 if (!ec)
341 {
342 foundFru = true;
343 break;
344 }
345 }
346
347 if (!foundFru)
348 {
349 phosphor::logging::log<phosphor::logging::level::ERR>(
James Feist25690252019-12-23 12:25:49 -0800350 "Couldn't get raw fru",
351 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
Johnathan Mantey07574002022-12-13 14:52:54 -0800352 cacheBus = 0xFFFF;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700353 cacheAddr = 0xFF;
James Feist25690252019-12-23 12:25:49 -0800354 return ipmi::ccResponseError;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700355 }
356
357 lastDevId = devId;
James Feist25690252019-12-23 12:25:49 -0800358 return ipmi::ccSuccess;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700359}
360
James Feiste4f710d2020-05-20 15:50:30 -0700361void writeFruIfRunning()
362{
363 if (!writeTimer->isRunning())
364 {
365 return;
366 }
367 writeTimer->stop();
368 writeFru();
369}
370
371void startMatch(void)
372{
373 if (fruMatches.size())
374 {
375 return;
376 }
377
378 fruMatches.reserve(2);
379
380 auto bus = getSdBus();
381 fruMatches.emplace_back(*bus,
382 "type='signal',arg0path='/xyz/openbmc_project/"
383 "FruDevice/',member='InterfacesAdded'",
Patrick Williamsf944d2e2022-07-22 19:26:52 -0500384 [](sdbusplus::message_t& message) {
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500385 sdbusplus::message::object_path path;
386 ObjectType object;
387 try
388 {
389 message.read(path, object);
390 }
391 catch (const sdbusplus::exception_t&)
392 {
393 return;
394 }
395 auto findType = object.find("xyz.openbmc_project.FruDevice");
396 if (findType == object.end())
397 {
398 return;
399 }
400 writeFruIfRunning();
401 frus[path] = object;
402 recalculateHashes();
403 lastDevId = 0xFF;
404 });
James Feiste4f710d2020-05-20 15:50:30 -0700405
406 fruMatches.emplace_back(*bus,
407 "type='signal',arg0path='/xyz/openbmc_project/"
408 "FruDevice/',member='InterfacesRemoved'",
Patrick Williamsf944d2e2022-07-22 19:26:52 -0500409 [](sdbusplus::message_t& message) {
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500410 sdbusplus::message::object_path path;
411 std::set<std::string> interfaces;
412 try
413 {
414 message.read(path, interfaces);
415 }
416 catch (const sdbusplus::exception_t&)
417 {
418 return;
419 }
420 auto findType = interfaces.find("xyz.openbmc_project.FruDevice");
421 if (findType == interfaces.end())
422 {
423 return;
424 }
425 writeFruIfRunning();
426 frus.erase(path);
427 recalculateHashes();
428 lastDevId = 0xFF;
429 });
James Feiste4f710d2020-05-20 15:50:30 -0700430
431 // call once to populate
432 boost::asio::spawn(*getIoContext(), [](boost::asio::yield_context yield) {
433 replaceCacheFru(getSdBus(), yield);
434 });
435}
436
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000437/** @brief implements the read FRU data command
438 * @param fruDeviceId - FRU Device ID
439 * @param fruInventoryOffset - FRU Inventory Offset to write
440 * @param countToRead - Count to read
441 *
442 * @returns ipmi completion code plus response data
443 * - countWritten - Count written
444 */
445ipmi::RspType<uint8_t, // Count
446 std::vector<uint8_t> // Requested data
447 >
James Feist25690252019-12-23 12:25:49 -0800448 ipmiStorageReadFruData(ipmi::Context::ptr ctx, uint8_t fruDeviceId,
449 uint16_t fruInventoryOffset, uint8_t countToRead)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700450{
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000451 if (fruDeviceId == 0xFF)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700452 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000453 return ipmi::responseInvalidFieldRequest();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700454 }
455
James Feiste4f710d2020-05-20 15:50:30 -0700456 ipmi::Cc status = getFru(ctx, fruDeviceId);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700457
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000458 if (status != ipmi::ccSuccess)
459 {
460 return ipmi::response(status);
461 }
462
463 size_t fromFruByteLen = 0;
464 if (countToRead + fruInventoryOffset < fruCache.size())
465 {
466 fromFruByteLen = countToRead;
467 }
468 else if (fruCache.size() > fruInventoryOffset)
469 {
470 fromFruByteLen = fruCache.size() - fruInventoryOffset;
471 }
472 else
473 {
srikanta mondal92108382020-02-27 18:53:20 +0000474 return ipmi::responseReqDataLenExceeded();
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000475 }
476
477 std::vector<uint8_t> requestedData;
478
479 requestedData.insert(
480 requestedData.begin(), fruCache.begin() + fruInventoryOffset,
481 fruCache.begin() + fruInventoryOffset + fromFruByteLen);
482
Patrick Venture70b17f92019-10-28 20:01:53 -0700483 return ipmi::responseSuccess(static_cast<uint8_t>(requestedData.size()),
484 requestedData);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700485}
486
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000487/** @brief implements the write FRU data command
488 * @param fruDeviceId - FRU Device ID
489 * @param fruInventoryOffset - FRU Inventory Offset to write
490 * @param dataToWrite - Data to write
491 *
492 * @returns ipmi completion code plus response data
493 * - countWritten - Count written
494 */
495ipmi::RspType<uint8_t>
James Feist25690252019-12-23 12:25:49 -0800496 ipmiStorageWriteFruData(ipmi::Context::ptr ctx, uint8_t fruDeviceId,
497 uint16_t fruInventoryOffset,
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000498 std::vector<uint8_t>& dataToWrite)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700499{
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000500 if (fruDeviceId == 0xFF)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700501 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000502 return ipmi::responseInvalidFieldRequest();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700503 }
504
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000505 size_t writeLen = dataToWrite.size();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700506
James Feiste4f710d2020-05-20 15:50:30 -0700507 ipmi::Cc status = getFru(ctx, fruDeviceId);
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000508 if (status != ipmi::ccSuccess)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700509 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000510 return ipmi::response(status);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700511 }
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000512 int lastWriteAddr = fruInventoryOffset + writeLen;
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700513 if (fruCache.size() < lastWriteAddr)
514 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000515 fruCache.resize(fruInventoryOffset + writeLen);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700516 }
517
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000518 std::copy(dataToWrite.begin(), dataToWrite.begin() + writeLen,
519 fruCache.begin() + fruInventoryOffset);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700520
521 bool atEnd = false;
522
523 if (fruCache.size() >= sizeof(FRUHeader))
524 {
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700525 FRUHeader* header = reinterpret_cast<FRUHeader*>(fruCache.data());
526
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800527 int areaLength = 0;
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700528 int lastRecordStart = std::max(
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800529 {header->internalOffset, header->chassisOffset, header->boardOffset,
530 header->productOffset, header->multiRecordOffset});
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700531 lastRecordStart *= 8; // header starts in are multiples of 8 bytes
532
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800533 if (header->multiRecordOffset)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700534 {
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800535 // This FRU has a MultiRecord Area
536 uint8_t endOfList = 0;
537 // Walk the MultiRecord headers until the last record
538 while (!endOfList)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700539 {
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800540 // The MSB in the second byte of the MultiRecord header signals
541 // "End of list"
542 endOfList = fruCache[lastRecordStart + 1] & 0x80;
543 // Third byte in the MultiRecord header is the length
544 areaLength = fruCache[lastRecordStart + 2];
545 // This length is in bytes (not 8 bytes like other headers)
546 areaLength += 5; // The length omits the 5 byte header
547 if (!endOfList)
548 {
549 // Next MultiRecord header
550 lastRecordStart += areaLength;
551 }
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700552 }
553 }
Peter Lundgrenc59391f2019-11-19 14:26:15 -0800554 else
555 {
556 // This FRU does not have a MultiRecord Area
557 // Get the length of the area in multiples of 8 bytes
558 if (lastWriteAddr > (lastRecordStart + 1))
559 {
560 // second byte in record area is the length
561 areaLength = fruCache[lastRecordStart + 1];
562 areaLength *= 8; // it is in multiples of 8 bytes
563 }
564 }
565 if (lastWriteAddr >= (areaLength + lastRecordStart))
566 {
567 atEnd = true;
568 }
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700569 }
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000570 uint8_t countWritten = 0;
James Feist25690252019-12-23 12:25:49 -0800571
572 writeBus = cacheBus;
573 writeAddr = cacheAddr;
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700574 if (atEnd)
575 {
576 // cancel timer, we're at the end so might as well send it
James Feist25690252019-12-23 12:25:49 -0800577 writeTimer->stop();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700578 if (!writeFru())
579 {
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000580 return ipmi::responseInvalidFieldRequest();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700581 }
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000582 countWritten = std::min(fruCache.size(), static_cast<size_t>(0xFF));
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700583 }
584 else
585 {
James Feist25690252019-12-23 12:25:49 -0800586 // start a timer, if no further data is sent to check to see if it is
587 // valid
588 writeTimer->start(std::chrono::duration_cast<std::chrono::microseconds>(
589 std::chrono::seconds(writeTimeoutSeconds)));
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000590 countWritten = 0;
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700591 }
592
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +0000593 return ipmi::responseSuccess(countWritten);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700594}
595
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000596/** @brief implements the get FRU inventory area info command
597 * @param fruDeviceId - FRU Device ID
598 *
599 * @returns IPMI completion code plus response data
600 * - inventorySize - Number of possible allocation units
601 * - accessType - Allocation unit size in bytes.
602 */
603ipmi::RspType<uint16_t, // inventorySize
604 uint8_t> // accessType
James Feist25690252019-12-23 12:25:49 -0800605 ipmiStorageGetFruInvAreaInfo(ipmi::Context::ptr ctx, uint8_t fruDeviceId)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700606{
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000607 if (fruDeviceId == 0xFF)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700608 {
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000609 return ipmi::responseInvalidFieldRequest();
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700610 }
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700611
Jayaprakash Mutyala1e2ab062020-08-03 16:57:00 +0000612 ipmi::Cc ret = getFru(ctx, fruDeviceId);
613 if (ret != ipmi::ccSuccess)
614 {
615 return ipmi::response(ret);
616 }
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700617
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000618 constexpr uint8_t accessType =
619 static_cast<uint8_t>(GetFRUAreaAccessType::byte);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700620
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +0000621 return ipmi::responseSuccess(fruCache.size(), accessType);
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700622}
623
James Feist25690252019-12-23 12:25:49 -0800624ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700625{
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700626 count = deviceHashes.size();
627 return IPMI_CC_OK;
628}
629
James Feist25690252019-12-23 12:25:49 -0800630ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index,
631 get_sdr::SensorDataFruRecord& resp)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700632{
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700633 if (deviceHashes.size() < index)
634 {
635 return IPMI_CC_INVALID_FIELD_REQUEST;
636 }
637 auto device = deviceHashes.begin() + index;
Johnathan Mantey07574002022-12-13 14:52:54 -0800638 uint16_t& bus = device->second.first;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700639 uint8_t& address = device->second.second;
640
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700641 boost::container::flat_map<std::string, DbusVariant>* fruData = nullptr;
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500642 auto fru = std::find_if(frus.begin(), frus.end(),
643 [bus, address, &fruData](ManagedEntry& entry) {
644 auto findFruDevice = entry.second.find("xyz.openbmc_project.FruDevice");
645 if (findFruDevice == entry.second.end())
646 {
647 return false;
648 }
649 fruData = &(findFruDevice->second);
650 auto findBus = findFruDevice->second.find("BUS");
651 auto findAddress = findFruDevice->second.find("ADDRESS");
652 if (findBus == findFruDevice->second.end() ||
653 findAddress == findFruDevice->second.end())
654 {
655 return false;
656 }
657 if (std::get<uint32_t>(findBus->second) != bus)
658 {
659 return false;
660 }
661 if (std::get<uint32_t>(findAddress->second) != address)
662 {
663 return false;
664 }
665 return true;
666 });
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700667 if (fru == frus.end())
668 {
669 return IPMI_CC_RESPONSE_ERROR;
670 }
Patrick Venture9ce789f2019-10-17 09:09:39 -0700671
James Feist25690252019-12-23 12:25:49 -0800672#ifdef USING_ENTITY_MANAGER_DECORATORS
673
Patrick Venture9ce789f2019-10-17 09:09:39 -0700674 boost::container::flat_map<std::string, DbusVariant>* entityData = nullptr;
Patrick Venture9ce789f2019-10-17 09:09:39 -0700675
James Feist25690252019-12-23 12:25:49 -0800676 // todo: this should really use caching, this is a very inefficient lookup
677 boost::system::error_code ec;
678 ManagedObjectType entities = ctx->bus->yield_method_call<ManagedObjectType>(
Nan Zhou9d2894d2022-09-20 22:22:00 +0000679 ctx->yield, ec, "xyz.openbmc_project.EntityManager",
680 "/xyz/openbmc_project/inventory", "org.freedesktop.DBus.ObjectManager",
681 "GetManagedObjects");
James Feist25690252019-12-23 12:25:49 -0800682
683 if (ec)
Patrick Venture9ce789f2019-10-17 09:09:39 -0700684 {
James Feist25690252019-12-23 12:25:49 -0800685 phosphor::logging::log<phosphor::logging::level::ERR>(
686 "GetMangagedObjects for getSensorMap failed",
687 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
Patrick Venture9ce789f2019-10-17 09:09:39 -0700688
James Feist25690252019-12-23 12:25:49 -0800689 return ipmi::ccResponseError;
690 }
Patrick Venture9ce789f2019-10-17 09:09:39 -0700691
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500692 auto entity =
693 std::find_if(entities.begin(), entities.end(),
694 [bus, address, &entityData](ManagedEntry& entry) {
695 auto findFruDevice = entry.second.find(
696 "xyz.openbmc_project.Inventory.Decorator.FruDevice");
697 if (findFruDevice == entry.second.end())
698 {
699 return false;
700 }
James Feist25690252019-12-23 12:25:49 -0800701
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500702 // Integer fields added via Entity-Manager json are uint64_ts by
703 // default.
704 auto findBus = findFruDevice->second.find("Bus");
705 auto findAddress = findFruDevice->second.find("Address");
James Feist25690252019-12-23 12:25:49 -0800706
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500707 if (findBus == findFruDevice->second.end() ||
708 findAddress == findFruDevice->second.end())
709 {
710 return false;
711 }
712 if ((std::get<uint64_t>(findBus->second) != bus) ||
713 (std::get<uint64_t>(findAddress->second) != address))
714 {
715 return false;
716 }
James Feist25690252019-12-23 12:25:49 -0800717
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500718 // At this point we found the device entry and should return
719 // true.
720 auto findIpmiDevice =
721 entry.second.find("xyz.openbmc_project.Inventory.Decorator.Ipmi");
722 if (findIpmiDevice != entry.second.end())
723 {
724 entityData = &(findIpmiDevice->second);
725 }
James Feist25690252019-12-23 12:25:49 -0800726
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500727 return true;
James Feist25690252019-12-23 12:25:49 -0800728 });
729
730 if (entity == entities.end())
731 {
732 if constexpr (DEBUG)
733 {
734 std::fprintf(stderr, "Ipmi or FruDevice Decorator interface "
735 "not found for Fru\n");
Patrick Venture9ce789f2019-10-17 09:09:39 -0700736 }
737 }
James Feist25690252019-12-23 12:25:49 -0800738
739#endif
Patrick Venture9ce789f2019-10-17 09:09:39 -0700740
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700741 std::string name;
742 auto findProductName = fruData->find("BOARD_PRODUCT_NAME");
743 auto findBoardName = fruData->find("PRODUCT_PRODUCT_NAME");
744 if (findProductName != fruData->end())
745 {
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700746 name = std::get<std::string>(findProductName->second);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700747 }
748 else if (findBoardName != fruData->end())
749 {
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700750 name = std::get<std::string>(findBoardName->second);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700751 }
752 else
753 {
754 name = "UNKNOWN";
755 }
756 if (name.size() > maxFruSdrNameSize)
757 {
758 name = name.substr(0, maxFruSdrNameSize);
759 }
760 size_t sizeDiff = maxFruSdrNameSize - name.size();
761
762 resp.header.record_id_lsb = 0x0; // calling code is to implement these
763 resp.header.record_id_msb = 0x0;
764 resp.header.sdr_version = ipmiSdrVersion;
Patrick Venture73d01352019-10-11 18:32:59 -0700765 resp.header.record_type = get_sdr::SENSOR_DATA_FRU_RECORD;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700766 resp.header.record_length = sizeof(resp.body) + sizeof(resp.key) - sizeDiff;
767 resp.key.deviceAddress = 0x20;
768 resp.key.fruID = device->first;
769 resp.key.accessLun = 0x80; // logical / physical fru device
770 resp.key.channelNumber = 0x0;
771 resp.body.reserved = 0x0;
772 resp.body.deviceType = 0x10;
James Feist4f86d1f2019-04-03 10:30:26 -0700773 resp.body.deviceTypeModifier = 0x0;
Patrick Venture9ce789f2019-10-17 09:09:39 -0700774
775 uint8_t entityID = 0;
776 uint8_t entityInstance = 0x1;
777
James Feist25690252019-12-23 12:25:49 -0800778#ifdef USING_ENTITY_MANAGER_DECORATORS
Patrick Venture9ce789f2019-10-17 09:09:39 -0700779 if (entityData)
780 {
781 auto entityIdProperty = entityData->find("EntityId");
782 auto entityInstanceProperty = entityData->find("EntityInstance");
783
784 if (entityIdProperty != entityData->end())
785 {
786 entityID = static_cast<uint8_t>(
787 std::get<uint64_t>(entityIdProperty->second));
788 }
789 if (entityInstanceProperty != entityData->end())
790 {
791 entityInstance = static_cast<uint8_t>(
792 std::get<uint64_t>(entityInstanceProperty->second));
793 }
794 }
James Feist25690252019-12-23 12:25:49 -0800795#endif
Patrick Venture9ce789f2019-10-17 09:09:39 -0700796
797 resp.body.entityID = entityID;
798 resp.body.entityInstance = entityInstance;
799
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700800 resp.body.oem = 0x0;
801 resp.body.deviceIDLen = name.size();
802 name.copy(resp.body.deviceID, name.size());
803
804 return IPMI_CC_OK;
805}
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700806
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700807static bool getSELLogFiles(std::vector<std::filesystem::path>& selLogFiles)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800808{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700809 // Loop through the directory looking for ipmi_sel log files
810 for (const std::filesystem::directory_entry& dirEnt :
811 std::filesystem::directory_iterator(intel_oem::ipmi::sel::selLogDir))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800812 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700813 std::string filename = dirEnt.path().filename();
814 if (boost::starts_with(filename, intel_oem::ipmi::sel::selLogFilename))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800815 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700816 // If we find an ipmi_sel log file, save the path
817 selLogFiles.emplace_back(intel_oem::ipmi::sel::selLogDir /
818 filename);
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800819 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800820 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700821 // As the log files rotate, they are appended with a ".#" that is higher for
822 // the older logs. Since we don't expect more than 10 log files, we
823 // can just sort the list to get them in order from newest to oldest
824 std::sort(selLogFiles.begin(), selLogFiles.end());
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800825
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700826 return !selLogFiles.empty();
827}
828
829static int countSELEntries()
830{
831 // Get the list of ipmi_sel log files
832 std::vector<std::filesystem::path> selLogFiles;
833 if (!getSELLogFiles(selLogFiles))
834 {
835 return 0;
836 }
837 int numSELEntries = 0;
838 // Loop through each log file and count the number of logs
839 for (const std::filesystem::path& file : selLogFiles)
840 {
841 std::ifstream logStream(file);
842 if (!logStream.is_open())
843 {
844 continue;
845 }
846
847 std::string line;
848 while (std::getline(logStream, line))
849 {
850 numSELEntries++;
851 }
852 }
853 return numSELEntries;
854}
855
856static bool findSELEntry(const int recordID,
Patrick Ventureff7e15b2019-09-25 16:48:26 -0700857 const std::vector<std::filesystem::path>& selLogFiles,
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700858 std::string& entry)
859{
860 // Record ID is the first entry field following the timestamp. It is
861 // preceded by a space and followed by a comma
862 std::string search = " " + std::to_string(recordID) + ",";
863
864 // Loop through the ipmi_sel log entries
865 for (const std::filesystem::path& file : selLogFiles)
866 {
867 std::ifstream logStream(file);
868 if (!logStream.is_open())
869 {
870 continue;
871 }
872
873 while (std::getline(logStream, entry))
874 {
875 // Check if the record ID matches
876 if (entry.find(search) != std::string::npos)
877 {
878 return true;
879 }
880 }
881 }
882 return false;
883}
884
885static uint16_t
886 getNextRecordID(const uint16_t recordID,
Patrick Ventureff7e15b2019-09-25 16:48:26 -0700887 const std::vector<std::filesystem::path>& selLogFiles)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700888{
889 uint16_t nextRecordID = recordID + 1;
890 std::string entry;
891 if (findSELEntry(nextRecordID, selLogFiles, entry))
892 {
893 return nextRecordID;
894 }
895 else
896 {
897 return ipmi::sel::lastEntry;
898 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800899}
900
Patrick Ventureff7e15b2019-09-25 16:48:26 -0700901static int fromHexStr(const std::string& hexStr, std::vector<uint8_t>& data)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800902{
903 for (unsigned int i = 0; i < hexStr.size(); i += 2)
904 {
905 try
906 {
907 data.push_back(static_cast<uint8_t>(
908 std::stoul(hexStr.substr(i, 2), nullptr, 16)));
909 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500910 catch (const std::invalid_argument& e)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800911 {
912 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
913 return -1;
914 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500915 catch (const std::out_of_range& e)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800916 {
917 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
918 return -1;
919 }
920 }
921 return 0;
922}
923
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700924ipmi::RspType<uint8_t, // SEL version
925 uint16_t, // SEL entry count
926 uint16_t, // free space
927 uint32_t, // last add timestamp
928 uint32_t, // last erase timestamp
929 uint8_t> // operation support
930 ipmiStorageGetSELInfo()
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800931{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700932 constexpr uint8_t selVersion = ipmi::sel::selVersion;
933 uint16_t entries = countSELEntries();
934 uint32_t addTimeStamp = intel_oem::ipmi::sel::getFileTimestamp(
935 intel_oem::ipmi::sel::selLogDir / intel_oem::ipmi::sel::selLogFilename);
936 uint32_t eraseTimeStamp = intel_oem::ipmi::sel::erase_time::get();
937 constexpr uint8_t operationSupport =
938 intel_oem::ipmi::sel::selOperationSupport;
939 constexpr uint16_t freeSpace =
940 0xffff; // Spec indicates that more than 64kB is free
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800941
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700942 return ipmi::responseSuccess(selVersion, entries, freeSpace, addTimeStamp,
943 eraseTimeStamp, operationSupport);
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800944}
945
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700946using systemEventType = std::tuple<
947 uint32_t, // Timestamp
948 uint16_t, // Generator ID
949 uint8_t, // EvM Rev
950 uint8_t, // Sensor Type
951 uint8_t, // Sensor Number
952 uint7_t, // Event Type
953 bool, // Event Direction
954 std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize>>; // Event Data
955using oemTsEventType = std::tuple<
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500956 uint32_t, // Timestamp
957 std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize>>; // Event Data
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700958using oemEventType =
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500959 std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize>; // Event Data
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800960
Patrick Williamsb37abfb2023-05-10 07:50:33 -0500961ipmi::RspType<uint16_t, // Next Record ID
962 uint16_t, // Record ID
963 uint8_t, // Record Type
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700964 std::variant<systemEventType, oemTsEventType,
965 oemEventType>> // Record Content
966 ipmiStorageGetSELEntry(uint16_t reservationID, uint16_t targetID,
967 uint8_t offset, uint8_t size)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800968{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700969 // Only support getting the entire SEL record. If a partial size or non-zero
970 // offset is requested, return an error
971 if (offset != 0 || size != ipmi::sel::entireRecord)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800972 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700973 return ipmi::responseRetBytesUnavailable();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800974 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800975
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700976 // Check the reservation ID if one is provided or required (only if the
977 // offset is non-zero)
978 if (reservationID != 0 || offset != 0)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800979 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700980 if (!checkSELReservation(reservationID))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800981 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700982 return ipmi::responseInvalidReservationId();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800983 }
984 }
985
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700986 // Get the ipmi_sel log files
987 std::vector<std::filesystem::path> selLogFiles;
988 if (!getSELLogFiles(selLogFiles))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800989 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700990 return ipmi::responseSensorInvalid();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800991 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800992
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700993 std::string targetEntry;
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800994
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800995 if (targetID == ipmi::sel::firstEntry)
996 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700997 // The first entry will be at the top of the oldest log file
998 std::ifstream logStream(selLogFiles.back());
999 if (!logStream.is_open())
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001000 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001001 return ipmi::responseUnspecifiedError();
1002 }
1003
1004 if (!std::getline(logStream, targetEntry))
1005 {
1006 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001007 }
1008 }
1009 else if (targetID == ipmi::sel::lastEntry)
1010 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001011 // The last entry will be at the bottom of the newest log file
1012 std::ifstream logStream(selLogFiles.front());
1013 if (!logStream.is_open())
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001014 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001015 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001016 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001017
1018 std::string line;
1019 while (std::getline(logStream, line))
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001020 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001021 targetEntry = line;
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001022 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001023 }
1024 else
1025 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001026 if (!findSELEntry(targetID, selLogFiles, targetEntry))
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001027 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001028 return ipmi::responseSensorInvalid();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001029 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001030 }
1031
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001032 // The format of the ipmi_sel message is "<Timestamp>
1033 // <ID>,<Type>,<EventData>,[<Generator ID>,<Path>,<Direction>]".
1034 // First get the Timestamp
1035 size_t space = targetEntry.find_first_of(" ");
1036 if (space == std::string::npos)
1037 {
1038 return ipmi::responseUnspecifiedError();
1039 }
1040 std::string entryTimestamp = targetEntry.substr(0, space);
1041 // Then get the log contents
1042 size_t entryStart = targetEntry.find_first_not_of(" ", space);
1043 if (entryStart == std::string::npos)
1044 {
1045 return ipmi::responseUnspecifiedError();
1046 }
1047 std::string_view entry(targetEntry);
1048 entry.remove_prefix(entryStart);
1049 // Use split to separate the entry into its fields
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001050 std::vector<std::string> targetEntryFields;
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001051 boost::split(targetEntryFields, entry, boost::is_any_of(","),
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001052 boost::token_compress_on);
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001053 if (targetEntryFields.size() < 3)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001054 {
1055 return ipmi::responseUnspecifiedError();
1056 }
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001057 std::string& recordIDStr = targetEntryFields[0];
1058 std::string& recordTypeStr = targetEntryFields[1];
1059 std::string& eventDataStr = targetEntryFields[2];
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001060
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001061 uint16_t recordID;
1062 uint8_t recordType;
1063 try
1064 {
1065 recordID = std::stoul(recordIDStr);
1066 recordType = std::stoul(recordTypeStr, nullptr, 16);
1067 }
1068 catch (const std::invalid_argument&)
1069 {
1070 return ipmi::responseUnspecifiedError();
1071 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001072 uint16_t nextRecordID = getNextRecordID(recordID, selLogFiles);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001073 std::vector<uint8_t> eventDataBytes;
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001074 if (fromHexStr(eventDataStr, eventDataBytes) < 0)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001075 {
1076 return ipmi::responseUnspecifiedError();
1077 }
1078
1079 if (recordType == intel_oem::ipmi::sel::systemEvent)
1080 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001081 // Get the timestamp
1082 std::tm timeStruct = {};
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001083 std::istringstream entryStream(entryTimestamp);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001084
1085 uint32_t timestamp = ipmi::sel::invalidTimeStamp;
1086 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
1087 {
1088 timestamp = std::mktime(&timeStruct);
1089 }
1090
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001091 // Set the event message revision
1092 uint8_t evmRev = intel_oem::ipmi::sel::eventMsgRev;
1093
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001094 uint16_t generatorID = 0;
1095 uint8_t sensorType = 0;
Johnathan Mantey308c3a82020-07-22 11:50:54 -07001096 uint16_t sensorAndLun = 0;
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001097 uint8_t sensorNum = 0xFF;
1098 uint7_t eventType = 0;
1099 bool eventDir = 0;
1100 // System type events should have six fields
1101 if (targetEntryFields.size() >= 6)
1102 {
1103 std::string& generatorIDStr = targetEntryFields[3];
1104 std::string& sensorPath = targetEntryFields[4];
1105 std::string& eventDirStr = targetEntryFields[5];
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001106
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001107 // Get the generator ID
1108 try
1109 {
1110 generatorID = std::stoul(generatorIDStr, nullptr, 16);
1111 }
1112 catch (const std::invalid_argument&)
1113 {
1114 std::cerr << "Invalid Generator ID\n";
1115 }
1116
1117 // Get the sensor type, sensor number, and event type for the sensor
1118 sensorType = getSensorTypeFromPath(sensorPath);
Johnathan Mantey308c3a82020-07-22 11:50:54 -07001119 sensorAndLun = getSensorNumberFromPath(sensorPath);
1120 sensorNum = static_cast<uint8_t>(sensorAndLun);
1121 generatorID |= sensorAndLun >> 8;
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -07001122 eventType = getSensorEventTypeFromPath(sensorPath);
1123
1124 // Get the event direction
1125 try
1126 {
1127 eventDir = std::stoul(eventDirStr) ? 0 : 1;
1128 }
1129 catch (const std::invalid_argument&)
1130 {
1131 std::cerr << "Invalid Event Direction\n";
1132 }
1133 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001134
1135 // Only keep the eventData bytes that fit in the record
1136 std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize> eventData{};
1137 std::copy_n(eventDataBytes.begin(),
1138 std::min(eventDataBytes.size(), eventData.size()),
1139 eventData.begin());
1140
1141 return ipmi::responseSuccess(
1142 nextRecordID, recordID, recordType,
1143 systemEventType{timestamp, generatorID, evmRev, sensorType,
1144 sensorNum, eventType, eventDir, eventData});
1145 }
1146 else if (recordType >= intel_oem::ipmi::sel::oemTsEventFirst &&
1147 recordType <= intel_oem::ipmi::sel::oemTsEventLast)
1148 {
1149 // Get the timestamp
1150 std::tm timeStruct = {};
Jason M. Bills52aaa7d2019-05-08 15:21:39 -07001151 std::istringstream entryStream(entryTimestamp);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001152
1153 uint32_t timestamp = ipmi::sel::invalidTimeStamp;
1154 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
1155 {
1156 timestamp = std::mktime(&timeStruct);
1157 }
1158
1159 // Only keep the bytes that fit in the record
1160 std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize> eventData{};
1161 std::copy_n(eventDataBytes.begin(),
1162 std::min(eventDataBytes.size(), eventData.size()),
1163 eventData.begin());
1164
1165 return ipmi::responseSuccess(nextRecordID, recordID, recordType,
1166 oemTsEventType{timestamp, eventData});
1167 }
Patrick Venturec5136aa2019-10-04 20:39:31 -07001168 else if (recordType >= intel_oem::ipmi::sel::oemEventFirst)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001169 {
1170 // Only keep the bytes that fit in the record
1171 std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize> eventData{};
1172 std::copy_n(eventDataBytes.begin(),
1173 std::min(eventDataBytes.size(), eventData.size()),
1174 eventData.begin());
1175
1176 return ipmi::responseSuccess(nextRecordID, recordID, recordType,
1177 eventData);
1178 }
1179
1180 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001181}
1182
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001183ipmi::RspType<uint16_t> ipmiStorageAddSELEntry(
1184 uint16_t recordID, uint8_t recordType, uint32_t timestamp,
1185 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType, uint8_t sensorNum,
1186 uint8_t eventType, uint8_t eventData1, uint8_t eventData2,
1187 uint8_t eventData3)
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001188{
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001189 // Per the IPMI spec, need to cancel any reservation when a SEL entry is
1190 // added
1191 cancelSELReservation();
1192
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001193 // Send this request to the Redfish hooks to log it as a Redfish message
1194 // instead. There is no need to add it to the SEL, so just return success.
1195 intel_oem::ipmi::sel::checkRedfishHooks(
1196 recordID, recordType, timestamp, generatorID, evmRev, sensorType,
1197 sensorNum, eventType, eventData1, eventData2, eventData3);
Jason M. Bills99b78ec2019-01-18 10:42:18 -08001198
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001199 uint16_t responseID = 0xFFFF;
1200 return ipmi::responseSuccess(responseID);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001201}
1202
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001203ipmi::RspType<uint8_t> ipmiStorageClearSEL(ipmi::Context::ptr ctx,
1204 uint16_t reservationID,
1205 const std::array<uint8_t, 3>& clr,
1206 uint8_t eraseOperation)
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001207{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001208 if (!checkSELReservation(reservationID))
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001209 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001210 return ipmi::responseInvalidReservationId();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001211 }
1212
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001213 static constexpr std::array<uint8_t, 3> clrExpected = {'C', 'L', 'R'};
1214 if (clr != clrExpected)
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001215 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001216 return ipmi::responseInvalidFieldRequest();
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001217 }
1218
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001219 // Erasure status cannot be fetched, so always return erasure status as
1220 // `erase completed`.
1221 if (eraseOperation == ipmi::sel::getEraseStatus)
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001222 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001223 return ipmi::responseSuccess(ipmi::sel::eraseComplete);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001224 }
1225
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001226 // Check that initiate erase is correct
1227 if (eraseOperation != ipmi::sel::initiateErase)
1228 {
1229 return ipmi::responseInvalidFieldRequest();
1230 }
1231
1232 // Per the IPMI spec, need to cancel any reservation when the SEL is
1233 // cleared
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001234 cancelSELReservation();
1235
Jason M. Bills7944c302019-03-20 15:24:05 -07001236 // Save the erase time
1237 intel_oem::ipmi::sel::erase_time::save();
1238
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001239 // Clear the SEL by deleting the log files
1240 std::vector<std::filesystem::path> selLogFiles;
1241 if (getSELLogFiles(selLogFiles))
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001242 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001243 for (const std::filesystem::path& file : selLogFiles)
1244 {
1245 std::error_code ec;
1246 std::filesystem::remove(file, ec);
1247 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001248 }
1249
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001250 // Reload rsyslog so it knows to start new log files
Vernon Mauery15419dd2019-05-24 09:40:30 -07001251 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Patrick Williamsf944d2e2022-07-22 19:26:52 -05001252 sdbusplus::message_t rsyslogReload = dbus->new_method_call(
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001253 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1254 "org.freedesktop.systemd1.Manager", "ReloadUnit");
1255 rsyslogReload.append("rsyslog.service", "replace");
1256 try
1257 {
Patrick Williamsf944d2e2022-07-22 19:26:52 -05001258 sdbusplus::message_t reloadResponse = dbus->call(rsyslogReload);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001259 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001260 catch (const sdbusplus::exception_t& e)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001261 {
1262 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1263 }
1264
1265 return ipmi::responseSuccess(ipmi::sel::eraseComplete);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001266}
1267
Jason M. Bills1a474622019-06-14 14:51:33 -07001268ipmi::RspType<uint32_t> ipmiStorageGetSELTime()
1269{
1270 struct timespec selTime = {};
1271
1272 if (clock_gettime(CLOCK_REALTIME, &selTime) < 0)
1273 {
1274 return ipmi::responseUnspecifiedError();
1275 }
1276
1277 return ipmi::responseSuccess(selTime.tv_sec);
1278}
1279
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001280ipmi::RspType<> ipmiStorageSetSELTime(uint32_t selTime)
Jason M. Billscac97a52019-01-30 14:43:46 -08001281{
1282 // Set SEL Time is not supported
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001283 return ipmi::responseInvalidCommand();
Jason M. Billscac97a52019-01-30 14:43:46 -08001284}
1285
James Feist74c50c62019-08-14 14:18:41 -07001286std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId)
1287{
1288 std::vector<uint8_t> resp;
1289 if (index == 0)
1290 {
James Feist74c50c62019-08-14 14:18:41 -07001291 std::string bmcName = "Basbrd Mgmt Ctlr";
Johnathan Manteyf4d5e052021-09-22 12:58:08 -07001292 Type12Record bmc(recordId, 0x20, 0, 0, 0xbf, 0x2e, 1, 0, bmcName);
James Feist74c50c62019-08-14 14:18:41 -07001293 uint8_t* bmcPtr = reinterpret_cast<uint8_t*>(&bmc);
1294 resp.insert(resp.end(), bmcPtr, bmcPtr + sizeof(Type12Record));
1295 }
1296 else if (index == 1)
1297 {
James Feist74c50c62019-08-14 14:18:41 -07001298 std::string meName = "Mgmt Engine";
Johnathan Manteyf4d5e052021-09-22 12:58:08 -07001299 Type12Record me(recordId, 0x2c, 6, 0x24, 0x21, 0x2e, 2, 0, meName);
James Feist74c50c62019-08-14 14:18:41 -07001300 uint8_t* mePtr = reinterpret_cast<uint8_t*>(&me);
1301 resp.insert(resp.end(), mePtr, mePtr + sizeof(Type12Record));
1302 }
1303 else
1304 {
1305 throw std::runtime_error("getType12SDRs:: Illegal index " +
1306 std::to_string(index));
1307 }
1308
1309 return resp;
1310}
1311
Yong Lifee5e4c2020-01-17 19:36:29 +08001312std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId)
1313{
1314 std::vector<uint8_t> resp;
1315 if (index == 0)
1316 {
1317 NMDiscoveryRecord nm = {};
1318 nm.header.record_id_lsb = recordId;
1319 nm.header.record_id_msb = recordId >> 8;
1320 nm.header.sdr_version = ipmiSdrVersion;
1321 nm.header.record_type = 0xC0;
1322 nm.header.record_length = 0xB;
1323 nm.oemID0 = 0x57;
1324 nm.oemID1 = 0x1;
1325 nm.oemID2 = 0x0;
1326 nm.subType = 0x0D;
1327 nm.version = 0x1;
Matt Simmering80d4d5f2023-02-15 15:18:51 -08001328 nm.targetAddress = 0x2C;
Yong Lifee5e4c2020-01-17 19:36:29 +08001329 nm.channelNumber = 0x60;
1330 nm.healthEventSensor = 0x19;
1331 nm.exceptionEventSensor = 0x18;
1332 nm.operationalCapSensor = 0x1A;
1333 nm.thresholdExceededSensor = 0x1B;
1334
1335 uint8_t* nmPtr = reinterpret_cast<uint8_t*>(&nm);
1336 resp.insert(resp.end(), nmPtr, nmPtr + sizeof(NMDiscoveryRecord));
1337 }
1338 else
1339 {
1340 throw std::runtime_error("getNMDiscoverySDR:: Illegal index " +
1341 std::to_string(index));
1342 }
1343
1344 return resp;
1345}
1346
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001347void registerStorageFunctions()
1348{
James Feist25690252019-12-23 12:25:49 -08001349 createTimers();
James Feiste4f710d2020-05-20 15:50:30 -07001350 startMatch();
1351
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001352 // <Get FRU Inventory Area Info>
jayaprakash Mutyalad33acd62019-05-17 19:37:25 +00001353 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage,
1354 ipmi::storage::cmdGetFruInventoryAreaInfo,
1355 ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001356 // <READ FRU Data>
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +00001357 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1358 ipmi::storage::cmdReadFruData, ipmi::Privilege::User,
1359 ipmiStorageReadFruData);
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001360
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001361 // <WRITE FRU Data>
jayaprakash Mutyala5f4194e2019-05-20 16:17:01 +00001362 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1363 ipmi::storage::cmdWriteFruData,
1364 ipmi::Privilege::Operator, ipmiStorageWriteFruData);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001365
1366 // <Get SEL Info>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001367 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
Jason M. Bills542498e2019-06-24 16:57:42 -07001368 ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
1369 ipmiStorageGetSELInfo);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001370
1371 // <Get SEL Entry>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001372 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
Jason M. Bills542498e2019-06-24 16:57:42 -07001373 ipmi::storage::cmdGetSelEntry, ipmi::Privilege::User,
1374 ipmiStorageGetSELEntry);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001375
1376 // <Add SEL Entry>
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001377 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
Vernon Mauery98bbf692019-09-16 11:14:59 -07001378 ipmi::storage::cmdAddSelEntry,
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001379 ipmi::Privilege::Operator, ipmiStorageAddSELEntry);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001380
1381 // <Clear SEL>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001382 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1383 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
1384 ipmiStorageClearSEL);
Jason M. Billscac97a52019-01-30 14:43:46 -08001385
Jason M. Bills1a474622019-06-14 14:51:33 -07001386 // <Get SEL Time>
1387 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
Jason M. Bills542498e2019-06-24 16:57:42 -07001388 ipmi::storage::cmdGetSelTime, ipmi::Privilege::User,
1389 ipmiStorageGetSELTime);
Jason M. Bills1a474622019-06-14 14:51:33 -07001390
Jason M. Billscac97a52019-01-30 14:43:46 -08001391 // <Set SEL Time>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001392 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1393 ipmi::storage::cmdSetSelTime,
1394 ipmi::Privilege::Operator, ipmiStorageSetSELTime);
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001395}
Jason M. Bills3f7c5e42018-10-03 14:00:41 -07001396} // namespace storage
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001397} // namespace ipmi