blob: 30c68d6593e73327d3d22ce1f8fdd7e03c21b2bf [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
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070017#include <boost/algorithm/string.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070018#include <boost/container/flat_map.hpp>
Jason M. Billsc04e2e72018-11-28 15:15:56 -080019#include <boost/process.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070020#include <commandutils.hpp>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070021#include <filesystem>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070022#include <iostream>
Jason M. Bills99b78ec2019-01-18 10:42:18 -080023#include <ipmi_to_redfish_hooks.hpp>
James Feist2a265d52019-04-08 11:16:27 -070024#include <ipmid/api.hpp>
Jason M. Billsc04e2e72018-11-28 15:15:56 -080025#include <phosphor-ipmi-host/selutility.hpp>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070026#include <phosphor-logging/log.hpp>
27#include <sdbusplus/message/types.hpp>
28#include <sdbusplus/timer.hpp>
Jason M. Billsc04e2e72018-11-28 15:15:56 -080029#include <sdrutils.hpp>
30#include <stdexcept>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070031#include <storagecommands.hpp>
Jason M. Bills52aaa7d2019-05-08 15:21:39 -070032#include <string_view>
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070033
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070034namespace intel_oem::ipmi::sel
35{
36static const std::filesystem::path selLogDir = "/var/log";
37static const std::string selLogFilename = "ipmi_sel";
38
39static int getFileTimestamp(const std::filesystem::path& file)
40{
41 struct stat st;
42
43 if (stat(file.c_str(), &st) >= 0)
44 {
45 return st.st_mtime;
46 }
47 return ::ipmi::sel::invalidTimeStamp;
48}
49
50namespace erase_time
Jason M. Bills7944c302019-03-20 15:24:05 -070051{
52static constexpr const char* selEraseTimestamp = "/var/lib/ipmi/sel_erase_time";
53
54void save()
55{
56 // open the file, creating it if necessary
57 int fd = open(selEraseTimestamp, O_WRONLY | O_CREAT | O_CLOEXEC, 0644);
58 if (fd < 0)
59 {
60 std::cerr << "Failed to open file\n";
61 return;
62 }
63
64 // update the file timestamp to the current time
65 if (futimens(fd, NULL) < 0)
66 {
67 std::cerr << "Failed to update timestamp: "
68 << std::string(strerror(errno));
69 }
70 close(fd);
71}
72
73int get()
74{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070075 return getFileTimestamp(selEraseTimestamp);
Jason M. Bills7944c302019-03-20 15:24:05 -070076}
Jason M. Bills1d4d54d2019-04-23 11:26:11 -070077} // namespace erase_time
78} // namespace intel_oem::ipmi::sel
Jason M. Bills7944c302019-03-20 15:24:05 -070079
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070080namespace ipmi
81{
82
83namespace storage
84{
85
Jason M. Billse2d1aee2018-10-03 15:57:18 -070086constexpr static const size_t maxMessageSize = 64;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070087constexpr static const size_t maxFruSdrNameSize = 16;
88using ManagedObjectType = boost::container::flat_map<
89 sdbusplus::message::object_path,
90 boost::container::flat_map<
91 std::string, boost::container::flat_map<std::string, DbusVariant>>>;
92using ManagedEntry = std::pair<
93 sdbusplus::message::object_path,
94 boost::container::flat_map<
95 std::string, boost::container::flat_map<std::string, DbusVariant>>>;
96
James Feist3bcba452018-12-20 12:31:03 -080097constexpr static const char* fruDeviceServiceName =
98 "xyz.openbmc_project.FruDevice";
Jason M. Billse2d1aee2018-10-03 15:57:18 -070099constexpr static const size_t cacheTimeoutSeconds = 10;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700100
Jason M. Bills4ed6f2c2019-04-02 12:21:25 -0700101// event direction is bit[7] of eventType where 1b = Deassertion event
102constexpr static const uint8_t deassertionEvent = 0x80;
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800103
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700104static std::vector<uint8_t> fruCache;
105static uint8_t cacheBus = 0xFF;
106static uint8_t cacheAddr = 0XFF;
107
108std::unique_ptr<phosphor::Timer> cacheTimer = nullptr;
109
110// we unfortunately have to build a map of hashes in case there is a
111// collision to verify our dev-id
112boost::container::flat_map<uint8_t, std::pair<uint8_t, uint8_t>> deviceHashes;
113
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700114void registerStorageFunctions() __attribute__((constructor));
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700115
116bool writeFru()
117{
Vernon Mauery15419dd2019-05-24 09:40:30 -0700118 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
119 sdbusplus::message::message writeFru = dbus->new_method_call(
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700120 fruDeviceServiceName, "/xyz/openbmc_project/FruDevice",
121 "xyz.openbmc_project.FruDeviceManager", "WriteFru");
122 writeFru.append(cacheBus, cacheAddr, fruCache);
123 try
124 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700125 sdbusplus::message::message writeFruResp = dbus->call(writeFru);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700126 }
127 catch (sdbusplus::exception_t&)
128 {
129 // todo: log sel?
130 phosphor::logging::log<phosphor::logging::level::ERR>(
131 "error writing fru");
132 return false;
133 }
134 return true;
135}
136
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700137void createTimer()
138{
139 if (cacheTimer == nullptr)
140 {
141 cacheTimer = std::make_unique<phosphor::Timer>(writeFru);
142 }
143}
144
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700145ipmi_ret_t replaceCacheFru(uint8_t devId)
146{
147 static uint8_t lastDevId = 0xFF;
148
149 bool timerRunning = (cacheTimer != nullptr) && !cacheTimer->isExpired();
150 if (lastDevId == devId && timerRunning)
151 {
152 return IPMI_CC_OK; // cache already up to date
153 }
154 // if timer is running, stop it and writeFru manually
155 else if (timerRunning)
156 {
157 cacheTimer->stop();
158 writeFru();
159 }
160
Vernon Mauery15419dd2019-05-24 09:40:30 -0700161 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
162 sdbusplus::message::message getObjects = dbus->new_method_call(
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700163 fruDeviceServiceName, "/", "org.freedesktop.DBus.ObjectManager",
164 "GetManagedObjects");
165 ManagedObjectType frus;
166 try
167 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700168 sdbusplus::message::message resp = dbus->call(getObjects);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700169 resp.read(frus);
170 }
171 catch (sdbusplus::exception_t&)
172 {
173 phosphor::logging::log<phosphor::logging::level::ERR>(
174 "replaceCacheFru: error getting managed objects");
175 return IPMI_CC_RESPONSE_ERROR;
176 }
177
178 deviceHashes.clear();
179
180 // hash the object paths to create unique device id's. increment on
181 // collision
182 std::hash<std::string> hasher;
183 for (const auto& fru : frus)
184 {
185 auto fruIface = fru.second.find("xyz.openbmc_project.FruDevice");
186 if (fruIface == fru.second.end())
187 {
188 continue;
189 }
190
191 auto busFind = fruIface->second.find("BUS");
192 auto addrFind = fruIface->second.find("ADDRESS");
193 if (busFind == fruIface->second.end() ||
194 addrFind == fruIface->second.end())
195 {
196 phosphor::logging::log<phosphor::logging::level::INFO>(
197 "fru device missing Bus or Address",
198 phosphor::logging::entry("FRU=%s", fru.first.str.c_str()));
199 continue;
200 }
201
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700202 uint8_t fruBus = std::get<uint32_t>(busFind->second);
203 uint8_t fruAddr = std::get<uint32_t>(addrFind->second);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700204
205 uint8_t fruHash = 0;
206 if (fruBus != 0 || fruAddr != 0)
207 {
208 fruHash = hasher(fru.first.str);
209 // can't be 0xFF based on spec, and 0 is reserved for baseboard
210 if (fruHash == 0 || fruHash == 0xFF)
211 {
212 fruHash = 1;
213 }
214 }
215 std::pair<uint8_t, uint8_t> newDev(fruBus, fruAddr);
216
217 bool emplacePassed = false;
218 while (!emplacePassed)
219 {
220 auto resp = deviceHashes.emplace(fruHash, newDev);
221 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 }
234 auto deviceFind = deviceHashes.find(devId);
235 if (deviceFind == deviceHashes.end())
236 {
237 return IPMI_CC_SENSOR_INVALID;
238 }
239
240 fruCache.clear();
Vernon Mauery15419dd2019-05-24 09:40:30 -0700241 sdbusplus::message::message getRawFru = dbus->new_method_call(
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700242 fruDeviceServiceName, "/xyz/openbmc_project/FruDevice",
243 "xyz.openbmc_project.FruDeviceManager", "GetRawFru");
244 cacheBus = deviceFind->second.first;
245 cacheAddr = deviceFind->second.second;
246 getRawFru.append(cacheBus, cacheAddr);
247 try
248 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700249 sdbusplus::message::message getRawResp = dbus->call(getRawFru);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700250 getRawResp.read(fruCache);
251 }
252 catch (sdbusplus::exception_t&)
253 {
254 lastDevId = 0xFF;
255 cacheBus = 0xFF;
256 cacheAddr = 0xFF;
257 return IPMI_CC_RESPONSE_ERROR;
258 }
259
260 lastDevId = devId;
261 return IPMI_CC_OK;
262}
263
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700264ipmi_ret_t ipmiStorageReadFRUData(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
265 ipmi_request_t request,
266 ipmi_response_t response,
267 ipmi_data_len_t dataLen,
268 ipmi_context_t context)
269{
270 if (*dataLen != 4)
271 {
272 *dataLen = 0;
273 return IPMI_CC_REQ_DATA_LEN_INVALID;
274 }
275 *dataLen = 0; // default to 0 in case of an error
276
277 auto req = static_cast<GetFRUAreaReq*>(request);
278
279 if (req->countToRead > maxMessageSize - 1)
280 {
281 return IPMI_CC_INVALID_FIELD_REQUEST;
282 }
283 ipmi_ret_t status = replaceCacheFru(req->fruDeviceID);
284
285 if (status != IPMI_CC_OK)
286 {
287 return status;
288 }
289
290 size_t fromFRUByteLen = 0;
291 if (req->countToRead + req->fruInventoryOffset < fruCache.size())
292 {
293 fromFRUByteLen = req->countToRead;
294 }
295 else if (fruCache.size() > req->fruInventoryOffset)
296 {
297 fromFRUByteLen = fruCache.size() - req->fruInventoryOffset;
298 }
299 size_t padByteLen = req->countToRead - fromFRUByteLen;
300 uint8_t* respPtr = static_cast<uint8_t*>(response);
301 *respPtr = req->countToRead;
302 std::copy(fruCache.begin() + req->fruInventoryOffset,
303 fruCache.begin() + req->fruInventoryOffset + fromFRUByteLen,
304 ++respPtr);
305 // if longer than the fru is requested, fill with 0xFF
306 if (padByteLen)
307 {
308 respPtr += fromFRUByteLen;
309 std::fill(respPtr, respPtr + padByteLen, 0xFF);
310 }
311 *dataLen = fromFRUByteLen + 1;
312
313 return IPMI_CC_OK;
314}
315
316ipmi_ret_t ipmiStorageWriteFRUData(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
317 ipmi_request_t request,
318 ipmi_response_t response,
319 ipmi_data_len_t dataLen,
320 ipmi_context_t context)
321{
322 if (*dataLen < 4 ||
323 *dataLen >=
324 0xFF + 3) // count written return is one byte, so limit to one byte
325 // of data after the three request data bytes
326 {
327 *dataLen = 0;
328 return IPMI_CC_REQ_DATA_LEN_INVALID;
329 }
330
331 auto req = static_cast<WriteFRUDataReq*>(request);
332 size_t writeLen = *dataLen - 3;
333 *dataLen = 0; // default to 0 in case of an error
334
335 ipmi_ret_t status = replaceCacheFru(req->fruDeviceID);
336 if (status != IPMI_CC_OK)
337 {
338 return status;
339 }
340 int lastWriteAddr = req->fruInventoryOffset + writeLen;
341 if (fruCache.size() < lastWriteAddr)
342 {
343 fruCache.resize(req->fruInventoryOffset + writeLen);
344 }
345
346 std::copy(req->data, req->data + writeLen,
347 fruCache.begin() + req->fruInventoryOffset);
348
349 bool atEnd = false;
350
351 if (fruCache.size() >= sizeof(FRUHeader))
352 {
353
354 FRUHeader* header = reinterpret_cast<FRUHeader*>(fruCache.data());
355
356 int lastRecordStart = std::max(
357 header->internalOffset,
358 std::max(header->chassisOffset,
359 std::max(header->boardOffset, header->productOffset)));
360 // TODO: Handle Multi-Record FRUs?
361
362 lastRecordStart *= 8; // header starts in are multiples of 8 bytes
363
364 // get the length of the area in multiples of 8 bytes
365 if (lastWriteAddr > (lastRecordStart + 1))
366 {
367 // second byte in record area is the length
368 int areaLength(fruCache[lastRecordStart + 1]);
369 areaLength *= 8; // it is in multiples of 8 bytes
370
371 if (lastWriteAddr >= (areaLength + lastRecordStart))
372 {
373 atEnd = true;
374 }
375 }
376 }
377 uint8_t* respPtr = static_cast<uint8_t*>(response);
378 if (atEnd)
379 {
380 // cancel timer, we're at the end so might as well send it
381 cacheTimer->stop();
382 if (!writeFru())
383 {
384 return IPMI_CC_INVALID_FIELD_REQUEST;
385 }
386 *respPtr = std::min(fruCache.size(), static_cast<size_t>(0xFF));
387 }
388 else
389 {
390 // start a timer, if no further data is sent in cacheTimeoutSeconds
391 // seconds, check to see if it is valid
392 createTimer();
393 cacheTimer->start(std::chrono::duration_cast<std::chrono::microseconds>(
394 std::chrono::seconds(cacheTimeoutSeconds)));
395 *respPtr = 0;
396 }
397
398 *dataLen = 1;
399
400 return IPMI_CC_OK;
401}
402
403ipmi_ret_t ipmiStorageGetFRUInvAreaInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
404 ipmi_request_t request,
405 ipmi_response_t response,
406 ipmi_data_len_t dataLen,
407 ipmi_context_t context)
408{
409 if (*dataLen != 1)
410 {
411 *dataLen = 0;
412 return IPMI_CC_REQ_DATA_LEN_INVALID;
413 }
414 *dataLen = 0; // default to 0 in case of an error
415
416 uint8_t reqDev = *(static_cast<uint8_t*>(request));
417 if (reqDev == 0xFF)
418 {
419 return IPMI_CC_INVALID_FIELD_REQUEST;
420 }
421 ipmi_ret_t status = replaceCacheFru(reqDev);
422
423 if (status != IPMI_CC_OK)
424 {
425 return status;
426 }
427
428 GetFRUAreaResp* respPtr = static_cast<GetFRUAreaResp*>(response);
429 respPtr->inventorySizeLSB = fruCache.size() & 0xFF;
430 respPtr->inventorySizeMSB = fruCache.size() >> 8;
431 respPtr->accessType = static_cast<uint8_t>(GetFRUAreaAccessType::byte);
432
433 *dataLen = sizeof(GetFRUAreaResp);
434 return IPMI_CC_OK;
435}
436
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700437ipmi_ret_t getFruSdrCount(size_t& count)
438{
439 ipmi_ret_t ret = replaceCacheFru(0);
440 if (ret != IPMI_CC_OK)
441 {
442 return ret;
443 }
444 count = deviceHashes.size();
445 return IPMI_CC_OK;
446}
447
448ipmi_ret_t getFruSdrs(size_t index, get_sdr::SensorDataFruRecord& resp)
449{
450 ipmi_ret_t ret = replaceCacheFru(0); // this will update the hash list
451 if (ret != IPMI_CC_OK)
452 {
453 return ret;
454 }
455 if (deviceHashes.size() < index)
456 {
457 return IPMI_CC_INVALID_FIELD_REQUEST;
458 }
459 auto device = deviceHashes.begin() + index;
460 uint8_t& bus = device->second.first;
461 uint8_t& address = device->second.second;
462
463 ManagedObjectType frus;
464
Vernon Mauery15419dd2019-05-24 09:40:30 -0700465 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
466 sdbusplus::message::message getObjects = dbus->new_method_call(
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700467 fruDeviceServiceName, "/", "org.freedesktop.DBus.ObjectManager",
468 "GetManagedObjects");
469 try
470 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700471 sdbusplus::message::message resp = dbus->call(getObjects);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700472 resp.read(frus);
473 }
474 catch (sdbusplus::exception_t&)
475 {
476 return IPMI_CC_RESPONSE_ERROR;
477 }
478 boost::container::flat_map<std::string, DbusVariant>* fruData = nullptr;
479 auto fru =
480 std::find_if(frus.begin(), frus.end(),
481 [bus, address, &fruData](ManagedEntry& entry) {
482 auto findFruDevice =
483 entry.second.find("xyz.openbmc_project.FruDevice");
484 if (findFruDevice == entry.second.end())
485 {
486 return false;
487 }
488 fruData = &(findFruDevice->second);
489 auto findBus = findFruDevice->second.find("BUS");
490 auto findAddress =
491 findFruDevice->second.find("ADDRESS");
492 if (findBus == findFruDevice->second.end() ||
493 findAddress == findFruDevice->second.end())
494 {
495 return false;
496 }
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700497 if (std::get<uint32_t>(findBus->second) != bus)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700498 {
499 return false;
500 }
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700501 if (std::get<uint32_t>(findAddress->second) != address)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700502 {
503 return false;
504 }
505 return true;
506 });
507 if (fru == frus.end())
508 {
509 return IPMI_CC_RESPONSE_ERROR;
510 }
511 std::string name;
512 auto findProductName = fruData->find("BOARD_PRODUCT_NAME");
513 auto findBoardName = fruData->find("PRODUCT_PRODUCT_NAME");
514 if (findProductName != fruData->end())
515 {
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700516 name = std::get<std::string>(findProductName->second);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700517 }
518 else if (findBoardName != fruData->end())
519 {
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700520 name = std::get<std::string>(findBoardName->second);
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700521 }
522 else
523 {
524 name = "UNKNOWN";
525 }
526 if (name.size() > maxFruSdrNameSize)
527 {
528 name = name.substr(0, maxFruSdrNameSize);
529 }
530 size_t sizeDiff = maxFruSdrNameSize - name.size();
531
532 resp.header.record_id_lsb = 0x0; // calling code is to implement these
533 resp.header.record_id_msb = 0x0;
534 resp.header.sdr_version = ipmiSdrVersion;
535 resp.header.record_type = 0x11; // FRU Device Locator
536 resp.header.record_length = sizeof(resp.body) + sizeof(resp.key) - sizeDiff;
537 resp.key.deviceAddress = 0x20;
538 resp.key.fruID = device->first;
539 resp.key.accessLun = 0x80; // logical / physical fru device
540 resp.key.channelNumber = 0x0;
541 resp.body.reserved = 0x0;
542 resp.body.deviceType = 0x10;
James Feist4f86d1f2019-04-03 10:30:26 -0700543 resp.body.deviceTypeModifier = 0x0;
Jason M. Bills3f7c5e42018-10-03 14:00:41 -0700544 resp.body.entityID = 0x0;
545 resp.body.entityInstance = 0x1;
546 resp.body.oem = 0x0;
547 resp.body.deviceIDLen = name.size();
548 name.copy(resp.body.deviceID, name.size());
549
550 return IPMI_CC_OK;
551}
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700552
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700553static bool getSELLogFiles(std::vector<std::filesystem::path>& selLogFiles)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800554{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700555 // Loop through the directory looking for ipmi_sel log files
556 for (const std::filesystem::directory_entry& dirEnt :
557 std::filesystem::directory_iterator(intel_oem::ipmi::sel::selLogDir))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800558 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700559 std::string filename = dirEnt.path().filename();
560 if (boost::starts_with(filename, intel_oem::ipmi::sel::selLogFilename))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800561 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700562 // If we find an ipmi_sel log file, save the path
563 selLogFiles.emplace_back(intel_oem::ipmi::sel::selLogDir /
564 filename);
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800565 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800566 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700567 // As the log files rotate, they are appended with a ".#" that is higher for
568 // the older logs. Since we don't expect more than 10 log files, we
569 // can just sort the list to get them in order from newest to oldest
570 std::sort(selLogFiles.begin(), selLogFiles.end());
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800571
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700572 return !selLogFiles.empty();
573}
574
575static int countSELEntries()
576{
577 // Get the list of ipmi_sel log files
578 std::vector<std::filesystem::path> selLogFiles;
579 if (!getSELLogFiles(selLogFiles))
580 {
581 return 0;
582 }
583 int numSELEntries = 0;
584 // Loop through each log file and count the number of logs
585 for (const std::filesystem::path& file : selLogFiles)
586 {
587 std::ifstream logStream(file);
588 if (!logStream.is_open())
589 {
590 continue;
591 }
592
593 std::string line;
594 while (std::getline(logStream, line))
595 {
596 numSELEntries++;
597 }
598 }
599 return numSELEntries;
600}
601
602static bool findSELEntry(const int recordID,
603 const std::vector<std::filesystem::path> selLogFiles,
604 std::string& entry)
605{
606 // Record ID is the first entry field following the timestamp. It is
607 // preceded by a space and followed by a comma
608 std::string search = " " + std::to_string(recordID) + ",";
609
610 // Loop through the ipmi_sel log entries
611 for (const std::filesystem::path& file : selLogFiles)
612 {
613 std::ifstream logStream(file);
614 if (!logStream.is_open())
615 {
616 continue;
617 }
618
619 while (std::getline(logStream, entry))
620 {
621 // Check if the record ID matches
622 if (entry.find(search) != std::string::npos)
623 {
624 return true;
625 }
626 }
627 }
628 return false;
629}
630
631static uint16_t
632 getNextRecordID(const uint16_t recordID,
633 const std::vector<std::filesystem::path> selLogFiles)
634{
635 uint16_t nextRecordID = recordID + 1;
636 std::string entry;
637 if (findSELEntry(nextRecordID, selLogFiles, entry))
638 {
639 return nextRecordID;
640 }
641 else
642 {
643 return ipmi::sel::lastEntry;
644 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800645}
646
647static int fromHexStr(const std::string hexStr, std::vector<uint8_t>& data)
648{
649 for (unsigned int i = 0; i < hexStr.size(); i += 2)
650 {
651 try
652 {
653 data.push_back(static_cast<uint8_t>(
654 std::stoul(hexStr.substr(i, 2), nullptr, 16)));
655 }
656 catch (std::invalid_argument& e)
657 {
658 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
659 return -1;
660 }
661 catch (std::out_of_range& e)
662 {
663 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
664 return -1;
665 }
666 }
667 return 0;
668}
669
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700670ipmi::RspType<uint8_t, // SEL version
671 uint16_t, // SEL entry count
672 uint16_t, // free space
673 uint32_t, // last add timestamp
674 uint32_t, // last erase timestamp
675 uint8_t> // operation support
676 ipmiStorageGetSELInfo()
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800677{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700678 constexpr uint8_t selVersion = ipmi::sel::selVersion;
679 uint16_t entries = countSELEntries();
680 uint32_t addTimeStamp = intel_oem::ipmi::sel::getFileTimestamp(
681 intel_oem::ipmi::sel::selLogDir / intel_oem::ipmi::sel::selLogFilename);
682 uint32_t eraseTimeStamp = intel_oem::ipmi::sel::erase_time::get();
683 constexpr uint8_t operationSupport =
684 intel_oem::ipmi::sel::selOperationSupport;
685 constexpr uint16_t freeSpace =
686 0xffff; // Spec indicates that more than 64kB is free
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800687
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700688 return ipmi::responseSuccess(selVersion, entries, freeSpace, addTimeStamp,
689 eraseTimeStamp, operationSupport);
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800690}
691
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700692using systemEventType = std::tuple<
693 uint32_t, // Timestamp
694 uint16_t, // Generator ID
695 uint8_t, // EvM Rev
696 uint8_t, // Sensor Type
697 uint8_t, // Sensor Number
698 uint7_t, // Event Type
699 bool, // Event Direction
700 std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize>>; // Event Data
701using oemTsEventType = std::tuple<
702 uint32_t, // Timestamp
703 std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize>>; // Event Data
704using oemEventType =
705 std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize>; // Event Data
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800706
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700707ipmi::RspType<uint16_t, // Next Record ID
708 uint16_t, // Record ID
709 uint8_t, // Record Type
710 std::variant<systemEventType, oemTsEventType,
711 oemEventType>> // Record Content
712 ipmiStorageGetSELEntry(uint16_t reservationID, uint16_t targetID,
713 uint8_t offset, uint8_t size)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800714{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700715 // Only support getting the entire SEL record. If a partial size or non-zero
716 // offset is requested, return an error
717 if (offset != 0 || size != ipmi::sel::entireRecord)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800718 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700719 return ipmi::responseRetBytesUnavailable();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800720 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800721
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700722 // Check the reservation ID if one is provided or required (only if the
723 // offset is non-zero)
724 if (reservationID != 0 || offset != 0)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800725 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700726 if (!checkSELReservation(reservationID))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800727 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700728 return ipmi::responseInvalidReservationId();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800729 }
730 }
731
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700732 // Get the ipmi_sel log files
733 std::vector<std::filesystem::path> selLogFiles;
734 if (!getSELLogFiles(selLogFiles))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800735 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700736 return ipmi::responseSensorInvalid();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800737 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800738
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700739 std::string targetEntry;
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800740
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800741 if (targetID == ipmi::sel::firstEntry)
742 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700743 // The first entry will be at the top of the oldest log file
744 std::ifstream logStream(selLogFiles.back());
745 if (!logStream.is_open())
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800746 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700747 return ipmi::responseUnspecifiedError();
748 }
749
750 if (!std::getline(logStream, targetEntry))
751 {
752 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800753 }
754 }
755 else if (targetID == ipmi::sel::lastEntry)
756 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700757 // The last entry will be at the bottom of the newest log file
758 std::ifstream logStream(selLogFiles.front());
759 if (!logStream.is_open())
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800760 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700761 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800762 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700763
764 std::string line;
765 while (std::getline(logStream, line))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800766 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700767 targetEntry = line;
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800768 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800769 }
770 else
771 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700772 if (!findSELEntry(targetID, selLogFiles, targetEntry))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800773 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700774 return ipmi::responseSensorInvalid();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800775 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800776 }
777
Jason M. Bills52aaa7d2019-05-08 15:21:39 -0700778 // The format of the ipmi_sel message is "<Timestamp>
779 // <ID>,<Type>,<EventData>,[<Generator ID>,<Path>,<Direction>]".
780 // First get the Timestamp
781 size_t space = targetEntry.find_first_of(" ");
782 if (space == std::string::npos)
783 {
784 return ipmi::responseUnspecifiedError();
785 }
786 std::string entryTimestamp = targetEntry.substr(0, space);
787 // Then get the log contents
788 size_t entryStart = targetEntry.find_first_not_of(" ", space);
789 if (entryStart == std::string::npos)
790 {
791 return ipmi::responseUnspecifiedError();
792 }
793 std::string_view entry(targetEntry);
794 entry.remove_prefix(entryStart);
795 // Use split to separate the entry into its fields
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700796 std::vector<std::string> targetEntryFields;
Jason M. Bills52aaa7d2019-05-08 15:21:39 -0700797 boost::split(targetEntryFields, entry, boost::is_any_of(","),
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700798 boost::token_compress_on);
Jason M. Bills52aaa7d2019-05-08 15:21:39 -0700799 if (targetEntryFields.size() < 3)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700800 {
801 return ipmi::responseUnspecifiedError();
802 }
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -0700803 std::string& recordIDStr = targetEntryFields[0];
804 std::string& recordTypeStr = targetEntryFields[1];
805 std::string& eventDataStr = targetEntryFields[2];
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700806
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -0700807 uint16_t recordID;
808 uint8_t recordType;
809 try
810 {
811 recordID = std::stoul(recordIDStr);
812 recordType = std::stoul(recordTypeStr, nullptr, 16);
813 }
814 catch (const std::invalid_argument&)
815 {
816 return ipmi::responseUnspecifiedError();
817 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700818 uint16_t nextRecordID = getNextRecordID(recordID, selLogFiles);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700819 std::vector<uint8_t> eventDataBytes;
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -0700820 if (fromHexStr(eventDataStr, eventDataBytes) < 0)
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700821 {
822 return ipmi::responseUnspecifiedError();
823 }
824
825 if (recordType == intel_oem::ipmi::sel::systemEvent)
826 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700827 // Get the timestamp
828 std::tm timeStruct = {};
Jason M. Bills52aaa7d2019-05-08 15:21:39 -0700829 std::istringstream entryStream(entryTimestamp);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700830
831 uint32_t timestamp = ipmi::sel::invalidTimeStamp;
832 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
833 {
834 timestamp = std::mktime(&timeStruct);
835 }
836
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700837 // Set the event message revision
838 uint8_t evmRev = intel_oem::ipmi::sel::eventMsgRev;
839
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -0700840 uint16_t generatorID = 0;
841 uint8_t sensorType = 0;
842 uint8_t sensorNum = 0xFF;
843 uint7_t eventType = 0;
844 bool eventDir = 0;
845 // System type events should have six fields
846 if (targetEntryFields.size() >= 6)
847 {
848 std::string& generatorIDStr = targetEntryFields[3];
849 std::string& sensorPath = targetEntryFields[4];
850 std::string& eventDirStr = targetEntryFields[5];
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700851
Jason M. Bills1a2fbdd2019-05-10 09:05:37 -0700852 // Get the generator ID
853 try
854 {
855 generatorID = std::stoul(generatorIDStr, nullptr, 16);
856 }
857 catch (const std::invalid_argument&)
858 {
859 std::cerr << "Invalid Generator ID\n";
860 }
861
862 // Get the sensor type, sensor number, and event type for the sensor
863 sensorType = getSensorTypeFromPath(sensorPath);
864 sensorNum = getSensorNumberFromPath(sensorPath);
865 eventType = getSensorEventTypeFromPath(sensorPath);
866
867 // Get the event direction
868 try
869 {
870 eventDir = std::stoul(eventDirStr) ? 0 : 1;
871 }
872 catch (const std::invalid_argument&)
873 {
874 std::cerr << "Invalid Event Direction\n";
875 }
876 }
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700877
878 // Only keep the eventData bytes that fit in the record
879 std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize> eventData{};
880 std::copy_n(eventDataBytes.begin(),
881 std::min(eventDataBytes.size(), eventData.size()),
882 eventData.begin());
883
884 return ipmi::responseSuccess(
885 nextRecordID, recordID, recordType,
886 systemEventType{timestamp, generatorID, evmRev, sensorType,
887 sensorNum, eventType, eventDir, eventData});
888 }
889 else if (recordType >= intel_oem::ipmi::sel::oemTsEventFirst &&
890 recordType <= intel_oem::ipmi::sel::oemTsEventLast)
891 {
892 // Get the timestamp
893 std::tm timeStruct = {};
Jason M. Bills52aaa7d2019-05-08 15:21:39 -0700894 std::istringstream entryStream(entryTimestamp);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700895
896 uint32_t timestamp = ipmi::sel::invalidTimeStamp;
897 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
898 {
899 timestamp = std::mktime(&timeStruct);
900 }
901
902 // Only keep the bytes that fit in the record
903 std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize> eventData{};
904 std::copy_n(eventDataBytes.begin(),
905 std::min(eventDataBytes.size(), eventData.size()),
906 eventData.begin());
907
908 return ipmi::responseSuccess(nextRecordID, recordID, recordType,
909 oemTsEventType{timestamp, eventData});
910 }
911 else if (recordType >= intel_oem::ipmi::sel::oemEventFirst &&
912 recordType <= intel_oem::ipmi::sel::oemEventLast)
913 {
914 // Only keep the bytes that fit in the record
915 std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize> eventData{};
916 std::copy_n(eventDataBytes.begin(),
917 std::min(eventDataBytes.size(), eventData.size()),
918 eventData.begin());
919
920 return ipmi::responseSuccess(nextRecordID, recordID, recordType,
921 eventData);
922 }
923
924 return ipmi::responseUnspecifiedError();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800925}
926
Jason M. Bills6dd8f042019-04-11 10:39:02 -0700927ipmi::RspType<uint16_t> ipmiStorageAddSELEntry(
928 uint16_t recordID, uint8_t recordType, uint32_t timestamp,
929 uint16_t generatorID, uint8_t evmRev, uint8_t sensorType, uint8_t sensorNum,
930 uint8_t eventType, uint8_t eventData1, uint8_t eventData2,
931 uint8_t eventData3)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800932{
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800933 // Per the IPMI spec, need to cancel any reservation when a SEL entry is
934 // added
935 cancelSELReservation();
936
Jason M. Bills6dd8f042019-04-11 10:39:02 -0700937 // Send this request to the Redfish hooks to log it as a Redfish message
938 // instead. There is no need to add it to the SEL, so just return success.
939 intel_oem::ipmi::sel::checkRedfishHooks(
940 recordID, recordType, timestamp, generatorID, evmRev, sensorType,
941 sensorNum, eventType, eventData1, eventData2, eventData3);
Jason M. Bills99b78ec2019-01-18 10:42:18 -0800942
Jason M. Bills6dd8f042019-04-11 10:39:02 -0700943 uint16_t responseID = 0xFFFF;
944 return ipmi::responseSuccess(responseID);
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800945}
946
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700947ipmi::RspType<uint8_t> ipmiStorageClearSEL(ipmi::Context::ptr ctx,
948 uint16_t reservationID,
949 const std::array<uint8_t, 3>& clr,
950 uint8_t eraseOperation)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800951{
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700952 if (!checkSELReservation(reservationID))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800953 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700954 return ipmi::responseInvalidReservationId();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800955 }
956
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700957 static constexpr std::array<uint8_t, 3> clrExpected = {'C', 'L', 'R'};
958 if (clr != clrExpected)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800959 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700960 return ipmi::responseInvalidFieldRequest();
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800961 }
962
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700963 // Erasure status cannot be fetched, so always return erasure status as
964 // `erase completed`.
965 if (eraseOperation == ipmi::sel::getEraseStatus)
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800966 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700967 return ipmi::responseSuccess(ipmi::sel::eraseComplete);
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800968 }
969
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700970 // Check that initiate erase is correct
971 if (eraseOperation != ipmi::sel::initiateErase)
972 {
973 return ipmi::responseInvalidFieldRequest();
974 }
975
976 // Per the IPMI spec, need to cancel any reservation when the SEL is
977 // cleared
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800978 cancelSELReservation();
979
Jason M. Bills7944c302019-03-20 15:24:05 -0700980 // Save the erase time
981 intel_oem::ipmi::sel::erase_time::save();
982
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700983 // Clear the SEL by deleting the log files
984 std::vector<std::filesystem::path> selLogFiles;
985 if (getSELLogFiles(selLogFiles))
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800986 {
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700987 for (const std::filesystem::path& file : selLogFiles)
988 {
989 std::error_code ec;
990 std::filesystem::remove(file, ec);
991 }
Jason M. Billsc04e2e72018-11-28 15:15:56 -0800992 }
993
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700994 // Reload rsyslog so it knows to start new log files
Vernon Mauery15419dd2019-05-24 09:40:30 -0700995 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
996 sdbusplus::message::message rsyslogReload = dbus->new_method_call(
Jason M. Bills1d4d54d2019-04-23 11:26:11 -0700997 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
998 "org.freedesktop.systemd1.Manager", "ReloadUnit");
999 rsyslogReload.append("rsyslog.service", "replace");
1000 try
1001 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001002 sdbusplus::message::message reloadResponse = dbus->call(rsyslogReload);
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001003 }
1004 catch (sdbusplus::exception_t& e)
1005 {
1006 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1007 }
1008
1009 return ipmi::responseSuccess(ipmi::sel::eraseComplete);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001010}
1011
Jason M. Bills1a474622019-06-14 14:51:33 -07001012ipmi::RspType<uint32_t> ipmiStorageGetSELTime()
1013{
1014 struct timespec selTime = {};
1015
1016 if (clock_gettime(CLOCK_REALTIME, &selTime) < 0)
1017 {
1018 return ipmi::responseUnspecifiedError();
1019 }
1020
1021 return ipmi::responseSuccess(selTime.tv_sec);
1022}
1023
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001024ipmi::RspType<> ipmiStorageSetSELTime(uint32_t selTime)
Jason M. Billscac97a52019-01-30 14:43:46 -08001025{
1026 // Set SEL Time is not supported
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001027 return ipmi::responseInvalidCommand();
Jason M. Billscac97a52019-01-30 14:43:46 -08001028}
1029
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001030void registerStorageFunctions()
1031{
1032 // <Get FRU Inventory Area Info>
1033 ipmiPrintAndRegister(
1034 NETFUN_STORAGE,
1035 static_cast<ipmi_cmd_t>(IPMINetfnStorageCmds::ipmiCmdGetFRUInvAreaInfo),
1036 NULL, ipmiStorageGetFRUInvAreaInfo, PRIVILEGE_OPERATOR);
1037
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001038 // <READ FRU Data>
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001039 ipmiPrintAndRegister(
1040 NETFUN_STORAGE,
1041 static_cast<ipmi_cmd_t>(IPMINetfnStorageCmds::ipmiCmdReadFRUData), NULL,
1042 ipmiStorageReadFRUData, PRIVILEGE_OPERATOR);
1043
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001044 // <WRITE FRU Data>
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001045 ipmiPrintAndRegister(
1046 NETFUN_STORAGE,
1047 static_cast<ipmi_cmd_t>(IPMINetfnStorageCmds::ipmiCmdWriteFRUData),
1048 NULL, ipmiStorageWriteFRUData, PRIVILEGE_OPERATOR);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001049
1050 // <Get SEL Info>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001051 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1052 ipmi::storage::cmdGetSelInfo,
1053 ipmi::Privilege::Operator, ipmiStorageGetSELInfo);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001054
1055 // <Get SEL Entry>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001056 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1057 ipmi::storage::cmdGetSelEntry,
1058 ipmi::Privilege::Operator, ipmiStorageGetSELEntry);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001059
1060 // <Add SEL Entry>
Jason M. Bills6dd8f042019-04-11 10:39:02 -07001061 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1062 static_cast<ipmi::Cmd>(ipmi::storage::cmdAddSelEntry),
1063 ipmi::Privilege::Operator, ipmiStorageAddSELEntry);
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001064
1065 // <Clear SEL>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001066 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1067 ipmi::storage::cmdClearSel, ipmi::Privilege::Operator,
1068 ipmiStorageClearSEL);
Jason M. Billscac97a52019-01-30 14:43:46 -08001069
Jason M. Bills1a474622019-06-14 14:51:33 -07001070 // <Get SEL Time>
1071 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1072 ipmi::storage::cmdGetSelTime,
1073 ipmi::Privilege::Operator, ipmiStorageGetSELTime);
1074
Jason M. Billscac97a52019-01-30 14:43:46 -08001075 // <Set SEL Time>
Jason M. Bills1d4d54d2019-04-23 11:26:11 -07001076 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
1077 ipmi::storage::cmdSetSelTime,
1078 ipmi::Privilege::Operator, ipmiStorageSetSELTime);
Jason M. Billse2d1aee2018-10-03 15:57:18 -07001079}
Jason M. Bills3f7c5e42018-10-03 14:00:41 -07001080} // namespace storage
Jason M. Billsc04e2e72018-11-28 15:15:56 -08001081} // namespace ipmi