Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1 | /* |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 2 | // Copyright (c) 2017-2019 Intel Corporation |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 3 | // |
| 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. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 17 | #include <boost/algorithm/string.hpp> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 18 | #include <boost/container/flat_map.hpp> |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 19 | #include <boost/process.hpp> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 20 | #include <commandutils.hpp> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 21 | #include <filesystem> |
Patrick Venture | e8767d2 | 2019-09-25 16:54:16 -0700 | [diff] [blame^] | 22 | #include <functional> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 23 | #include <iostream> |
Jason M. Bills | 99b78ec | 2019-01-18 10:42:18 -0800 | [diff] [blame] | 24 | #include <ipmi_to_redfish_hooks.hpp> |
James Feist | 2a265d5 | 2019-04-08 11:16:27 -0700 | [diff] [blame] | 25 | #include <ipmid/api.hpp> |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 26 | #include <phosphor-ipmi-host/selutility.hpp> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 27 | #include <phosphor-logging/log.hpp> |
| 28 | #include <sdbusplus/message/types.hpp> |
| 29 | #include <sdbusplus/timer.hpp> |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 30 | #include <sdrutils.hpp> |
| 31 | #include <stdexcept> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 32 | #include <storagecommands.hpp> |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 33 | #include <string_view> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 34 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 35 | namespace intel_oem::ipmi::sel |
| 36 | { |
| 37 | static const std::filesystem::path selLogDir = "/var/log"; |
| 38 | static const std::string selLogFilename = "ipmi_sel"; |
| 39 | |
| 40 | static int getFileTimestamp(const std::filesystem::path& file) |
| 41 | { |
| 42 | struct stat st; |
| 43 | |
| 44 | if (stat(file.c_str(), &st) >= 0) |
| 45 | { |
| 46 | return st.st_mtime; |
| 47 | } |
| 48 | return ::ipmi::sel::invalidTimeStamp; |
| 49 | } |
| 50 | |
| 51 | namespace erase_time |
Jason M. Bills | 7944c30 | 2019-03-20 15:24:05 -0700 | [diff] [blame] | 52 | { |
| 53 | static constexpr const char* selEraseTimestamp = "/var/lib/ipmi/sel_erase_time"; |
| 54 | |
| 55 | void save() |
| 56 | { |
| 57 | // open the file, creating it if necessary |
| 58 | int fd = open(selEraseTimestamp, O_WRONLY | O_CREAT | O_CLOEXEC, 0644); |
| 59 | if (fd < 0) |
| 60 | { |
| 61 | std::cerr << "Failed to open file\n"; |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | // update the file timestamp to the current time |
| 66 | if (futimens(fd, NULL) < 0) |
| 67 | { |
| 68 | std::cerr << "Failed to update timestamp: " |
| 69 | << std::string(strerror(errno)); |
| 70 | } |
| 71 | close(fd); |
| 72 | } |
| 73 | |
| 74 | int get() |
| 75 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 76 | return getFileTimestamp(selEraseTimestamp); |
Jason M. Bills | 7944c30 | 2019-03-20 15:24:05 -0700 | [diff] [blame] | 77 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 78 | } // namespace erase_time |
| 79 | } // namespace intel_oem::ipmi::sel |
Jason M. Bills | 7944c30 | 2019-03-20 15:24:05 -0700 | [diff] [blame] | 80 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 81 | namespace ipmi |
| 82 | { |
| 83 | |
| 84 | namespace storage |
| 85 | { |
| 86 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 87 | constexpr static const size_t maxMessageSize = 64; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 88 | constexpr static const size_t maxFruSdrNameSize = 16; |
| 89 | using ManagedObjectType = boost::container::flat_map< |
| 90 | sdbusplus::message::object_path, |
| 91 | boost::container::flat_map< |
| 92 | std::string, boost::container::flat_map<std::string, DbusVariant>>>; |
| 93 | using ManagedEntry = std::pair< |
| 94 | sdbusplus::message::object_path, |
| 95 | boost::container::flat_map< |
| 96 | std::string, boost::container::flat_map<std::string, DbusVariant>>>; |
| 97 | |
James Feist | 3bcba45 | 2018-12-20 12:31:03 -0800 | [diff] [blame] | 98 | constexpr static const char* fruDeviceServiceName = |
| 99 | "xyz.openbmc_project.FruDevice"; |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 100 | constexpr static const size_t cacheTimeoutSeconds = 10; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 101 | |
Jason M. Bills | 4ed6f2c | 2019-04-02 12:21:25 -0700 | [diff] [blame] | 102 | // event direction is bit[7] of eventType where 1b = Deassertion event |
| 103 | constexpr static const uint8_t deassertionEvent = 0x80; |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 104 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 105 | static std::vector<uint8_t> fruCache; |
| 106 | static uint8_t cacheBus = 0xFF; |
| 107 | static uint8_t cacheAddr = 0XFF; |
| 108 | |
| 109 | std::unique_ptr<phosphor::Timer> cacheTimer = nullptr; |
| 110 | |
| 111 | // we unfortunately have to build a map of hashes in case there is a |
| 112 | // collision to verify our dev-id |
| 113 | boost::container::flat_map<uint8_t, std::pair<uint8_t, uint8_t>> deviceHashes; |
| 114 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 115 | void registerStorageFunctions() __attribute__((constructor)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 116 | |
| 117 | bool writeFru() |
| 118 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 119 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 120 | sdbusplus::message::message writeFru = dbus->new_method_call( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 121 | fruDeviceServiceName, "/xyz/openbmc_project/FruDevice", |
| 122 | "xyz.openbmc_project.FruDeviceManager", "WriteFru"); |
| 123 | writeFru.append(cacheBus, cacheAddr, fruCache); |
| 124 | try |
| 125 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 126 | sdbusplus::message::message writeFruResp = dbus->call(writeFru); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 127 | } |
| 128 | catch (sdbusplus::exception_t&) |
| 129 | { |
| 130 | // todo: log sel? |
| 131 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 132 | "error writing fru"); |
| 133 | return false; |
| 134 | } |
| 135 | return true; |
| 136 | } |
| 137 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 138 | void createTimer() |
| 139 | { |
| 140 | if (cacheTimer == nullptr) |
| 141 | { |
| 142 | cacheTimer = std::make_unique<phosphor::Timer>(writeFru); |
| 143 | } |
| 144 | } |
| 145 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 146 | ipmi_ret_t replaceCacheFru(uint8_t devId) |
| 147 | { |
| 148 | static uint8_t lastDevId = 0xFF; |
| 149 | |
| 150 | bool timerRunning = (cacheTimer != nullptr) && !cacheTimer->isExpired(); |
| 151 | if (lastDevId == devId && timerRunning) |
| 152 | { |
| 153 | return IPMI_CC_OK; // cache already up to date |
| 154 | } |
| 155 | // if timer is running, stop it and writeFru manually |
| 156 | else if (timerRunning) |
| 157 | { |
| 158 | cacheTimer->stop(); |
| 159 | writeFru(); |
| 160 | } |
| 161 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 162 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 163 | sdbusplus::message::message getObjects = dbus->new_method_call( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 164 | fruDeviceServiceName, "/", "org.freedesktop.DBus.ObjectManager", |
| 165 | "GetManagedObjects"); |
| 166 | ManagedObjectType frus; |
| 167 | try |
| 168 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 169 | sdbusplus::message::message resp = dbus->call(getObjects); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 170 | resp.read(frus); |
| 171 | } |
| 172 | catch (sdbusplus::exception_t&) |
| 173 | { |
| 174 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 175 | "replaceCacheFru: error getting managed objects"); |
| 176 | return IPMI_CC_RESPONSE_ERROR; |
| 177 | } |
| 178 | |
| 179 | deviceHashes.clear(); |
| 180 | |
| 181 | // hash the object paths to create unique device id's. increment on |
| 182 | // collision |
| 183 | std::hash<std::string> hasher; |
| 184 | for (const auto& fru : frus) |
| 185 | { |
| 186 | auto fruIface = fru.second.find("xyz.openbmc_project.FruDevice"); |
| 187 | if (fruIface == fru.second.end()) |
| 188 | { |
| 189 | continue; |
| 190 | } |
| 191 | |
| 192 | auto busFind = fruIface->second.find("BUS"); |
| 193 | auto addrFind = fruIface->second.find("ADDRESS"); |
| 194 | if (busFind == fruIface->second.end() || |
| 195 | addrFind == fruIface->second.end()) |
| 196 | { |
| 197 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 198 | "fru device missing Bus or Address", |
| 199 | phosphor::logging::entry("FRU=%s", fru.first.str.c_str())); |
| 200 | continue; |
| 201 | } |
| 202 | |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 203 | uint8_t fruBus = std::get<uint32_t>(busFind->second); |
| 204 | uint8_t fruAddr = std::get<uint32_t>(addrFind->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 205 | |
| 206 | uint8_t fruHash = 0; |
| 207 | if (fruBus != 0 || fruAddr != 0) |
| 208 | { |
| 209 | fruHash = hasher(fru.first.str); |
| 210 | // can't be 0xFF based on spec, and 0 is reserved for baseboard |
| 211 | if (fruHash == 0 || fruHash == 0xFF) |
| 212 | { |
| 213 | fruHash = 1; |
| 214 | } |
| 215 | } |
| 216 | std::pair<uint8_t, uint8_t> newDev(fruBus, fruAddr); |
| 217 | |
| 218 | bool emplacePassed = false; |
| 219 | while (!emplacePassed) |
| 220 | { |
| 221 | auto resp = deviceHashes.emplace(fruHash, newDev); |
| 222 | emplacePassed = resp.second; |
| 223 | if (!emplacePassed) |
| 224 | { |
| 225 | fruHash++; |
| 226 | // can't be 0xFF based on spec, and 0 is reserved for |
| 227 | // baseboard |
| 228 | if (fruHash == 0XFF) |
| 229 | { |
| 230 | fruHash = 0x1; |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | auto deviceFind = deviceHashes.find(devId); |
| 236 | if (deviceFind == deviceHashes.end()) |
| 237 | { |
| 238 | return IPMI_CC_SENSOR_INVALID; |
| 239 | } |
| 240 | |
| 241 | fruCache.clear(); |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 242 | sdbusplus::message::message getRawFru = dbus->new_method_call( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 243 | fruDeviceServiceName, "/xyz/openbmc_project/FruDevice", |
| 244 | "xyz.openbmc_project.FruDeviceManager", "GetRawFru"); |
| 245 | cacheBus = deviceFind->second.first; |
| 246 | cacheAddr = deviceFind->second.second; |
| 247 | getRawFru.append(cacheBus, cacheAddr); |
| 248 | try |
| 249 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 250 | sdbusplus::message::message getRawResp = dbus->call(getRawFru); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 251 | getRawResp.read(fruCache); |
| 252 | } |
| 253 | catch (sdbusplus::exception_t&) |
| 254 | { |
| 255 | lastDevId = 0xFF; |
| 256 | cacheBus = 0xFF; |
| 257 | cacheAddr = 0xFF; |
| 258 | return IPMI_CC_RESPONSE_ERROR; |
| 259 | } |
| 260 | |
| 261 | lastDevId = devId; |
| 262 | return IPMI_CC_OK; |
| 263 | } |
| 264 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 265 | /** @brief implements the read FRU data command |
| 266 | * @param fruDeviceId - FRU Device ID |
| 267 | * @param fruInventoryOffset - FRU Inventory Offset to write |
| 268 | * @param countToRead - Count to read |
| 269 | * |
| 270 | * @returns ipmi completion code plus response data |
| 271 | * - countWritten - Count written |
| 272 | */ |
| 273 | ipmi::RspType<uint8_t, // Count |
| 274 | std::vector<uint8_t> // Requested data |
| 275 | > |
| 276 | ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t fruInventoryOffset, |
| 277 | uint8_t countToRead) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 278 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 279 | if (fruDeviceId == 0xFF) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 280 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 281 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 282 | } |
| 283 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 284 | ipmi::Cc status = replaceCacheFru(fruDeviceId); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 285 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 286 | if (status != ipmi::ccSuccess) |
| 287 | { |
| 288 | return ipmi::response(status); |
| 289 | } |
| 290 | |
| 291 | size_t fromFruByteLen = 0; |
| 292 | if (countToRead + fruInventoryOffset < fruCache.size()) |
| 293 | { |
| 294 | fromFruByteLen = countToRead; |
| 295 | } |
| 296 | else if (fruCache.size() > fruInventoryOffset) |
| 297 | { |
| 298 | fromFruByteLen = fruCache.size() - fruInventoryOffset; |
| 299 | } |
| 300 | else |
| 301 | { |
| 302 | return ipmi::responseInvalidFieldRequest(); |
| 303 | } |
| 304 | |
| 305 | std::vector<uint8_t> requestedData; |
| 306 | |
| 307 | requestedData.insert( |
| 308 | requestedData.begin(), fruCache.begin() + fruInventoryOffset, |
| 309 | fruCache.begin() + fruInventoryOffset + fromFruByteLen); |
| 310 | |
| 311 | return ipmi::responseSuccess(countToRead, requestedData); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 312 | } |
| 313 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 314 | /** @brief implements the write FRU data command |
| 315 | * @param fruDeviceId - FRU Device ID |
| 316 | * @param fruInventoryOffset - FRU Inventory Offset to write |
| 317 | * @param dataToWrite - Data to write |
| 318 | * |
| 319 | * @returns ipmi completion code plus response data |
| 320 | * - countWritten - Count written |
| 321 | */ |
| 322 | ipmi::RspType<uint8_t> |
| 323 | ipmiStorageWriteFruData(uint8_t fruDeviceId, uint16_t fruInventoryOffset, |
| 324 | std::vector<uint8_t>& dataToWrite) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 325 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 326 | if (fruDeviceId == 0xFF) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 327 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 328 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 329 | } |
| 330 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 331 | size_t writeLen = dataToWrite.size(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 332 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 333 | ipmi::Cc status = replaceCacheFru(fruDeviceId); |
| 334 | if (status != ipmi::ccSuccess) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 335 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 336 | return ipmi::response(status); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 337 | } |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 338 | int lastWriteAddr = fruInventoryOffset + writeLen; |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 339 | if (fruCache.size() < lastWriteAddr) |
| 340 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 341 | fruCache.resize(fruInventoryOffset + writeLen); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 342 | } |
| 343 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 344 | std::copy(dataToWrite.begin(), dataToWrite.begin() + writeLen, |
| 345 | fruCache.begin() + fruInventoryOffset); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 346 | |
| 347 | bool atEnd = false; |
| 348 | |
| 349 | if (fruCache.size() >= sizeof(FRUHeader)) |
| 350 | { |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 351 | FRUHeader* header = reinterpret_cast<FRUHeader*>(fruCache.data()); |
| 352 | |
| 353 | int lastRecordStart = std::max( |
| 354 | header->internalOffset, |
| 355 | std::max(header->chassisOffset, |
| 356 | std::max(header->boardOffset, header->productOffset))); |
| 357 | // TODO: Handle Multi-Record FRUs? |
| 358 | |
| 359 | lastRecordStart *= 8; // header starts in are multiples of 8 bytes |
| 360 | |
| 361 | // get the length of the area in multiples of 8 bytes |
| 362 | if (lastWriteAddr > (lastRecordStart + 1)) |
| 363 | { |
| 364 | // second byte in record area is the length |
| 365 | int areaLength(fruCache[lastRecordStart + 1]); |
| 366 | areaLength *= 8; // it is in multiples of 8 bytes |
| 367 | |
| 368 | if (lastWriteAddr >= (areaLength + lastRecordStart)) |
| 369 | { |
| 370 | atEnd = true; |
| 371 | } |
| 372 | } |
| 373 | } |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 374 | uint8_t countWritten = 0; |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 375 | if (atEnd) |
| 376 | { |
| 377 | // cancel timer, we're at the end so might as well send it |
| 378 | cacheTimer->stop(); |
| 379 | if (!writeFru()) |
| 380 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 381 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 382 | } |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 383 | countWritten = std::min(fruCache.size(), static_cast<size_t>(0xFF)); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 384 | } |
| 385 | else |
| 386 | { |
| 387 | // start a timer, if no further data is sent in cacheTimeoutSeconds |
| 388 | // seconds, check to see if it is valid |
| 389 | createTimer(); |
| 390 | cacheTimer->start(std::chrono::duration_cast<std::chrono::microseconds>( |
| 391 | std::chrono::seconds(cacheTimeoutSeconds))); |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 392 | countWritten = 0; |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 393 | } |
| 394 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 395 | return ipmi::responseSuccess(countWritten); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 396 | } |
| 397 | |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 398 | /** @brief implements the get FRU inventory area info command |
| 399 | * @param fruDeviceId - FRU Device ID |
| 400 | * |
| 401 | * @returns IPMI completion code plus response data |
| 402 | * - inventorySize - Number of possible allocation units |
| 403 | * - accessType - Allocation unit size in bytes. |
| 404 | */ |
| 405 | ipmi::RspType<uint16_t, // inventorySize |
| 406 | uint8_t> // accessType |
| 407 | ipmiStorageGetFruInvAreaInfo(uint8_t fruDeviceId) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 408 | { |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 409 | if (fruDeviceId == 0xFF) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 410 | { |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 411 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 412 | } |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 413 | |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 414 | ipmi::Cc status = replaceCacheFru(fruDeviceId); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 415 | |
| 416 | if (status != IPMI_CC_OK) |
| 417 | { |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 418 | return ipmi::response(status); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 419 | } |
| 420 | |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 421 | constexpr uint8_t accessType = |
| 422 | static_cast<uint8_t>(GetFRUAreaAccessType::byte); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 423 | |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 424 | return ipmi::responseSuccess(fruCache.size(), accessType); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 427 | ipmi_ret_t getFruSdrCount(size_t& count) |
| 428 | { |
| 429 | ipmi_ret_t ret = replaceCacheFru(0); |
| 430 | if (ret != IPMI_CC_OK) |
| 431 | { |
| 432 | return ret; |
| 433 | } |
| 434 | count = deviceHashes.size(); |
| 435 | return IPMI_CC_OK; |
| 436 | } |
| 437 | |
| 438 | ipmi_ret_t getFruSdrs(size_t index, get_sdr::SensorDataFruRecord& resp) |
| 439 | { |
| 440 | ipmi_ret_t ret = replaceCacheFru(0); // this will update the hash list |
| 441 | if (ret != IPMI_CC_OK) |
| 442 | { |
| 443 | return ret; |
| 444 | } |
| 445 | if (deviceHashes.size() < index) |
| 446 | { |
| 447 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 448 | } |
| 449 | auto device = deviceHashes.begin() + index; |
| 450 | uint8_t& bus = device->second.first; |
| 451 | uint8_t& address = device->second.second; |
| 452 | |
| 453 | ManagedObjectType frus; |
| 454 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 455 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 456 | sdbusplus::message::message getObjects = dbus->new_method_call( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 457 | fruDeviceServiceName, "/", "org.freedesktop.DBus.ObjectManager", |
| 458 | "GetManagedObjects"); |
| 459 | try |
| 460 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 461 | sdbusplus::message::message resp = dbus->call(getObjects); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 462 | resp.read(frus); |
| 463 | } |
| 464 | catch (sdbusplus::exception_t&) |
| 465 | { |
| 466 | return IPMI_CC_RESPONSE_ERROR; |
| 467 | } |
| 468 | boost::container::flat_map<std::string, DbusVariant>* fruData = nullptr; |
| 469 | auto fru = |
| 470 | std::find_if(frus.begin(), frus.end(), |
| 471 | [bus, address, &fruData](ManagedEntry& entry) { |
| 472 | auto findFruDevice = |
| 473 | entry.second.find("xyz.openbmc_project.FruDevice"); |
| 474 | if (findFruDevice == entry.second.end()) |
| 475 | { |
| 476 | return false; |
| 477 | } |
| 478 | fruData = &(findFruDevice->second); |
| 479 | auto findBus = findFruDevice->second.find("BUS"); |
| 480 | auto findAddress = |
| 481 | findFruDevice->second.find("ADDRESS"); |
| 482 | if (findBus == findFruDevice->second.end() || |
| 483 | findAddress == findFruDevice->second.end()) |
| 484 | { |
| 485 | return false; |
| 486 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 487 | if (std::get<uint32_t>(findBus->second) != bus) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 488 | { |
| 489 | return false; |
| 490 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 491 | if (std::get<uint32_t>(findAddress->second) != address) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 492 | { |
| 493 | return false; |
| 494 | } |
| 495 | return true; |
| 496 | }); |
| 497 | if (fru == frus.end()) |
| 498 | { |
| 499 | return IPMI_CC_RESPONSE_ERROR; |
| 500 | } |
| 501 | std::string name; |
| 502 | auto findProductName = fruData->find("BOARD_PRODUCT_NAME"); |
| 503 | auto findBoardName = fruData->find("PRODUCT_PRODUCT_NAME"); |
| 504 | if (findProductName != fruData->end()) |
| 505 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 506 | name = std::get<std::string>(findProductName->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 507 | } |
| 508 | else if (findBoardName != fruData->end()) |
| 509 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 510 | name = std::get<std::string>(findBoardName->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 511 | } |
| 512 | else |
| 513 | { |
| 514 | name = "UNKNOWN"; |
| 515 | } |
| 516 | if (name.size() > maxFruSdrNameSize) |
| 517 | { |
| 518 | name = name.substr(0, maxFruSdrNameSize); |
| 519 | } |
| 520 | size_t sizeDiff = maxFruSdrNameSize - name.size(); |
| 521 | |
| 522 | resp.header.record_id_lsb = 0x0; // calling code is to implement these |
| 523 | resp.header.record_id_msb = 0x0; |
| 524 | resp.header.sdr_version = ipmiSdrVersion; |
| 525 | resp.header.record_type = 0x11; // FRU Device Locator |
| 526 | resp.header.record_length = sizeof(resp.body) + sizeof(resp.key) - sizeDiff; |
| 527 | resp.key.deviceAddress = 0x20; |
| 528 | resp.key.fruID = device->first; |
| 529 | resp.key.accessLun = 0x80; // logical / physical fru device |
| 530 | resp.key.channelNumber = 0x0; |
| 531 | resp.body.reserved = 0x0; |
| 532 | resp.body.deviceType = 0x10; |
James Feist | 4f86d1f | 2019-04-03 10:30:26 -0700 | [diff] [blame] | 533 | resp.body.deviceTypeModifier = 0x0; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 534 | resp.body.entityID = 0x0; |
| 535 | resp.body.entityInstance = 0x1; |
| 536 | resp.body.oem = 0x0; |
| 537 | resp.body.deviceIDLen = name.size(); |
| 538 | name.copy(resp.body.deviceID, name.size()); |
| 539 | |
| 540 | return IPMI_CC_OK; |
| 541 | } |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 542 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 543 | static bool getSELLogFiles(std::vector<std::filesystem::path>& selLogFiles) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 544 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 545 | // Loop through the directory looking for ipmi_sel log files |
| 546 | for (const std::filesystem::directory_entry& dirEnt : |
| 547 | std::filesystem::directory_iterator(intel_oem::ipmi::sel::selLogDir)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 548 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 549 | std::string filename = dirEnt.path().filename(); |
| 550 | if (boost::starts_with(filename, intel_oem::ipmi::sel::selLogFilename)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 551 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 552 | // If we find an ipmi_sel log file, save the path |
| 553 | selLogFiles.emplace_back(intel_oem::ipmi::sel::selLogDir / |
| 554 | filename); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 555 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 556 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 557 | // As the log files rotate, they are appended with a ".#" that is higher for |
| 558 | // the older logs. Since we don't expect more than 10 log files, we |
| 559 | // can just sort the list to get them in order from newest to oldest |
| 560 | std::sort(selLogFiles.begin(), selLogFiles.end()); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 561 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 562 | return !selLogFiles.empty(); |
| 563 | } |
| 564 | |
| 565 | static int countSELEntries() |
| 566 | { |
| 567 | // Get the list of ipmi_sel log files |
| 568 | std::vector<std::filesystem::path> selLogFiles; |
| 569 | if (!getSELLogFiles(selLogFiles)) |
| 570 | { |
| 571 | return 0; |
| 572 | } |
| 573 | int numSELEntries = 0; |
| 574 | // Loop through each log file and count the number of logs |
| 575 | for (const std::filesystem::path& file : selLogFiles) |
| 576 | { |
| 577 | std::ifstream logStream(file); |
| 578 | if (!logStream.is_open()) |
| 579 | { |
| 580 | continue; |
| 581 | } |
| 582 | |
| 583 | std::string line; |
| 584 | while (std::getline(logStream, line)) |
| 585 | { |
| 586 | numSELEntries++; |
| 587 | } |
| 588 | } |
| 589 | return numSELEntries; |
| 590 | } |
| 591 | |
| 592 | static bool findSELEntry(const int recordID, |
Patrick Venture | ff7e15b | 2019-09-25 16:48:26 -0700 | [diff] [blame] | 593 | const std::vector<std::filesystem::path>& selLogFiles, |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 594 | std::string& entry) |
| 595 | { |
| 596 | // Record ID is the first entry field following the timestamp. It is |
| 597 | // preceded by a space and followed by a comma |
| 598 | std::string search = " " + std::to_string(recordID) + ","; |
| 599 | |
| 600 | // Loop through the ipmi_sel log entries |
| 601 | for (const std::filesystem::path& file : selLogFiles) |
| 602 | { |
| 603 | std::ifstream logStream(file); |
| 604 | if (!logStream.is_open()) |
| 605 | { |
| 606 | continue; |
| 607 | } |
| 608 | |
| 609 | while (std::getline(logStream, entry)) |
| 610 | { |
| 611 | // Check if the record ID matches |
| 612 | if (entry.find(search) != std::string::npos) |
| 613 | { |
| 614 | return true; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | return false; |
| 619 | } |
| 620 | |
| 621 | static uint16_t |
| 622 | getNextRecordID(const uint16_t recordID, |
Patrick Venture | ff7e15b | 2019-09-25 16:48:26 -0700 | [diff] [blame] | 623 | const std::vector<std::filesystem::path>& selLogFiles) |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 624 | { |
| 625 | uint16_t nextRecordID = recordID + 1; |
| 626 | std::string entry; |
| 627 | if (findSELEntry(nextRecordID, selLogFiles, entry)) |
| 628 | { |
| 629 | return nextRecordID; |
| 630 | } |
| 631 | else |
| 632 | { |
| 633 | return ipmi::sel::lastEntry; |
| 634 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Patrick Venture | ff7e15b | 2019-09-25 16:48:26 -0700 | [diff] [blame] | 637 | static int fromHexStr(const std::string& hexStr, std::vector<uint8_t>& data) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 638 | { |
| 639 | for (unsigned int i = 0; i < hexStr.size(); i += 2) |
| 640 | { |
| 641 | try |
| 642 | { |
| 643 | data.push_back(static_cast<uint8_t>( |
| 644 | std::stoul(hexStr.substr(i, 2), nullptr, 16))); |
| 645 | } |
| 646 | catch (std::invalid_argument& e) |
| 647 | { |
| 648 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 649 | return -1; |
| 650 | } |
| 651 | catch (std::out_of_range& e) |
| 652 | { |
| 653 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 654 | return -1; |
| 655 | } |
| 656 | } |
| 657 | return 0; |
| 658 | } |
| 659 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 660 | ipmi::RspType<uint8_t, // SEL version |
| 661 | uint16_t, // SEL entry count |
| 662 | uint16_t, // free space |
| 663 | uint32_t, // last add timestamp |
| 664 | uint32_t, // last erase timestamp |
| 665 | uint8_t> // operation support |
| 666 | ipmiStorageGetSELInfo() |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 667 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 668 | constexpr uint8_t selVersion = ipmi::sel::selVersion; |
| 669 | uint16_t entries = countSELEntries(); |
| 670 | uint32_t addTimeStamp = intel_oem::ipmi::sel::getFileTimestamp( |
| 671 | intel_oem::ipmi::sel::selLogDir / intel_oem::ipmi::sel::selLogFilename); |
| 672 | uint32_t eraseTimeStamp = intel_oem::ipmi::sel::erase_time::get(); |
| 673 | constexpr uint8_t operationSupport = |
| 674 | intel_oem::ipmi::sel::selOperationSupport; |
| 675 | constexpr uint16_t freeSpace = |
| 676 | 0xffff; // Spec indicates that more than 64kB is free |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 677 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 678 | return ipmi::responseSuccess(selVersion, entries, freeSpace, addTimeStamp, |
| 679 | eraseTimeStamp, operationSupport); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 680 | } |
| 681 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 682 | using systemEventType = std::tuple< |
| 683 | uint32_t, // Timestamp |
| 684 | uint16_t, // Generator ID |
| 685 | uint8_t, // EvM Rev |
| 686 | uint8_t, // Sensor Type |
| 687 | uint8_t, // Sensor Number |
| 688 | uint7_t, // Event Type |
| 689 | bool, // Event Direction |
| 690 | std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize>>; // Event Data |
| 691 | using oemTsEventType = std::tuple< |
| 692 | uint32_t, // Timestamp |
| 693 | std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize>>; // Event Data |
| 694 | using oemEventType = |
| 695 | std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize>; // Event Data |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 696 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 697 | ipmi::RspType<uint16_t, // Next Record ID |
| 698 | uint16_t, // Record ID |
| 699 | uint8_t, // Record Type |
| 700 | std::variant<systemEventType, oemTsEventType, |
| 701 | oemEventType>> // Record Content |
| 702 | ipmiStorageGetSELEntry(uint16_t reservationID, uint16_t targetID, |
| 703 | uint8_t offset, uint8_t size) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 704 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 705 | // Only support getting the entire SEL record. If a partial size or non-zero |
| 706 | // offset is requested, return an error |
| 707 | if (offset != 0 || size != ipmi::sel::entireRecord) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 708 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 709 | return ipmi::responseRetBytesUnavailable(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 710 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 711 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 712 | // Check the reservation ID if one is provided or required (only if the |
| 713 | // offset is non-zero) |
| 714 | if (reservationID != 0 || offset != 0) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 715 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 716 | if (!checkSELReservation(reservationID)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 717 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 718 | return ipmi::responseInvalidReservationId(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 722 | // Get the ipmi_sel log files |
| 723 | std::vector<std::filesystem::path> selLogFiles; |
| 724 | if (!getSELLogFiles(selLogFiles)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 725 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 726 | return ipmi::responseSensorInvalid(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 727 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 728 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 729 | std::string targetEntry; |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 730 | |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 731 | if (targetID == ipmi::sel::firstEntry) |
| 732 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 733 | // The first entry will be at the top of the oldest log file |
| 734 | std::ifstream logStream(selLogFiles.back()); |
| 735 | if (!logStream.is_open()) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 736 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 737 | return ipmi::responseUnspecifiedError(); |
| 738 | } |
| 739 | |
| 740 | if (!std::getline(logStream, targetEntry)) |
| 741 | { |
| 742 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | else if (targetID == ipmi::sel::lastEntry) |
| 746 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 747 | // The last entry will be at the bottom of the newest log file |
| 748 | std::ifstream logStream(selLogFiles.front()); |
| 749 | if (!logStream.is_open()) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 750 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 751 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 752 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 753 | |
| 754 | std::string line; |
| 755 | while (std::getline(logStream, line)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 756 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 757 | targetEntry = line; |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 758 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 759 | } |
| 760 | else |
| 761 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 762 | if (!findSELEntry(targetID, selLogFiles, targetEntry)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 763 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 764 | return ipmi::responseSensorInvalid(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 765 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 766 | } |
| 767 | |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 768 | // The format of the ipmi_sel message is "<Timestamp> |
| 769 | // <ID>,<Type>,<EventData>,[<Generator ID>,<Path>,<Direction>]". |
| 770 | // First get the Timestamp |
| 771 | size_t space = targetEntry.find_first_of(" "); |
| 772 | if (space == std::string::npos) |
| 773 | { |
| 774 | return ipmi::responseUnspecifiedError(); |
| 775 | } |
| 776 | std::string entryTimestamp = targetEntry.substr(0, space); |
| 777 | // Then get the log contents |
| 778 | size_t entryStart = targetEntry.find_first_not_of(" ", space); |
| 779 | if (entryStart == std::string::npos) |
| 780 | { |
| 781 | return ipmi::responseUnspecifiedError(); |
| 782 | } |
| 783 | std::string_view entry(targetEntry); |
| 784 | entry.remove_prefix(entryStart); |
| 785 | // Use split to separate the entry into its fields |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 786 | std::vector<std::string> targetEntryFields; |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 787 | boost::split(targetEntryFields, entry, boost::is_any_of(","), |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 788 | boost::token_compress_on); |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 789 | if (targetEntryFields.size() < 3) |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 790 | { |
| 791 | return ipmi::responseUnspecifiedError(); |
| 792 | } |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 793 | std::string& recordIDStr = targetEntryFields[0]; |
| 794 | std::string& recordTypeStr = targetEntryFields[1]; |
| 795 | std::string& eventDataStr = targetEntryFields[2]; |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 796 | |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 797 | uint16_t recordID; |
| 798 | uint8_t recordType; |
| 799 | try |
| 800 | { |
| 801 | recordID = std::stoul(recordIDStr); |
| 802 | recordType = std::stoul(recordTypeStr, nullptr, 16); |
| 803 | } |
| 804 | catch (const std::invalid_argument&) |
| 805 | { |
| 806 | return ipmi::responseUnspecifiedError(); |
| 807 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 808 | uint16_t nextRecordID = getNextRecordID(recordID, selLogFiles); |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 809 | std::vector<uint8_t> eventDataBytes; |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 810 | if (fromHexStr(eventDataStr, eventDataBytes) < 0) |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 811 | { |
| 812 | return ipmi::responseUnspecifiedError(); |
| 813 | } |
| 814 | |
| 815 | if (recordType == intel_oem::ipmi::sel::systemEvent) |
| 816 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 817 | // Get the timestamp |
| 818 | std::tm timeStruct = {}; |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 819 | std::istringstream entryStream(entryTimestamp); |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 820 | |
| 821 | uint32_t timestamp = ipmi::sel::invalidTimeStamp; |
| 822 | if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) |
| 823 | { |
| 824 | timestamp = std::mktime(&timeStruct); |
| 825 | } |
| 826 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 827 | // Set the event message revision |
| 828 | uint8_t evmRev = intel_oem::ipmi::sel::eventMsgRev; |
| 829 | |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 830 | uint16_t generatorID = 0; |
| 831 | uint8_t sensorType = 0; |
| 832 | uint8_t sensorNum = 0xFF; |
| 833 | uint7_t eventType = 0; |
| 834 | bool eventDir = 0; |
| 835 | // System type events should have six fields |
| 836 | if (targetEntryFields.size() >= 6) |
| 837 | { |
| 838 | std::string& generatorIDStr = targetEntryFields[3]; |
| 839 | std::string& sensorPath = targetEntryFields[4]; |
| 840 | std::string& eventDirStr = targetEntryFields[5]; |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 841 | |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 842 | // Get the generator ID |
| 843 | try |
| 844 | { |
| 845 | generatorID = std::stoul(generatorIDStr, nullptr, 16); |
| 846 | } |
| 847 | catch (const std::invalid_argument&) |
| 848 | { |
| 849 | std::cerr << "Invalid Generator ID\n"; |
| 850 | } |
| 851 | |
| 852 | // Get the sensor type, sensor number, and event type for the sensor |
| 853 | sensorType = getSensorTypeFromPath(sensorPath); |
| 854 | sensorNum = getSensorNumberFromPath(sensorPath); |
| 855 | eventType = getSensorEventTypeFromPath(sensorPath); |
| 856 | |
| 857 | // Get the event direction |
| 858 | try |
| 859 | { |
| 860 | eventDir = std::stoul(eventDirStr) ? 0 : 1; |
| 861 | } |
| 862 | catch (const std::invalid_argument&) |
| 863 | { |
| 864 | std::cerr << "Invalid Event Direction\n"; |
| 865 | } |
| 866 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 867 | |
| 868 | // Only keep the eventData bytes that fit in the record |
| 869 | std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize> eventData{}; |
| 870 | std::copy_n(eventDataBytes.begin(), |
| 871 | std::min(eventDataBytes.size(), eventData.size()), |
| 872 | eventData.begin()); |
| 873 | |
| 874 | return ipmi::responseSuccess( |
| 875 | nextRecordID, recordID, recordType, |
| 876 | systemEventType{timestamp, generatorID, evmRev, sensorType, |
| 877 | sensorNum, eventType, eventDir, eventData}); |
| 878 | } |
| 879 | else if (recordType >= intel_oem::ipmi::sel::oemTsEventFirst && |
| 880 | recordType <= intel_oem::ipmi::sel::oemTsEventLast) |
| 881 | { |
| 882 | // Get the timestamp |
| 883 | std::tm timeStruct = {}; |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 884 | std::istringstream entryStream(entryTimestamp); |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 885 | |
| 886 | uint32_t timestamp = ipmi::sel::invalidTimeStamp; |
| 887 | if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) |
| 888 | { |
| 889 | timestamp = std::mktime(&timeStruct); |
| 890 | } |
| 891 | |
| 892 | // Only keep the bytes that fit in the record |
| 893 | std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize> eventData{}; |
| 894 | std::copy_n(eventDataBytes.begin(), |
| 895 | std::min(eventDataBytes.size(), eventData.size()), |
| 896 | eventData.begin()); |
| 897 | |
| 898 | return ipmi::responseSuccess(nextRecordID, recordID, recordType, |
| 899 | oemTsEventType{timestamp, eventData}); |
| 900 | } |
| 901 | else if (recordType >= intel_oem::ipmi::sel::oemEventFirst && |
| 902 | recordType <= intel_oem::ipmi::sel::oemEventLast) |
| 903 | { |
| 904 | // Only keep the bytes that fit in the record |
| 905 | std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize> eventData{}; |
| 906 | std::copy_n(eventDataBytes.begin(), |
| 907 | std::min(eventDataBytes.size(), eventData.size()), |
| 908 | eventData.begin()); |
| 909 | |
| 910 | return ipmi::responseSuccess(nextRecordID, recordID, recordType, |
| 911 | eventData); |
| 912 | } |
| 913 | |
| 914 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 915 | } |
| 916 | |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 917 | ipmi::RspType<uint16_t> ipmiStorageAddSELEntry( |
| 918 | uint16_t recordID, uint8_t recordType, uint32_t timestamp, |
| 919 | uint16_t generatorID, uint8_t evmRev, uint8_t sensorType, uint8_t sensorNum, |
| 920 | uint8_t eventType, uint8_t eventData1, uint8_t eventData2, |
| 921 | uint8_t eventData3) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 922 | { |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 923 | // Per the IPMI spec, need to cancel any reservation when a SEL entry is |
| 924 | // added |
| 925 | cancelSELReservation(); |
| 926 | |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 927 | // Send this request to the Redfish hooks to log it as a Redfish message |
| 928 | // instead. There is no need to add it to the SEL, so just return success. |
| 929 | intel_oem::ipmi::sel::checkRedfishHooks( |
| 930 | recordID, recordType, timestamp, generatorID, evmRev, sensorType, |
| 931 | sensorNum, eventType, eventData1, eventData2, eventData3); |
Jason M. Bills | 99b78ec | 2019-01-18 10:42:18 -0800 | [diff] [blame] | 932 | |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 933 | uint16_t responseID = 0xFFFF; |
| 934 | return ipmi::responseSuccess(responseID); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 935 | } |
| 936 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 937 | ipmi::RspType<uint8_t> ipmiStorageClearSEL(ipmi::Context::ptr ctx, |
| 938 | uint16_t reservationID, |
| 939 | const std::array<uint8_t, 3>& clr, |
| 940 | uint8_t eraseOperation) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 941 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 942 | if (!checkSELReservation(reservationID)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 943 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 944 | return ipmi::responseInvalidReservationId(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 947 | static constexpr std::array<uint8_t, 3> clrExpected = {'C', 'L', 'R'}; |
| 948 | if (clr != clrExpected) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 949 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 950 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 951 | } |
| 952 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 953 | // Erasure status cannot be fetched, so always return erasure status as |
| 954 | // `erase completed`. |
| 955 | if (eraseOperation == ipmi::sel::getEraseStatus) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 956 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 957 | return ipmi::responseSuccess(ipmi::sel::eraseComplete); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 958 | } |
| 959 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 960 | // Check that initiate erase is correct |
| 961 | if (eraseOperation != ipmi::sel::initiateErase) |
| 962 | { |
| 963 | return ipmi::responseInvalidFieldRequest(); |
| 964 | } |
| 965 | |
| 966 | // Per the IPMI spec, need to cancel any reservation when the SEL is |
| 967 | // cleared |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 968 | cancelSELReservation(); |
| 969 | |
Jason M. Bills | 7944c30 | 2019-03-20 15:24:05 -0700 | [diff] [blame] | 970 | // Save the erase time |
| 971 | intel_oem::ipmi::sel::erase_time::save(); |
| 972 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 973 | // Clear the SEL by deleting the log files |
| 974 | std::vector<std::filesystem::path> selLogFiles; |
| 975 | if (getSELLogFiles(selLogFiles)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 976 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 977 | for (const std::filesystem::path& file : selLogFiles) |
| 978 | { |
| 979 | std::error_code ec; |
| 980 | std::filesystem::remove(file, ec); |
| 981 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 982 | } |
| 983 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 984 | // Reload rsyslog so it knows to start new log files |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 985 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 986 | sdbusplus::message::message rsyslogReload = dbus->new_method_call( |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 987 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 988 | "org.freedesktop.systemd1.Manager", "ReloadUnit"); |
| 989 | rsyslogReload.append("rsyslog.service", "replace"); |
| 990 | try |
| 991 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 992 | sdbusplus::message::message reloadResponse = dbus->call(rsyslogReload); |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 993 | } |
| 994 | catch (sdbusplus::exception_t& e) |
| 995 | { |
| 996 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 997 | } |
| 998 | |
| 999 | return ipmi::responseSuccess(ipmi::sel::eraseComplete); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
Jason M. Bills | 1a47462 | 2019-06-14 14:51:33 -0700 | [diff] [blame] | 1002 | ipmi::RspType<uint32_t> ipmiStorageGetSELTime() |
| 1003 | { |
| 1004 | struct timespec selTime = {}; |
| 1005 | |
| 1006 | if (clock_gettime(CLOCK_REALTIME, &selTime) < 0) |
| 1007 | { |
| 1008 | return ipmi::responseUnspecifiedError(); |
| 1009 | } |
| 1010 | |
| 1011 | return ipmi::responseSuccess(selTime.tv_sec); |
| 1012 | } |
| 1013 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1014 | ipmi::RspType<> ipmiStorageSetSELTime(uint32_t selTime) |
Jason M. Bills | cac97a5 | 2019-01-30 14:43:46 -0800 | [diff] [blame] | 1015 | { |
| 1016 | // Set SEL Time is not supported |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1017 | return ipmi::responseInvalidCommand(); |
Jason M. Bills | cac97a5 | 2019-01-30 14:43:46 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1020 | std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId) |
| 1021 | { |
| 1022 | std::vector<uint8_t> resp; |
| 1023 | if (index == 0) |
| 1024 | { |
| 1025 | Type12Record bmc = {}; |
| 1026 | bmc.header.record_id_lsb = recordId; |
| 1027 | bmc.header.record_id_msb = recordId >> 8; |
| 1028 | bmc.header.sdr_version = ipmiSdrVersion; |
| 1029 | bmc.header.record_type = 0x12; |
| 1030 | bmc.header.record_length = 0x1b; |
| 1031 | bmc.slaveAddress = 0x20; |
| 1032 | bmc.channelNumber = 0; |
| 1033 | bmc.powerStateNotification = 0; |
| 1034 | bmc.deviceCapabilities = 0xBF; |
| 1035 | bmc.reserved = 0; |
| 1036 | bmc.entityID = 0x2E; |
| 1037 | bmc.entityInstance = 1; |
| 1038 | bmc.oem = 0; |
| 1039 | bmc.typeLengthCode = 0xD0; |
| 1040 | std::string bmcName = "Basbrd Mgmt Ctlr"; |
| 1041 | std::copy(bmcName.begin(), bmcName.end(), bmc.name); |
| 1042 | uint8_t* bmcPtr = reinterpret_cast<uint8_t*>(&bmc); |
| 1043 | resp.insert(resp.end(), bmcPtr, bmcPtr + sizeof(Type12Record)); |
| 1044 | } |
| 1045 | else if (index == 1) |
| 1046 | { |
| 1047 | Type12Record me = {}; |
| 1048 | me.header.record_id_lsb = recordId; |
| 1049 | me.header.record_id_msb = recordId >> 8; |
| 1050 | me.header.sdr_version = ipmiSdrVersion; |
| 1051 | me.header.record_type = 0x12; |
| 1052 | me.header.record_length = 0x16; |
| 1053 | me.slaveAddress = 0x2C; |
| 1054 | me.channelNumber = 6; |
| 1055 | me.powerStateNotification = 0x24; |
| 1056 | me.deviceCapabilities = 0x21; |
| 1057 | me.reserved = 0; |
| 1058 | me.entityID = 0x2E; |
| 1059 | me.entityInstance = 2; |
| 1060 | me.oem = 0; |
| 1061 | me.typeLengthCode = 0xCB; |
| 1062 | std::string meName = "Mgmt Engine"; |
| 1063 | std::copy(meName.begin(), meName.end(), me.name); |
| 1064 | uint8_t* mePtr = reinterpret_cast<uint8_t*>(&me); |
| 1065 | resp.insert(resp.end(), mePtr, mePtr + sizeof(Type12Record)); |
| 1066 | } |
| 1067 | else |
| 1068 | { |
| 1069 | throw std::runtime_error("getType12SDRs:: Illegal index " + |
| 1070 | std::to_string(index)); |
| 1071 | } |
| 1072 | |
| 1073 | return resp; |
| 1074 | } |
| 1075 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 1076 | void registerStorageFunctions() |
| 1077 | { |
| 1078 | // <Get FRU Inventory Area Info> |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 1079 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1080 | ipmi::storage::cmdGetFruInventoryAreaInfo, |
| 1081 | ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1082 | // <READ FRU Data> |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 1083 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 1084 | ipmi::storage::cmdReadFruData, ipmi::Privilege::User, |
| 1085 | ipmiStorageReadFruData); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 1086 | |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1087 | // <WRITE FRU Data> |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 1088 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 1089 | ipmi::storage::cmdWriteFruData, |
| 1090 | ipmi::Privilege::Operator, ipmiStorageWriteFruData); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1091 | |
| 1092 | // <Get SEL Info> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1093 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
Jason M. Bills | 542498e | 2019-06-24 16:57:42 -0700 | [diff] [blame] | 1094 | ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User, |
| 1095 | ipmiStorageGetSELInfo); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1096 | |
| 1097 | // <Get SEL Entry> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1098 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
Jason M. Bills | 542498e | 2019-06-24 16:57:42 -0700 | [diff] [blame] | 1099 | ipmi::storage::cmdGetSelEntry, ipmi::Privilege::User, |
| 1100 | ipmiStorageGetSELEntry); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1101 | |
| 1102 | // <Add SEL Entry> |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 1103 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1104 | ipmi::storage::cmdAddSelEntry, |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 1105 | ipmi::Privilege::Operator, ipmiStorageAddSELEntry); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1106 | |
| 1107 | // <Clear SEL> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1108 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 1109 | ipmi::storage::cmdClearSel, ipmi::Privilege::Operator, |
| 1110 | ipmiStorageClearSEL); |
Jason M. Bills | cac97a5 | 2019-01-30 14:43:46 -0800 | [diff] [blame] | 1111 | |
Jason M. Bills | 1a47462 | 2019-06-14 14:51:33 -0700 | [diff] [blame] | 1112 | // <Get SEL Time> |
| 1113 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
Jason M. Bills | 542498e | 2019-06-24 16:57:42 -0700 | [diff] [blame] | 1114 | ipmi::storage::cmdGetSelTime, ipmi::Privilege::User, |
| 1115 | ipmiStorageGetSELTime); |
Jason M. Bills | 1a47462 | 2019-06-14 14:51:33 -0700 | [diff] [blame] | 1116 | |
Jason M. Bills | cac97a5 | 2019-01-30 14:43:46 -0800 | [diff] [blame] | 1117 | // <Set SEL Time> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1118 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 1119 | ipmi::storage::cmdSetSelTime, |
| 1120 | ipmi::Privilege::Operator, ipmiStorageSetSELTime); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 1121 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1122 | } // namespace storage |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1123 | } // namespace ipmi |