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 | |
Patrick Venture | ca99ef5 | 2019-10-20 14:00:50 -0700 | [diff] [blame] | 17 | #include "storagecommands.hpp" |
| 18 | |
| 19 | #include "commandutils.hpp" |
| 20 | #include "ipmi_to_redfish_hooks.hpp" |
| 21 | #include "sdrutils.hpp" |
Patrick Venture | c2a07d4 | 2020-05-30 16:35:03 -0700 | [diff] [blame] | 22 | #include "types.hpp" |
Patrick Venture | ca99ef5 | 2019-10-20 14:00:50 -0700 | [diff] [blame] | 23 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 24 | #include <boost/algorithm/string.hpp> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 25 | #include <boost/container/flat_map.hpp> |
James Feist | 2a265d5 | 2019-04-08 11:16:27 -0700 | [diff] [blame] | 26 | #include <ipmid/api.hpp> |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 27 | #include <ipmid/message.hpp> |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 28 | #include <phosphor-ipmi-host/selutility.hpp> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 29 | #include <phosphor-logging/log.hpp> |
| 30 | #include <sdbusplus/message/types.hpp> |
| 31 | #include <sdbusplus/timer.hpp> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 32 | |
| 33 | #include <filesystem> |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 34 | #include <fstream> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 35 | #include <iostream> |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 36 | #include <stdexcept> |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 37 | #include <unordered_set> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 38 | |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 39 | static constexpr bool DEBUG = false; |
| 40 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 41 | namespace intel_oem::ipmi::sel |
| 42 | { |
| 43 | static const std::filesystem::path selLogDir = "/var/log"; |
| 44 | static const std::string selLogFilename = "ipmi_sel"; |
| 45 | |
| 46 | static int getFileTimestamp(const std::filesystem::path& file) |
| 47 | { |
| 48 | struct stat st; |
| 49 | |
| 50 | if (stat(file.c_str(), &st) >= 0) |
| 51 | { |
| 52 | return st.st_mtime; |
| 53 | } |
| 54 | return ::ipmi::sel::invalidTimeStamp; |
| 55 | } |
| 56 | |
| 57 | namespace erase_time |
Jason M. Bills | 7944c30 | 2019-03-20 15:24:05 -0700 | [diff] [blame] | 58 | { |
| 59 | static constexpr const char* selEraseTimestamp = "/var/lib/ipmi/sel_erase_time"; |
| 60 | |
| 61 | void save() |
| 62 | { |
| 63 | // open the file, creating it if necessary |
| 64 | int fd = open(selEraseTimestamp, O_WRONLY | O_CREAT | O_CLOEXEC, 0644); |
| 65 | if (fd < 0) |
| 66 | { |
| 67 | std::cerr << "Failed to open file\n"; |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | // update the file timestamp to the current time |
| 72 | if (futimens(fd, NULL) < 0) |
| 73 | { |
| 74 | std::cerr << "Failed to update timestamp: " |
| 75 | << std::string(strerror(errno)); |
| 76 | } |
| 77 | close(fd); |
| 78 | } |
| 79 | |
| 80 | int get() |
| 81 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 82 | return getFileTimestamp(selEraseTimestamp); |
Jason M. Bills | 7944c30 | 2019-03-20 15:24:05 -0700 | [diff] [blame] | 83 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 84 | } // namespace erase_time |
| 85 | } // namespace intel_oem::ipmi::sel |
Jason M. Bills | 7944c30 | 2019-03-20 15:24:05 -0700 | [diff] [blame] | 86 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 87 | namespace ipmi |
| 88 | { |
| 89 | |
| 90 | namespace storage |
| 91 | { |
| 92 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 93 | constexpr static const size_t maxMessageSize = 64; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 94 | constexpr static const size_t maxFruSdrNameSize = 16; |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 95 | using ObjectType = boost::container::flat_map< |
| 96 | std::string, boost::container::flat_map<std::string, DbusVariant>>; |
| 97 | using ManagedObjectType = |
| 98 | boost::container::flat_map<sdbusplus::message::object_path, ObjectType>; |
| 99 | using ManagedEntry = std::pair<sdbusplus::message::object_path, ObjectType>; |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 100 | using GetObjectType = |
| 101 | std::vector<std::pair<std::string, std::vector<std::string>>>; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 102 | |
James Feist | 3bcba45 | 2018-12-20 12:31:03 -0800 | [diff] [blame] | 103 | constexpr static const char* fruDeviceServiceName = |
| 104 | "xyz.openbmc_project.FruDevice"; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 105 | constexpr static const size_t writeTimeoutSeconds = 10; |
Anoop S | 358e7df | 2020-05-05 16:43:34 +0000 | [diff] [blame] | 106 | constexpr static const char* chassisTypeRackMount = "23"; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 107 | |
Jason M. Bills | 4ed6f2c | 2019-04-02 12:21:25 -0700 | [diff] [blame] | 108 | // event direction is bit[7] of eventType where 1b = Deassertion event |
| 109 | constexpr static const uint8_t deassertionEvent = 0x80; |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 110 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 111 | static std::vector<uint8_t> fruCache; |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 112 | static uint16_t cacheBus = 0xFFFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 113 | static uint8_t cacheAddr = 0XFF; |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 114 | static uint8_t lastDevId = 0xFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 115 | |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 116 | static uint16_t writeBus = 0xFFFF; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 117 | static uint8_t writeAddr = 0XFF; |
| 118 | |
| 119 | std::unique_ptr<phosphor::Timer> writeTimer = nullptr; |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 120 | static std::vector<sdbusplus::bus::match_t> fruMatches; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 121 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 122 | ManagedObjectType frus; |
| 123 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 124 | // we unfortunately have to build a map of hashes in case there is a |
| 125 | // collision to verify our dev-id |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 126 | boost::container::flat_map<uint8_t, std::pair<uint16_t, uint8_t>> deviceHashes; |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 127 | // Map devId to Object Path |
| 128 | boost::container::flat_map<uint8_t, std::string> devicePath; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 129 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 130 | void registerStorageFunctions() __attribute__((constructor)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 131 | |
| 132 | bool writeFru() |
| 133 | { |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 134 | if (writeBus == 0xFFFF && writeAddr == 0xFF) |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 135 | { |
| 136 | return true; |
| 137 | } |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 138 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 139 | sdbusplus::message_t writeFru = dbus->new_method_call( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 140 | fruDeviceServiceName, "/xyz/openbmc_project/FruDevice", |
| 141 | "xyz.openbmc_project.FruDeviceManager", "WriteFru"); |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 142 | writeFru.append(writeBus, writeAddr, fruCache); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 143 | try |
| 144 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 145 | sdbusplus::message_t writeFruResp = dbus->call(writeFru); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 146 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 147 | catch (const sdbusplus::exception_t&) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 148 | { |
| 149 | // todo: log sel? |
| 150 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 151 | "error writing fru"); |
| 152 | return false; |
| 153 | } |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 154 | writeBus = 0xFFFF; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 155 | writeAddr = 0xFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 156 | return true; |
| 157 | } |
| 158 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 159 | void createTimers() |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 160 | { |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 161 | writeTimer = std::make_unique<phosphor::Timer>(writeFru); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 162 | } |
| 163 | |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 164 | void recalculateHashes() |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 165 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 166 | deviceHashes.clear(); |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 167 | devicePath.clear(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 168 | // hash the object paths to create unique device id's. increment on |
| 169 | // collision |
| 170 | std::hash<std::string> hasher; |
| 171 | for (const auto& fru : frus) |
| 172 | { |
| 173 | auto fruIface = fru.second.find("xyz.openbmc_project.FruDevice"); |
| 174 | if (fruIface == fru.second.end()) |
| 175 | { |
| 176 | continue; |
| 177 | } |
| 178 | |
| 179 | auto busFind = fruIface->second.find("BUS"); |
| 180 | auto addrFind = fruIface->second.find("ADDRESS"); |
| 181 | if (busFind == fruIface->second.end() || |
| 182 | addrFind == fruIface->second.end()) |
| 183 | { |
| 184 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 185 | "fru device missing Bus or Address", |
| 186 | phosphor::logging::entry("FRU=%s", fru.first.str.c_str())); |
| 187 | continue; |
| 188 | } |
| 189 | |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 190 | uint16_t fruBus = std::get<uint32_t>(busFind->second); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 191 | uint8_t fruAddr = std::get<uint32_t>(addrFind->second); |
Anoop S | 358e7df | 2020-05-05 16:43:34 +0000 | [diff] [blame] | 192 | auto chassisFind = fruIface->second.find("CHASSIS_TYPE"); |
| 193 | std::string chassisType; |
| 194 | if (chassisFind != fruIface->second.end()) |
| 195 | { |
| 196 | chassisType = std::get<std::string>(chassisFind->second); |
| 197 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 198 | |
| 199 | uint8_t fruHash = 0; |
Anoop S | 358e7df | 2020-05-05 16:43:34 +0000 | [diff] [blame] | 200 | if (chassisType.compare(chassisTypeRackMount) != 0) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 201 | { |
| 202 | fruHash = hasher(fru.first.str); |
| 203 | // can't be 0xFF based on spec, and 0 is reserved for baseboard |
| 204 | if (fruHash == 0 || fruHash == 0xFF) |
| 205 | { |
| 206 | fruHash = 1; |
| 207 | } |
| 208 | } |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 209 | std::pair<uint16_t, uint8_t> newDev(fruBus, fruAddr); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 210 | |
| 211 | bool emplacePassed = false; |
| 212 | while (!emplacePassed) |
| 213 | { |
| 214 | auto resp = deviceHashes.emplace(fruHash, newDev); |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 215 | |
| 216 | devicePath.emplace(fruHash, fru.first); |
| 217 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 218 | emplacePassed = resp.second; |
| 219 | if (!emplacePassed) |
| 220 | { |
| 221 | fruHash++; |
| 222 | // can't be 0xFF based on spec, and 0 is reserved for |
| 223 | // baseboard |
| 224 | if (fruHash == 0XFF) |
| 225 | { |
| 226 | fruHash = 0x1; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | } |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | void replaceCacheFru(const std::shared_ptr<sdbusplus::asio::connection>& bus, |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 234 | boost::asio::yield_context& yield) |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 235 | { |
| 236 | boost::system::error_code ec; |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 237 | // ObjectPaths and Services which implements "xyz.openbmc_project.FruDevice" |
| 238 | // interface |
| 239 | GetSubTreeType fruServices = bus->yield_method_call<GetSubTreeType>( |
| 240 | yield, ec, "xyz.openbmc_project.ObjectMapper", |
| 241 | "/xyz/openbmc_project/object_mapper", |
| 242 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, |
| 243 | std::array<const char*, 1>{"xyz.openbmc_project.FruDevice"}); |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 244 | |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 245 | if (ec) |
| 246 | { |
| 247 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 248 | "GetSubTree failed for FruDevice Interface ", |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 249 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 250 | |
| 251 | return; |
| 252 | } |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 253 | // Get List of services which have implemented FruDevice interface |
| 254 | std::unordered_set<std::string> services; |
| 255 | for (const auto& [path, serviceMap] : fruServices) |
| 256 | { |
| 257 | for (const auto& [service, interfaces] : serviceMap) |
| 258 | { |
| 259 | services.insert(service); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // GetAll the objects under services which implement FruDevice interface |
| 264 | for (const std::string& service : services) |
| 265 | { |
| 266 | ec = boost::system::errc::make_error_code(boost::system::errc::success); |
| 267 | ManagedObjectType obj = bus->yield_method_call<ManagedObjectType>( |
| 268 | yield, ec, service, "/", "org.freedesktop.DBus.ObjectManager", |
| 269 | "GetManagedObjects"); |
| 270 | if (ec) |
| 271 | { |
| 272 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 273 | "GetMangagedObjects failed", |
| 274 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 275 | continue; |
| 276 | } |
| 277 | // Save the object path which has FruDevice interface |
| 278 | for (const auto& [path, serviceMap] : fruServices) |
| 279 | { |
| 280 | for (const auto& serv : serviceMap) |
| 281 | { |
| 282 | if (serv.first == service) |
| 283 | { |
| 284 | auto fru = obj.find(path); |
| 285 | if (fru == obj.end()) |
| 286 | { |
| 287 | continue; |
| 288 | } |
| 289 | frus.emplace(fru->first, fru->second); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 295 | recalculateHashes(); |
| 296 | } |
| 297 | |
| 298 | ipmi::Cc getFru(ipmi::Context::ptr ctx, uint8_t devId) |
| 299 | { |
| 300 | if (lastDevId == devId && devId != 0xFF) |
| 301 | { |
| 302 | return ipmi::ccSuccess; |
| 303 | } |
| 304 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 305 | auto deviceFind = deviceHashes.find(devId); |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 306 | auto devPath = devicePath.find(devId); |
| 307 | if (deviceFind == deviceHashes.end() || devPath == devicePath.end()) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 308 | { |
| 309 | return IPMI_CC_SENSOR_INVALID; |
| 310 | } |
| 311 | |
PavanKumarIntel | 3432a0a | 2023-07-10 14:37:29 +0000 | [diff] [blame] | 312 | if (writeTimer->isRunning()) |
| 313 | { |
| 314 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 315 | "Couldn't get raw fru as fru is updating"); |
| 316 | return ipmi::ccBusy; |
| 317 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 318 | fruCache.clear(); |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 319 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 320 | cacheBus = deviceFind->second.first; |
| 321 | cacheAddr = deviceFind->second.second; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 322 | |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 323 | boost::system::error_code ec; |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 324 | GetObjectType fruService = ctx->bus->yield_method_call<GetObjectType>( |
| 325 | ctx->yield, ec, "xyz.openbmc_project.ObjectMapper", |
| 326 | "/xyz/openbmc_project/object_mapper", |
| 327 | "xyz.openbmc_project.ObjectMapper", "GetObject", devPath->second, |
| 328 | std::array<const char*, 1>{"xyz.openbmc_project.FruDevice"}); |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 329 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 330 | if (ec) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 331 | { |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 332 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Archana Kakani | f23fd54 | 2021-09-16 05:05:10 +0000 | [diff] [blame] | 333 | "Couldn't get raw fru because of service", |
| 334 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 335 | return ipmi::ccResponseError; |
| 336 | } |
| 337 | |
| 338 | bool foundFru = false; |
| 339 | for (auto& service : fruService) |
| 340 | { |
| 341 | fruCache = ctx->bus->yield_method_call<std::vector<uint8_t>>( |
| 342 | ctx->yield, ec, service.first, "/xyz/openbmc_project/FruDevice", |
| 343 | "xyz.openbmc_project.FruDeviceManager", "GetRawFru", cacheBus, |
| 344 | cacheAddr); |
| 345 | |
| 346 | if (!ec) |
| 347 | { |
| 348 | foundFru = true; |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | if (!foundFru) |
| 354 | { |
| 355 | phosphor::logging::log<phosphor::logging::level::ERR>( |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 356 | "Couldn't get raw fru", |
| 357 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 358 | cacheBus = 0xFFFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 359 | cacheAddr = 0xFF; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 360 | return ipmi::ccResponseError; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | lastDevId = devId; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 364 | return ipmi::ccSuccess; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 365 | } |
| 366 | |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 367 | void writeFruIfRunning() |
| 368 | { |
| 369 | if (!writeTimer->isRunning()) |
| 370 | { |
| 371 | return; |
| 372 | } |
| 373 | writeTimer->stop(); |
| 374 | writeFru(); |
| 375 | } |
| 376 | |
| 377 | void startMatch(void) |
| 378 | { |
| 379 | if (fruMatches.size()) |
| 380 | { |
| 381 | return; |
| 382 | } |
| 383 | |
| 384 | fruMatches.reserve(2); |
| 385 | |
| 386 | auto bus = getSdBus(); |
| 387 | fruMatches.emplace_back(*bus, |
| 388 | "type='signal',arg0path='/xyz/openbmc_project/" |
| 389 | "FruDevice/',member='InterfacesAdded'", |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 390 | [](sdbusplus::message_t& message) { |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 391 | sdbusplus::message::object_path path; |
| 392 | ObjectType object; |
| 393 | try |
| 394 | { |
| 395 | message.read(path, object); |
| 396 | } |
| 397 | catch (const sdbusplus::exception_t&) |
| 398 | { |
| 399 | return; |
| 400 | } |
| 401 | auto findType = object.find("xyz.openbmc_project.FruDevice"); |
| 402 | if (findType == object.end()) |
| 403 | { |
| 404 | return; |
| 405 | } |
| 406 | writeFruIfRunning(); |
| 407 | frus[path] = object; |
| 408 | recalculateHashes(); |
| 409 | lastDevId = 0xFF; |
| 410 | }); |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 411 | |
| 412 | fruMatches.emplace_back(*bus, |
| 413 | "type='signal',arg0path='/xyz/openbmc_project/" |
| 414 | "FruDevice/',member='InterfacesRemoved'", |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 415 | [](sdbusplus::message_t& message) { |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 416 | sdbusplus::message::object_path path; |
| 417 | std::set<std::string> interfaces; |
| 418 | try |
| 419 | { |
| 420 | message.read(path, interfaces); |
| 421 | } |
| 422 | catch (const sdbusplus::exception_t&) |
| 423 | { |
| 424 | return; |
| 425 | } |
| 426 | auto findType = interfaces.find("xyz.openbmc_project.FruDevice"); |
| 427 | if (findType == interfaces.end()) |
| 428 | { |
| 429 | return; |
| 430 | } |
| 431 | writeFruIfRunning(); |
| 432 | frus.erase(path); |
| 433 | recalculateHashes(); |
| 434 | lastDevId = 0xFF; |
| 435 | }); |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 436 | |
| 437 | // call once to populate |
| 438 | boost::asio::spawn(*getIoContext(), [](boost::asio::yield_context yield) { |
| 439 | replaceCacheFru(getSdBus(), yield); |
| 440 | }); |
| 441 | } |
| 442 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 443 | /** @brief implements the read FRU data command |
| 444 | * @param fruDeviceId - FRU Device ID |
| 445 | * @param fruInventoryOffset - FRU Inventory Offset to write |
| 446 | * @param countToRead - Count to read |
| 447 | * |
| 448 | * @returns ipmi completion code plus response data |
| 449 | * - countWritten - Count written |
| 450 | */ |
| 451 | ipmi::RspType<uint8_t, // Count |
| 452 | std::vector<uint8_t> // Requested data |
| 453 | > |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 454 | ipmiStorageReadFruData(ipmi::Context::ptr ctx, uint8_t fruDeviceId, |
| 455 | uint16_t fruInventoryOffset, uint8_t countToRead) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 456 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 457 | if (fruDeviceId == 0xFF) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 458 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 459 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 460 | } |
| 461 | |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 462 | ipmi::Cc status = getFru(ctx, fruDeviceId); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 463 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 464 | if (status != ipmi::ccSuccess) |
| 465 | { |
| 466 | return ipmi::response(status); |
| 467 | } |
| 468 | |
| 469 | size_t fromFruByteLen = 0; |
| 470 | if (countToRead + fruInventoryOffset < fruCache.size()) |
| 471 | { |
| 472 | fromFruByteLen = countToRead; |
| 473 | } |
| 474 | else if (fruCache.size() > fruInventoryOffset) |
| 475 | { |
| 476 | fromFruByteLen = fruCache.size() - fruInventoryOffset; |
| 477 | } |
| 478 | else |
| 479 | { |
srikanta mondal | 9210838 | 2020-02-27 18:53:20 +0000 | [diff] [blame] | 480 | return ipmi::responseReqDataLenExceeded(); |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | std::vector<uint8_t> requestedData; |
| 484 | |
| 485 | requestedData.insert( |
| 486 | requestedData.begin(), fruCache.begin() + fruInventoryOffset, |
| 487 | fruCache.begin() + fruInventoryOffset + fromFruByteLen); |
| 488 | |
Patrick Venture | 70b17f9 | 2019-10-28 20:01:53 -0700 | [diff] [blame] | 489 | return ipmi::responseSuccess(static_cast<uint8_t>(requestedData.size()), |
| 490 | requestedData); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 491 | } |
| 492 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 493 | /** @brief implements the write FRU data command |
| 494 | * @param fruDeviceId - FRU Device ID |
| 495 | * @param fruInventoryOffset - FRU Inventory Offset to write |
| 496 | * @param dataToWrite - Data to write |
| 497 | * |
| 498 | * @returns ipmi completion code plus response data |
| 499 | * - countWritten - Count written |
| 500 | */ |
| 501 | ipmi::RspType<uint8_t> |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 502 | ipmiStorageWriteFruData(ipmi::Context::ptr ctx, uint8_t fruDeviceId, |
| 503 | uint16_t fruInventoryOffset, |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 504 | std::vector<uint8_t>& dataToWrite) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 505 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 506 | if (fruDeviceId == 0xFF) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 507 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 508 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 509 | } |
| 510 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 511 | size_t writeLen = dataToWrite.size(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 512 | |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 513 | ipmi::Cc status = getFru(ctx, fruDeviceId); |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 514 | if (status != ipmi::ccSuccess) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 515 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 516 | return ipmi::response(status); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 517 | } |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 518 | int lastWriteAddr = fruInventoryOffset + writeLen; |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 519 | if (fruCache.size() < lastWriteAddr) |
| 520 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 521 | fruCache.resize(fruInventoryOffset + writeLen); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 522 | } |
| 523 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 524 | std::copy(dataToWrite.begin(), dataToWrite.begin() + writeLen, |
| 525 | fruCache.begin() + fruInventoryOffset); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 526 | |
| 527 | bool atEnd = false; |
| 528 | |
| 529 | if (fruCache.size() >= sizeof(FRUHeader)) |
| 530 | { |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 531 | FRUHeader* header = reinterpret_cast<FRUHeader*>(fruCache.data()); |
| 532 | |
Peter Lundgren | c59391f | 2019-11-19 14:26:15 -0800 | [diff] [blame] | 533 | int areaLength = 0; |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 534 | int lastRecordStart = std::max( |
Peter Lundgren | c59391f | 2019-11-19 14:26:15 -0800 | [diff] [blame] | 535 | {header->internalOffset, header->chassisOffset, header->boardOffset, |
| 536 | header->productOffset, header->multiRecordOffset}); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 537 | lastRecordStart *= 8; // header starts in are multiples of 8 bytes |
| 538 | |
Peter Lundgren | c59391f | 2019-11-19 14:26:15 -0800 | [diff] [blame] | 539 | if (header->multiRecordOffset) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 540 | { |
Peter Lundgren | c59391f | 2019-11-19 14:26:15 -0800 | [diff] [blame] | 541 | // This FRU has a MultiRecord Area |
| 542 | uint8_t endOfList = 0; |
| 543 | // Walk the MultiRecord headers until the last record |
| 544 | while (!endOfList) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 545 | { |
Peter Lundgren | c59391f | 2019-11-19 14:26:15 -0800 | [diff] [blame] | 546 | // The MSB in the second byte of the MultiRecord header signals |
| 547 | // "End of list" |
| 548 | endOfList = fruCache[lastRecordStart + 1] & 0x80; |
| 549 | // Third byte in the MultiRecord header is the length |
| 550 | areaLength = fruCache[lastRecordStart + 2]; |
| 551 | // This length is in bytes (not 8 bytes like other headers) |
| 552 | areaLength += 5; // The length omits the 5 byte header |
| 553 | if (!endOfList) |
| 554 | { |
| 555 | // Next MultiRecord header |
| 556 | lastRecordStart += areaLength; |
| 557 | } |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 558 | } |
| 559 | } |
Peter Lundgren | c59391f | 2019-11-19 14:26:15 -0800 | [diff] [blame] | 560 | else |
| 561 | { |
| 562 | // This FRU does not have a MultiRecord Area |
| 563 | // Get the length of the area in multiples of 8 bytes |
| 564 | if (lastWriteAddr > (lastRecordStart + 1)) |
| 565 | { |
| 566 | // second byte in record area is the length |
| 567 | areaLength = fruCache[lastRecordStart + 1]; |
| 568 | areaLength *= 8; // it is in multiples of 8 bytes |
| 569 | } |
| 570 | } |
| 571 | if (lastWriteAddr >= (areaLength + lastRecordStart)) |
| 572 | { |
| 573 | atEnd = true; |
| 574 | } |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 575 | } |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 576 | uint8_t countWritten = 0; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 577 | |
| 578 | writeBus = cacheBus; |
| 579 | writeAddr = cacheAddr; |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 580 | if (atEnd) |
| 581 | { |
| 582 | // cancel timer, we're at the end so might as well send it |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 583 | writeTimer->stop(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 584 | if (!writeFru()) |
| 585 | { |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 586 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 587 | } |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 588 | countWritten = std::min(fruCache.size(), static_cast<size_t>(0xFF)); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 589 | } |
| 590 | else |
| 591 | { |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 592 | // start a timer, if no further data is sent to check to see if it is |
| 593 | // valid |
| 594 | writeTimer->start(std::chrono::duration_cast<std::chrono::microseconds>( |
| 595 | std::chrono::seconds(writeTimeoutSeconds))); |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 596 | countWritten = 0; |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 597 | } |
| 598 | |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 599 | return ipmi::responseSuccess(countWritten); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 600 | } |
| 601 | |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 602 | /** @brief implements the get FRU inventory area info command |
| 603 | * @param fruDeviceId - FRU Device ID |
| 604 | * |
| 605 | * @returns IPMI completion code plus response data |
| 606 | * - inventorySize - Number of possible allocation units |
| 607 | * - accessType - Allocation unit size in bytes. |
| 608 | */ |
| 609 | ipmi::RspType<uint16_t, // inventorySize |
| 610 | uint8_t> // accessType |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 611 | ipmiStorageGetFruInvAreaInfo(ipmi::Context::ptr ctx, uint8_t fruDeviceId) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 612 | { |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 613 | if (fruDeviceId == 0xFF) |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 614 | { |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 615 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 616 | } |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 617 | |
Jayaprakash Mutyala | 1e2ab06 | 2020-08-03 16:57:00 +0000 | [diff] [blame] | 618 | ipmi::Cc ret = getFru(ctx, fruDeviceId); |
| 619 | if (ret != ipmi::ccSuccess) |
| 620 | { |
| 621 | return ipmi::response(ret); |
| 622 | } |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 623 | |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 624 | constexpr uint8_t accessType = |
| 625 | static_cast<uint8_t>(GetFRUAreaAccessType::byte); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 626 | |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 627 | return ipmi::responseSuccess(fruCache.size(), accessType); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 628 | } |
| 629 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 630 | ipmi_ret_t getFruSdrCount(ipmi::Context::ptr ctx, size_t& count) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 631 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 632 | count = deviceHashes.size(); |
| 633 | return IPMI_CC_OK; |
| 634 | } |
| 635 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 636 | ipmi_ret_t getFruSdrs(ipmi::Context::ptr ctx, size_t index, |
| 637 | get_sdr::SensorDataFruRecord& resp) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 638 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 639 | if (deviceHashes.size() < index) |
| 640 | { |
| 641 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 642 | } |
| 643 | auto device = deviceHashes.begin() + index; |
Johnathan Mantey | 0757400 | 2022-12-13 14:52:54 -0800 | [diff] [blame] | 644 | uint16_t& bus = device->second.first; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 645 | uint8_t& address = device->second.second; |
| 646 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 647 | boost::container::flat_map<std::string, DbusVariant>* fruData = nullptr; |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 648 | auto fru = std::find_if(frus.begin(), frus.end(), |
| 649 | [bus, address, &fruData](ManagedEntry& entry) { |
| 650 | auto findFruDevice = entry.second.find("xyz.openbmc_project.FruDevice"); |
| 651 | if (findFruDevice == entry.second.end()) |
| 652 | { |
| 653 | return false; |
| 654 | } |
| 655 | fruData = &(findFruDevice->second); |
| 656 | auto findBus = findFruDevice->second.find("BUS"); |
| 657 | auto findAddress = findFruDevice->second.find("ADDRESS"); |
| 658 | if (findBus == findFruDevice->second.end() || |
| 659 | findAddress == findFruDevice->second.end()) |
| 660 | { |
| 661 | return false; |
| 662 | } |
| 663 | if (std::get<uint32_t>(findBus->second) != bus) |
| 664 | { |
| 665 | return false; |
| 666 | } |
| 667 | if (std::get<uint32_t>(findAddress->second) != address) |
| 668 | { |
| 669 | return false; |
| 670 | } |
| 671 | return true; |
| 672 | }); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 673 | if (fru == frus.end()) |
| 674 | { |
| 675 | return IPMI_CC_RESPONSE_ERROR; |
| 676 | } |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 677 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 678 | #ifdef USING_ENTITY_MANAGER_DECORATORS |
| 679 | |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 680 | boost::container::flat_map<std::string, DbusVariant>* entityData = nullptr; |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 681 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 682 | // todo: this should really use caching, this is a very inefficient lookup |
| 683 | boost::system::error_code ec; |
| 684 | ManagedObjectType entities = ctx->bus->yield_method_call<ManagedObjectType>( |
Nan Zhou | 9d2894d | 2022-09-20 22:22:00 +0000 | [diff] [blame] | 685 | ctx->yield, ec, "xyz.openbmc_project.EntityManager", |
| 686 | "/xyz/openbmc_project/inventory", "org.freedesktop.DBus.ObjectManager", |
| 687 | "GetManagedObjects"); |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 688 | |
| 689 | if (ec) |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 690 | { |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 691 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 692 | "GetMangagedObjects for getSensorMap failed", |
| 693 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 694 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 695 | return ipmi::ccResponseError; |
| 696 | } |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 697 | |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 698 | auto entity = |
| 699 | std::find_if(entities.begin(), entities.end(), |
| 700 | [bus, address, &entityData](ManagedEntry& entry) { |
| 701 | auto findFruDevice = entry.second.find( |
| 702 | "xyz.openbmc_project.Inventory.Decorator.FruDevice"); |
| 703 | if (findFruDevice == entry.second.end()) |
| 704 | { |
| 705 | return false; |
| 706 | } |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 707 | |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 708 | // Integer fields added via Entity-Manager json are uint64_ts by |
| 709 | // default. |
| 710 | auto findBus = findFruDevice->second.find("Bus"); |
| 711 | auto findAddress = findFruDevice->second.find("Address"); |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 712 | |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 713 | if (findBus == findFruDevice->second.end() || |
| 714 | findAddress == findFruDevice->second.end()) |
| 715 | { |
| 716 | return false; |
| 717 | } |
| 718 | if ((std::get<uint64_t>(findBus->second) != bus) || |
| 719 | (std::get<uint64_t>(findAddress->second) != address)) |
| 720 | { |
| 721 | return false; |
| 722 | } |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 723 | |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 724 | // At this point we found the device entry and should return |
| 725 | // true. |
| 726 | auto findIpmiDevice = |
| 727 | entry.second.find("xyz.openbmc_project.Inventory.Decorator.Ipmi"); |
| 728 | if (findIpmiDevice != entry.second.end()) |
| 729 | { |
| 730 | entityData = &(findIpmiDevice->second); |
| 731 | } |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 732 | |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 733 | return true; |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 734 | }); |
| 735 | |
| 736 | if (entity == entities.end()) |
| 737 | { |
| 738 | if constexpr (DEBUG) |
| 739 | { |
| 740 | std::fprintf(stderr, "Ipmi or FruDevice Decorator interface " |
| 741 | "not found for Fru\n"); |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 744 | |
| 745 | #endif |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 746 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 747 | std::string name; |
| 748 | auto findProductName = fruData->find("BOARD_PRODUCT_NAME"); |
| 749 | auto findBoardName = fruData->find("PRODUCT_PRODUCT_NAME"); |
| 750 | if (findProductName != fruData->end()) |
| 751 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 752 | name = std::get<std::string>(findProductName->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 753 | } |
| 754 | else if (findBoardName != fruData->end()) |
| 755 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 756 | name = std::get<std::string>(findBoardName->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 757 | } |
| 758 | else |
| 759 | { |
| 760 | name = "UNKNOWN"; |
| 761 | } |
| 762 | if (name.size() > maxFruSdrNameSize) |
| 763 | { |
| 764 | name = name.substr(0, maxFruSdrNameSize); |
| 765 | } |
| 766 | size_t sizeDiff = maxFruSdrNameSize - name.size(); |
| 767 | |
| 768 | resp.header.record_id_lsb = 0x0; // calling code is to implement these |
| 769 | resp.header.record_id_msb = 0x0; |
| 770 | resp.header.sdr_version = ipmiSdrVersion; |
Patrick Venture | 73d0135 | 2019-10-11 18:32:59 -0700 | [diff] [blame] | 771 | resp.header.record_type = get_sdr::SENSOR_DATA_FRU_RECORD; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 772 | resp.header.record_length = sizeof(resp.body) + sizeof(resp.key) - sizeDiff; |
| 773 | resp.key.deviceAddress = 0x20; |
| 774 | resp.key.fruID = device->first; |
| 775 | resp.key.accessLun = 0x80; // logical / physical fru device |
| 776 | resp.key.channelNumber = 0x0; |
| 777 | resp.body.reserved = 0x0; |
| 778 | resp.body.deviceType = 0x10; |
James Feist | 4f86d1f | 2019-04-03 10:30:26 -0700 | [diff] [blame] | 779 | resp.body.deviceTypeModifier = 0x0; |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 780 | |
| 781 | uint8_t entityID = 0; |
| 782 | uint8_t entityInstance = 0x1; |
| 783 | |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 784 | #ifdef USING_ENTITY_MANAGER_DECORATORS |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 785 | if (entityData) |
| 786 | { |
| 787 | auto entityIdProperty = entityData->find("EntityId"); |
| 788 | auto entityInstanceProperty = entityData->find("EntityInstance"); |
| 789 | |
| 790 | if (entityIdProperty != entityData->end()) |
| 791 | { |
| 792 | entityID = static_cast<uint8_t>( |
| 793 | std::get<uint64_t>(entityIdProperty->second)); |
| 794 | } |
| 795 | if (entityInstanceProperty != entityData->end()) |
| 796 | { |
| 797 | entityInstance = static_cast<uint8_t>( |
| 798 | std::get<uint64_t>(entityInstanceProperty->second)); |
| 799 | } |
| 800 | } |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 801 | #endif |
Patrick Venture | 9ce789f | 2019-10-17 09:09:39 -0700 | [diff] [blame] | 802 | |
| 803 | resp.body.entityID = entityID; |
| 804 | resp.body.entityInstance = entityInstance; |
| 805 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 806 | resp.body.oem = 0x0; |
| 807 | resp.body.deviceIDLen = name.size(); |
| 808 | name.copy(resp.body.deviceID, name.size()); |
| 809 | |
| 810 | return IPMI_CC_OK; |
| 811 | } |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 812 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 813 | static bool getSELLogFiles(std::vector<std::filesystem::path>& selLogFiles) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 814 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 815 | // Loop through the directory looking for ipmi_sel log files |
| 816 | for (const std::filesystem::directory_entry& dirEnt : |
| 817 | std::filesystem::directory_iterator(intel_oem::ipmi::sel::selLogDir)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 818 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 819 | std::string filename = dirEnt.path().filename(); |
| 820 | if (boost::starts_with(filename, intel_oem::ipmi::sel::selLogFilename)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 821 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 822 | // If we find an ipmi_sel log file, save the path |
| 823 | selLogFiles.emplace_back(intel_oem::ipmi::sel::selLogDir / |
| 824 | filename); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 825 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 826 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 827 | // As the log files rotate, they are appended with a ".#" that is higher for |
| 828 | // the older logs. Since we don't expect more than 10 log files, we |
| 829 | // can just sort the list to get them in order from newest to oldest |
| 830 | std::sort(selLogFiles.begin(), selLogFiles.end()); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 831 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 832 | return !selLogFiles.empty(); |
| 833 | } |
| 834 | |
| 835 | static int countSELEntries() |
| 836 | { |
| 837 | // Get the list of ipmi_sel log files |
| 838 | std::vector<std::filesystem::path> selLogFiles; |
| 839 | if (!getSELLogFiles(selLogFiles)) |
| 840 | { |
| 841 | return 0; |
| 842 | } |
| 843 | int numSELEntries = 0; |
| 844 | // Loop through each log file and count the number of logs |
| 845 | for (const std::filesystem::path& file : selLogFiles) |
| 846 | { |
| 847 | std::ifstream logStream(file); |
| 848 | if (!logStream.is_open()) |
| 849 | { |
| 850 | continue; |
| 851 | } |
| 852 | |
| 853 | std::string line; |
| 854 | while (std::getline(logStream, line)) |
| 855 | { |
| 856 | numSELEntries++; |
| 857 | } |
| 858 | } |
| 859 | return numSELEntries; |
| 860 | } |
| 861 | |
| 862 | static bool findSELEntry(const int recordID, |
Patrick Venture | ff7e15b | 2019-09-25 16:48:26 -0700 | [diff] [blame] | 863 | const std::vector<std::filesystem::path>& selLogFiles, |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 864 | std::string& entry) |
| 865 | { |
| 866 | // Record ID is the first entry field following the timestamp. It is |
| 867 | // preceded by a space and followed by a comma |
| 868 | std::string search = " " + std::to_string(recordID) + ","; |
| 869 | |
| 870 | // Loop through the ipmi_sel log entries |
| 871 | for (const std::filesystem::path& file : selLogFiles) |
| 872 | { |
| 873 | std::ifstream logStream(file); |
| 874 | if (!logStream.is_open()) |
| 875 | { |
| 876 | continue; |
| 877 | } |
| 878 | |
| 879 | while (std::getline(logStream, entry)) |
| 880 | { |
| 881 | // Check if the record ID matches |
| 882 | if (entry.find(search) != std::string::npos) |
| 883 | { |
| 884 | return true; |
| 885 | } |
| 886 | } |
| 887 | } |
| 888 | return false; |
| 889 | } |
| 890 | |
| 891 | static uint16_t |
| 892 | getNextRecordID(const uint16_t recordID, |
Patrick Venture | ff7e15b | 2019-09-25 16:48:26 -0700 | [diff] [blame] | 893 | const std::vector<std::filesystem::path>& selLogFiles) |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 894 | { |
| 895 | uint16_t nextRecordID = recordID + 1; |
| 896 | std::string entry; |
| 897 | if (findSELEntry(nextRecordID, selLogFiles, entry)) |
| 898 | { |
| 899 | return nextRecordID; |
| 900 | } |
| 901 | else |
| 902 | { |
| 903 | return ipmi::sel::lastEntry; |
| 904 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 905 | } |
| 906 | |
Patrick Venture | ff7e15b | 2019-09-25 16:48:26 -0700 | [diff] [blame] | 907 | 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] | 908 | { |
| 909 | for (unsigned int i = 0; i < hexStr.size(); i += 2) |
| 910 | { |
| 911 | try |
| 912 | { |
| 913 | data.push_back(static_cast<uint8_t>( |
| 914 | std::stoul(hexStr.substr(i, 2), nullptr, 16))); |
| 915 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 916 | catch (const std::invalid_argument& e) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 917 | { |
| 918 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 919 | return -1; |
| 920 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 921 | catch (const std::out_of_range& e) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 922 | { |
| 923 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 924 | return -1; |
| 925 | } |
| 926 | } |
| 927 | return 0; |
| 928 | } |
| 929 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 930 | ipmi::RspType<uint8_t, // SEL version |
| 931 | uint16_t, // SEL entry count |
| 932 | uint16_t, // free space |
| 933 | uint32_t, // last add timestamp |
| 934 | uint32_t, // last erase timestamp |
| 935 | uint8_t> // operation support |
| 936 | ipmiStorageGetSELInfo() |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 937 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 938 | constexpr uint8_t selVersion = ipmi::sel::selVersion; |
| 939 | uint16_t entries = countSELEntries(); |
| 940 | uint32_t addTimeStamp = intel_oem::ipmi::sel::getFileTimestamp( |
| 941 | intel_oem::ipmi::sel::selLogDir / intel_oem::ipmi::sel::selLogFilename); |
| 942 | uint32_t eraseTimeStamp = intel_oem::ipmi::sel::erase_time::get(); |
| 943 | constexpr uint8_t operationSupport = |
| 944 | intel_oem::ipmi::sel::selOperationSupport; |
| 945 | constexpr uint16_t freeSpace = |
| 946 | 0xffff; // Spec indicates that more than 64kB is free |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 947 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 948 | return ipmi::responseSuccess(selVersion, entries, freeSpace, addTimeStamp, |
| 949 | eraseTimeStamp, operationSupport); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 950 | } |
| 951 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 952 | using systemEventType = std::tuple< |
| 953 | uint32_t, // Timestamp |
| 954 | uint16_t, // Generator ID |
| 955 | uint8_t, // EvM Rev |
| 956 | uint8_t, // Sensor Type |
| 957 | uint8_t, // Sensor Number |
| 958 | uint7_t, // Event Type |
| 959 | bool, // Event Direction |
| 960 | std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize>>; // Event Data |
| 961 | using oemTsEventType = std::tuple< |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 962 | uint32_t, // Timestamp |
| 963 | std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize>>; // Event Data |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 964 | using oemEventType = |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 965 | std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize>; // Event Data |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 966 | |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 967 | ipmi::RspType<uint16_t, // Next Record ID |
| 968 | uint16_t, // Record ID |
| 969 | uint8_t, // Record Type |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 970 | std::variant<systemEventType, oemTsEventType, |
| 971 | oemEventType>> // Record Content |
| 972 | ipmiStorageGetSELEntry(uint16_t reservationID, uint16_t targetID, |
| 973 | uint8_t offset, uint8_t size) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 974 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 975 | // Only support getting the entire SEL record. If a partial size or non-zero |
| 976 | // offset is requested, return an error |
| 977 | if (offset != 0 || size != ipmi::sel::entireRecord) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 978 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 979 | return ipmi::responseRetBytesUnavailable(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 980 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 981 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 982 | // Check the reservation ID if one is provided or required (only if the |
| 983 | // offset is non-zero) |
| 984 | if (reservationID != 0 || offset != 0) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 985 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 986 | if (!checkSELReservation(reservationID)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 987 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 988 | return ipmi::responseInvalidReservationId(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 992 | // Get the ipmi_sel log files |
| 993 | std::vector<std::filesystem::path> selLogFiles; |
| 994 | if (!getSELLogFiles(selLogFiles)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 995 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 996 | return ipmi::responseSensorInvalid(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 997 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 998 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 999 | std::string targetEntry; |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1000 | |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1001 | if (targetID == ipmi::sel::firstEntry) |
| 1002 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1003 | // The first entry will be at the top of the oldest log file |
| 1004 | std::ifstream logStream(selLogFiles.back()); |
| 1005 | if (!logStream.is_open()) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1006 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1007 | return ipmi::responseUnspecifiedError(); |
| 1008 | } |
| 1009 | |
| 1010 | if (!std::getline(logStream, targetEntry)) |
| 1011 | { |
| 1012 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | else if (targetID == ipmi::sel::lastEntry) |
| 1016 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1017 | // The last entry will be at the bottom of the newest log file |
| 1018 | std::ifstream logStream(selLogFiles.front()); |
| 1019 | if (!logStream.is_open()) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1020 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1021 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1022 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1023 | |
| 1024 | std::string line; |
| 1025 | while (std::getline(logStream, line)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1026 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1027 | targetEntry = line; |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1028 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1029 | } |
| 1030 | else |
| 1031 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1032 | if (!findSELEntry(targetID, selLogFiles, targetEntry)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1033 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1034 | return ipmi::responseSensorInvalid(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1035 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1036 | } |
| 1037 | |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 1038 | // The format of the ipmi_sel message is "<Timestamp> |
| 1039 | // <ID>,<Type>,<EventData>,[<Generator ID>,<Path>,<Direction>]". |
| 1040 | // First get the Timestamp |
| 1041 | size_t space = targetEntry.find_first_of(" "); |
| 1042 | if (space == std::string::npos) |
| 1043 | { |
| 1044 | return ipmi::responseUnspecifiedError(); |
| 1045 | } |
| 1046 | std::string entryTimestamp = targetEntry.substr(0, space); |
| 1047 | // Then get the log contents |
| 1048 | size_t entryStart = targetEntry.find_first_not_of(" ", space); |
| 1049 | if (entryStart == std::string::npos) |
| 1050 | { |
| 1051 | return ipmi::responseUnspecifiedError(); |
| 1052 | } |
| 1053 | std::string_view entry(targetEntry); |
| 1054 | entry.remove_prefix(entryStart); |
| 1055 | // Use split to separate the entry into its fields |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1056 | std::vector<std::string> targetEntryFields; |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 1057 | boost::split(targetEntryFields, entry, boost::is_any_of(","), |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1058 | boost::token_compress_on); |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 1059 | if (targetEntryFields.size() < 3) |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1060 | { |
| 1061 | return ipmi::responseUnspecifiedError(); |
| 1062 | } |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 1063 | std::string& recordIDStr = targetEntryFields[0]; |
| 1064 | std::string& recordTypeStr = targetEntryFields[1]; |
| 1065 | std::string& eventDataStr = targetEntryFields[2]; |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1066 | |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 1067 | uint16_t recordID; |
| 1068 | uint8_t recordType; |
| 1069 | try |
| 1070 | { |
| 1071 | recordID = std::stoul(recordIDStr); |
| 1072 | recordType = std::stoul(recordTypeStr, nullptr, 16); |
| 1073 | } |
| 1074 | catch (const std::invalid_argument&) |
| 1075 | { |
| 1076 | return ipmi::responseUnspecifiedError(); |
| 1077 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1078 | uint16_t nextRecordID = getNextRecordID(recordID, selLogFiles); |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1079 | std::vector<uint8_t> eventDataBytes; |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 1080 | if (fromHexStr(eventDataStr, eventDataBytes) < 0) |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1081 | { |
| 1082 | return ipmi::responseUnspecifiedError(); |
| 1083 | } |
| 1084 | |
| 1085 | if (recordType == intel_oem::ipmi::sel::systemEvent) |
| 1086 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1087 | // Get the timestamp |
| 1088 | std::tm timeStruct = {}; |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 1089 | std::istringstream entryStream(entryTimestamp); |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1090 | |
| 1091 | uint32_t timestamp = ipmi::sel::invalidTimeStamp; |
| 1092 | if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) |
| 1093 | { |
| 1094 | timestamp = std::mktime(&timeStruct); |
| 1095 | } |
| 1096 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1097 | // Set the event message revision |
| 1098 | uint8_t evmRev = intel_oem::ipmi::sel::eventMsgRev; |
| 1099 | |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 1100 | uint16_t generatorID = 0; |
| 1101 | uint8_t sensorType = 0; |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1102 | uint16_t sensorAndLun = 0; |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 1103 | uint8_t sensorNum = 0xFF; |
| 1104 | uint7_t eventType = 0; |
| 1105 | bool eventDir = 0; |
| 1106 | // System type events should have six fields |
| 1107 | if (targetEntryFields.size() >= 6) |
| 1108 | { |
| 1109 | std::string& generatorIDStr = targetEntryFields[3]; |
| 1110 | std::string& sensorPath = targetEntryFields[4]; |
| 1111 | std::string& eventDirStr = targetEntryFields[5]; |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1112 | |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 1113 | // Get the generator ID |
| 1114 | try |
| 1115 | { |
| 1116 | generatorID = std::stoul(generatorIDStr, nullptr, 16); |
| 1117 | } |
| 1118 | catch (const std::invalid_argument&) |
| 1119 | { |
| 1120 | std::cerr << "Invalid Generator ID\n"; |
| 1121 | } |
| 1122 | |
| 1123 | // Get the sensor type, sensor number, and event type for the sensor |
| 1124 | sensorType = getSensorTypeFromPath(sensorPath); |
Johnathan Mantey | 308c3a8 | 2020-07-22 11:50:54 -0700 | [diff] [blame] | 1125 | sensorAndLun = getSensorNumberFromPath(sensorPath); |
| 1126 | sensorNum = static_cast<uint8_t>(sensorAndLun); |
| 1127 | generatorID |= sensorAndLun >> 8; |
Jason M. Bills | 1a2fbdd | 2019-05-10 09:05:37 -0700 | [diff] [blame] | 1128 | eventType = getSensorEventTypeFromPath(sensorPath); |
| 1129 | |
| 1130 | // Get the event direction |
| 1131 | try |
| 1132 | { |
| 1133 | eventDir = std::stoul(eventDirStr) ? 0 : 1; |
| 1134 | } |
| 1135 | catch (const std::invalid_argument&) |
| 1136 | { |
| 1137 | std::cerr << "Invalid Event Direction\n"; |
| 1138 | } |
| 1139 | } |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1140 | |
| 1141 | // Only keep the eventData bytes that fit in the record |
| 1142 | std::array<uint8_t, intel_oem::ipmi::sel::systemEventSize> eventData{}; |
| 1143 | std::copy_n(eventDataBytes.begin(), |
| 1144 | std::min(eventDataBytes.size(), eventData.size()), |
| 1145 | eventData.begin()); |
| 1146 | |
| 1147 | return ipmi::responseSuccess( |
| 1148 | nextRecordID, recordID, recordType, |
| 1149 | systemEventType{timestamp, generatorID, evmRev, sensorType, |
| 1150 | sensorNum, eventType, eventDir, eventData}); |
| 1151 | } |
| 1152 | else if (recordType >= intel_oem::ipmi::sel::oemTsEventFirst && |
| 1153 | recordType <= intel_oem::ipmi::sel::oemTsEventLast) |
| 1154 | { |
| 1155 | // Get the timestamp |
| 1156 | std::tm timeStruct = {}; |
Jason M. Bills | 52aaa7d | 2019-05-08 15:21:39 -0700 | [diff] [blame] | 1157 | std::istringstream entryStream(entryTimestamp); |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1158 | |
| 1159 | uint32_t timestamp = ipmi::sel::invalidTimeStamp; |
| 1160 | if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) |
| 1161 | { |
| 1162 | timestamp = std::mktime(&timeStruct); |
| 1163 | } |
| 1164 | |
| 1165 | // Only keep the bytes that fit in the record |
| 1166 | std::array<uint8_t, intel_oem::ipmi::sel::oemTsEventSize> eventData{}; |
| 1167 | std::copy_n(eventDataBytes.begin(), |
| 1168 | std::min(eventDataBytes.size(), eventData.size()), |
| 1169 | eventData.begin()); |
| 1170 | |
| 1171 | return ipmi::responseSuccess(nextRecordID, recordID, recordType, |
| 1172 | oemTsEventType{timestamp, eventData}); |
| 1173 | } |
Patrick Venture | c5136aa | 2019-10-04 20:39:31 -0700 | [diff] [blame] | 1174 | else if (recordType >= intel_oem::ipmi::sel::oemEventFirst) |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1175 | { |
| 1176 | // Only keep the bytes that fit in the record |
| 1177 | std::array<uint8_t, intel_oem::ipmi::sel::oemEventSize> eventData{}; |
| 1178 | std::copy_n(eventDataBytes.begin(), |
| 1179 | std::min(eventDataBytes.size(), eventData.size()), |
| 1180 | eventData.begin()); |
| 1181 | |
| 1182 | return ipmi::responseSuccess(nextRecordID, recordID, recordType, |
| 1183 | eventData); |
| 1184 | } |
| 1185 | |
| 1186 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1187 | } |
| 1188 | |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 1189 | ipmi::RspType<uint16_t> ipmiStorageAddSELEntry( |
| 1190 | uint16_t recordID, uint8_t recordType, uint32_t timestamp, |
| 1191 | uint16_t generatorID, uint8_t evmRev, uint8_t sensorType, uint8_t sensorNum, |
| 1192 | uint8_t eventType, uint8_t eventData1, uint8_t eventData2, |
| 1193 | uint8_t eventData3) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1194 | { |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1195 | // Per the IPMI spec, need to cancel any reservation when a SEL entry is |
| 1196 | // added |
| 1197 | cancelSELReservation(); |
| 1198 | |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 1199 | // Send this request to the Redfish hooks to log it as a Redfish message |
| 1200 | // instead. There is no need to add it to the SEL, so just return success. |
| 1201 | intel_oem::ipmi::sel::checkRedfishHooks( |
| 1202 | recordID, recordType, timestamp, generatorID, evmRev, sensorType, |
| 1203 | sensorNum, eventType, eventData1, eventData2, eventData3); |
Jason M. Bills | 99b78ec | 2019-01-18 10:42:18 -0800 | [diff] [blame] | 1204 | |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 1205 | uint16_t responseID = 0xFFFF; |
| 1206 | return ipmi::responseSuccess(responseID); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1207 | } |
| 1208 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1209 | ipmi::RspType<uint8_t> ipmiStorageClearSEL(ipmi::Context::ptr ctx, |
| 1210 | uint16_t reservationID, |
| 1211 | const std::array<uint8_t, 3>& clr, |
| 1212 | uint8_t eraseOperation) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1213 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1214 | if (!checkSELReservation(reservationID)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1215 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1216 | return ipmi::responseInvalidReservationId(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1219 | static constexpr std::array<uint8_t, 3> clrExpected = {'C', 'L', 'R'}; |
| 1220 | if (clr != clrExpected) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1221 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1222 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1225 | // Erasure status cannot be fetched, so always return erasure status as |
| 1226 | // `erase completed`. |
| 1227 | if (eraseOperation == ipmi::sel::getEraseStatus) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1228 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1229 | return ipmi::responseSuccess(ipmi::sel::eraseComplete); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1232 | // Check that initiate erase is correct |
| 1233 | if (eraseOperation != ipmi::sel::initiateErase) |
| 1234 | { |
| 1235 | return ipmi::responseInvalidFieldRequest(); |
| 1236 | } |
| 1237 | |
| 1238 | // Per the IPMI spec, need to cancel any reservation when the SEL is |
| 1239 | // cleared |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1240 | cancelSELReservation(); |
| 1241 | |
Jason M. Bills | 7944c30 | 2019-03-20 15:24:05 -0700 | [diff] [blame] | 1242 | // Save the erase time |
| 1243 | intel_oem::ipmi::sel::erase_time::save(); |
| 1244 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1245 | // Clear the SEL by deleting the log files |
| 1246 | std::vector<std::filesystem::path> selLogFiles; |
| 1247 | if (getSELLogFiles(selLogFiles)) |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1248 | { |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1249 | for (const std::filesystem::path& file : selLogFiles) |
| 1250 | { |
| 1251 | std::error_code ec; |
| 1252 | std::filesystem::remove(file, ec); |
| 1253 | } |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1254 | } |
| 1255 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1256 | // Reload rsyslog so it knows to start new log files |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1257 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 1258 | sdbusplus::message_t rsyslogReload = dbus->new_method_call( |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1259 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 1260 | "org.freedesktop.systemd1.Manager", "ReloadUnit"); |
| 1261 | rsyslogReload.append("rsyslog.service", "replace"); |
| 1262 | try |
| 1263 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 1264 | sdbusplus::message_t reloadResponse = dbus->call(rsyslogReload); |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1265 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 1266 | catch (const sdbusplus::exception_t& e) |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1267 | { |
| 1268 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 1269 | } |
| 1270 | |
| 1271 | return ipmi::responseSuccess(ipmi::sel::eraseComplete); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
Jason M. Bills | 1a47462 | 2019-06-14 14:51:33 -0700 | [diff] [blame] | 1274 | ipmi::RspType<uint32_t> ipmiStorageGetSELTime() |
| 1275 | { |
| 1276 | struct timespec selTime = {}; |
| 1277 | |
| 1278 | if (clock_gettime(CLOCK_REALTIME, &selTime) < 0) |
| 1279 | { |
| 1280 | return ipmi::responseUnspecifiedError(); |
| 1281 | } |
| 1282 | |
| 1283 | return ipmi::responseSuccess(selTime.tv_sec); |
| 1284 | } |
| 1285 | |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1286 | ipmi::RspType<> ipmiStorageSetSELTime(uint32_t selTime) |
Jason M. Bills | cac97a5 | 2019-01-30 14:43:46 -0800 | [diff] [blame] | 1287 | { |
| 1288 | // Set SEL Time is not supported |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1289 | return ipmi::responseInvalidCommand(); |
Jason M. Bills | cac97a5 | 2019-01-30 14:43:46 -0800 | [diff] [blame] | 1290 | } |
| 1291 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1292 | std::vector<uint8_t> getType12SDRs(uint16_t index, uint16_t recordId) |
| 1293 | { |
| 1294 | std::vector<uint8_t> resp; |
| 1295 | if (index == 0) |
| 1296 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1297 | std::string bmcName = "Basbrd Mgmt Ctlr"; |
Johnathan Mantey | f4d5e05 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 1298 | Type12Record bmc(recordId, 0x20, 0, 0, 0xbf, 0x2e, 1, 0, bmcName); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1299 | uint8_t* bmcPtr = reinterpret_cast<uint8_t*>(&bmc); |
| 1300 | resp.insert(resp.end(), bmcPtr, bmcPtr + sizeof(Type12Record)); |
| 1301 | } |
| 1302 | else if (index == 1) |
| 1303 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1304 | std::string meName = "Mgmt Engine"; |
Johnathan Mantey | f4d5e05 | 2021-09-22 12:58:08 -0700 | [diff] [blame] | 1305 | Type12Record me(recordId, 0x2c, 6, 0x24, 0x21, 0x2e, 2, 0, meName); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1306 | uint8_t* mePtr = reinterpret_cast<uint8_t*>(&me); |
| 1307 | resp.insert(resp.end(), mePtr, mePtr + sizeof(Type12Record)); |
| 1308 | } |
| 1309 | else |
| 1310 | { |
| 1311 | throw std::runtime_error("getType12SDRs:: Illegal index " + |
| 1312 | std::to_string(index)); |
| 1313 | } |
| 1314 | |
| 1315 | return resp; |
| 1316 | } |
| 1317 | |
Yong Li | fee5e4c | 2020-01-17 19:36:29 +0800 | [diff] [blame] | 1318 | std::vector<uint8_t> getNMDiscoverySDR(uint16_t index, uint16_t recordId) |
| 1319 | { |
| 1320 | std::vector<uint8_t> resp; |
| 1321 | if (index == 0) |
| 1322 | { |
| 1323 | NMDiscoveryRecord nm = {}; |
| 1324 | nm.header.record_id_lsb = recordId; |
| 1325 | nm.header.record_id_msb = recordId >> 8; |
| 1326 | nm.header.sdr_version = ipmiSdrVersion; |
| 1327 | nm.header.record_type = 0xC0; |
| 1328 | nm.header.record_length = 0xB; |
| 1329 | nm.oemID0 = 0x57; |
| 1330 | nm.oemID1 = 0x1; |
| 1331 | nm.oemID2 = 0x0; |
| 1332 | nm.subType = 0x0D; |
| 1333 | nm.version = 0x1; |
Matt Simmering | 80d4d5f | 2023-02-15 15:18:51 -0800 | [diff] [blame] | 1334 | nm.targetAddress = 0x2C; |
Yong Li | fee5e4c | 2020-01-17 19:36:29 +0800 | [diff] [blame] | 1335 | nm.channelNumber = 0x60; |
| 1336 | nm.healthEventSensor = 0x19; |
| 1337 | nm.exceptionEventSensor = 0x18; |
| 1338 | nm.operationalCapSensor = 0x1A; |
| 1339 | nm.thresholdExceededSensor = 0x1B; |
| 1340 | |
| 1341 | uint8_t* nmPtr = reinterpret_cast<uint8_t*>(&nm); |
| 1342 | resp.insert(resp.end(), nmPtr, nmPtr + sizeof(NMDiscoveryRecord)); |
| 1343 | } |
| 1344 | else |
| 1345 | { |
| 1346 | throw std::runtime_error("getNMDiscoverySDR:: Illegal index " + |
| 1347 | std::to_string(index)); |
| 1348 | } |
| 1349 | |
| 1350 | return resp; |
| 1351 | } |
| 1352 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 1353 | void registerStorageFunctions() |
| 1354 | { |
James Feist | 2569025 | 2019-12-23 12:25:49 -0800 | [diff] [blame] | 1355 | createTimers(); |
James Feist | e4f710d | 2020-05-20 15:50:30 -0700 | [diff] [blame] | 1356 | startMatch(); |
| 1357 | |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 1358 | // <Get FRU Inventory Area Info> |
jayaprakash Mutyala | d33acd6 | 2019-05-17 19:37:25 +0000 | [diff] [blame] | 1359 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1360 | ipmi::storage::cmdGetFruInventoryAreaInfo, |
| 1361 | ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1362 | // <READ FRU Data> |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 1363 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 1364 | ipmi::storage::cmdReadFruData, ipmi::Privilege::User, |
| 1365 | ipmiStorageReadFruData); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 1366 | |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1367 | // <WRITE FRU Data> |
jayaprakash Mutyala | 5f4194e | 2019-05-20 16:17:01 +0000 | [diff] [blame] | 1368 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 1369 | ipmi::storage::cmdWriteFruData, |
| 1370 | ipmi::Privilege::Operator, ipmiStorageWriteFruData); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1371 | |
| 1372 | // <Get SEL Info> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1373 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
Jason M. Bills | 542498e | 2019-06-24 16:57:42 -0700 | [diff] [blame] | 1374 | ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User, |
| 1375 | ipmiStorageGetSELInfo); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1376 | |
| 1377 | // <Get SEL Entry> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1378 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
Jason M. Bills | 542498e | 2019-06-24 16:57:42 -0700 | [diff] [blame] | 1379 | ipmi::storage::cmdGetSelEntry, ipmi::Privilege::User, |
| 1380 | ipmiStorageGetSELEntry); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1381 | |
| 1382 | // <Add SEL Entry> |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 1383 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1384 | ipmi::storage::cmdAddSelEntry, |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 1385 | ipmi::Privilege::Operator, ipmiStorageAddSELEntry); |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1386 | |
| 1387 | // <Clear SEL> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1388 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 1389 | ipmi::storage::cmdClearSel, ipmi::Privilege::Operator, |
| 1390 | ipmiStorageClearSEL); |
Jason M. Bills | cac97a5 | 2019-01-30 14:43:46 -0800 | [diff] [blame] | 1391 | |
Jason M. Bills | 1a47462 | 2019-06-14 14:51:33 -0700 | [diff] [blame] | 1392 | // <Get SEL Time> |
| 1393 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
Jason M. Bills | 542498e | 2019-06-24 16:57:42 -0700 | [diff] [blame] | 1394 | ipmi::storage::cmdGetSelTime, ipmi::Privilege::User, |
| 1395 | ipmiStorageGetSELTime); |
Jason M. Bills | 1a47462 | 2019-06-14 14:51:33 -0700 | [diff] [blame] | 1396 | |
Jason M. Bills | cac97a5 | 2019-01-30 14:43:46 -0800 | [diff] [blame] | 1397 | // <Set SEL Time> |
Jason M. Bills | 1d4d54d | 2019-04-23 11:26:11 -0700 | [diff] [blame] | 1398 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 1399 | ipmi::storage::cmdSetSelTime, |
| 1400 | ipmi::Privilege::Operator, ipmiStorageSetSELTime); |
Jason M. Bills | e2d1aee | 2018-10-03 15:57:18 -0700 | [diff] [blame] | 1401 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1402 | } // namespace storage |
Jason M. Bills | c04e2e7 | 2018-11-28 15:15:56 -0800 | [diff] [blame] | 1403 | } // namespace ipmi |