Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2017 2018 Intel Corporation |
| 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 | f777e1b | 2019-09-25 17:45:44 -0700 | [diff] [blame^] | 17 | #include <algorithm> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 18 | #include <boost/algorithm/string.hpp> |
| 19 | #include <boost/container/flat_map.hpp> |
| 20 | #include <chrono> |
| 21 | #include <cmath> |
| 22 | #include <commandutils.hpp> |
Patrick Venture | 5c2d26e | 2019-09-25 17:43:53 -0700 | [diff] [blame] | 23 | #include <cstring> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 24 | #include <iostream> |
Jason M. Bills | 99b78ec | 2019-01-18 10:42:18 -0800 | [diff] [blame] | 25 | #include <ipmi_to_redfish_hooks.hpp> |
James Feist | 2a265d5 | 2019-04-08 11:16:27 -0700 | [diff] [blame] | 26 | #include <ipmid/api.hpp> |
Vernon Mauery | 5480ef6 | 2019-03-20 13:43:11 -0700 | [diff] [blame] | 27 | #include <ipmid/utils.hpp> |
Patrick Venture | b10ec8b | 2019-09-25 16:39:14 -0700 | [diff] [blame] | 28 | #include <map> |
Patrick Venture | c4e9de6 | 2019-09-25 17:40:54 -0700 | [diff] [blame] | 29 | #include <optional> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 30 | #include <phosphor-logging/log.hpp> |
| 31 | #include <sdbusplus/bus.hpp> |
| 32 | #include <sdrutils.hpp> |
| 33 | #include <sensorcommands.hpp> |
| 34 | #include <sensorutils.hpp> |
| 35 | #include <storagecommands.hpp> |
| 36 | #include <string> |
Patrick Venture | 38f46f2 | 2019-09-25 17:41:26 -0700 | [diff] [blame] | 37 | #include <utility> |
Patrick Venture | eb02a5c | 2019-09-25 17:44:43 -0700 | [diff] [blame] | 38 | #include <variant> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 39 | |
| 40 | namespace ipmi |
| 41 | { |
| 42 | using ManagedObjectType = |
| 43 | std::map<sdbusplus::message::object_path, |
| 44 | std::map<std::string, std::map<std::string, DbusVariant>>>; |
| 45 | |
| 46 | using SensorMap = std::map<std::string, std::map<std::string, DbusVariant>>; |
| 47 | |
| 48 | static constexpr int sensorListUpdatePeriod = 10; |
| 49 | static constexpr int sensorMapUpdatePeriod = 2; |
| 50 | |
| 51 | constexpr size_t maxSDRTotalSize = |
| 52 | 76; // Largest SDR Record Size (type 01) + SDR Overheader Size |
| 53 | constexpr static const uint32_t noTimestamp = 0xFFFFFFFF; |
| 54 | |
| 55 | static uint16_t sdrReservationID; |
| 56 | static uint32_t sdrLastAdd = noTimestamp; |
| 57 | static uint32_t sdrLastRemove = noTimestamp; |
| 58 | |
Richard Marian Thomaiyar | 01fbcb5 | 2018-11-19 22:04:34 +0530 | [diff] [blame] | 59 | SensorSubTree sensorTree; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 60 | static boost::container::flat_map<std::string, ManagedObjectType> SensorCache; |
| 61 | |
Jason M. Bills | 17add59 | 2018-11-12 14:30:12 -0800 | [diff] [blame] | 62 | // Specify the comparison required to sort and find char* map objects |
| 63 | struct CmpStr |
| 64 | { |
| 65 | bool operator()(const char *a, const char *b) const |
| 66 | { |
| 67 | return std::strcmp(a, b) < 0; |
| 68 | } |
| 69 | }; |
| 70 | const static boost::container::flat_map<const char *, SensorUnits, CmpStr> |
| 71 | sensorUnits{{{"temperature", SensorUnits::degreesC}, |
| 72 | {"voltage", SensorUnits::volts}, |
| 73 | {"current", SensorUnits::amps}, |
| 74 | {"fan_tach", SensorUnits::rpm}, |
| 75 | {"power", SensorUnits::watts}}}; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 76 | |
| 77 | void registerSensorFunctions() __attribute__((constructor)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 78 | |
| 79 | static sdbusplus::bus::match::match sensorAdded( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 80 | *getSdBus(), |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 81 | "type='signal',member='InterfacesAdded',arg0path='/xyz/openbmc_project/" |
| 82 | "sensors/'", |
| 83 | [](sdbusplus::message::message &m) { |
| 84 | sensorTree.clear(); |
| 85 | sdrLastAdd = std::chrono::duration_cast<std::chrono::seconds>( |
| 86 | std::chrono::system_clock::now().time_since_epoch()) |
| 87 | .count(); |
| 88 | }); |
| 89 | |
| 90 | static sdbusplus::bus::match::match sensorRemoved( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 91 | *getSdBus(), |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 92 | "type='signal',member='InterfacesRemoved',arg0path='/xyz/openbmc_project/" |
| 93 | "sensors/'", |
| 94 | [](sdbusplus::message::message &m) { |
| 95 | sensorTree.clear(); |
| 96 | sdrLastRemove = std::chrono::duration_cast<std::chrono::seconds>( |
| 97 | std::chrono::system_clock::now().time_since_epoch()) |
| 98 | .count(); |
| 99 | }); |
| 100 | |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 101 | // this keeps track of deassertions for sensor event status command. A |
| 102 | // deasertion can only happen if an assertion was seen first. |
| 103 | static boost::container::flat_map< |
| 104 | std::string, boost::container::flat_map<std::string, std::optional<bool>>> |
| 105 | thresholdDeassertMap; |
| 106 | |
| 107 | static sdbusplus::bus::match::match thresholdChanged( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 108 | *getSdBus(), |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 109 | "type='signal',member='PropertiesChanged',interface='org.freedesktop.DBus." |
| 110 | "Properties',arg0namespace='xyz.openbmc_project.Sensor.Threshold'", |
| 111 | [](sdbusplus::message::message &m) { |
| 112 | boost::container::flat_map<std::string, std::variant<bool, double>> |
| 113 | values; |
| 114 | m.read(std::string(), values); |
| 115 | |
| 116 | auto findAssert = |
| 117 | std::find_if(values.begin(), values.end(), [](const auto &pair) { |
| 118 | return pair.first.find("Alarm") != std::string::npos; |
| 119 | }); |
| 120 | if (findAssert != values.end()) |
| 121 | { |
| 122 | auto ptr = std::get_if<bool>(&(findAssert->second)); |
| 123 | if (ptr == nullptr) |
| 124 | { |
| 125 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 126 | "thresholdChanged: Assert non bool"); |
| 127 | return; |
| 128 | } |
| 129 | if (*ptr) |
| 130 | { |
| 131 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 132 | "thresholdChanged: Assert", |
| 133 | phosphor::logging::entry("SENSOR=%s", m.get_path())); |
| 134 | thresholdDeassertMap[m.get_path()][findAssert->first] = *ptr; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | auto &value = |
| 139 | thresholdDeassertMap[m.get_path()][findAssert->first]; |
| 140 | if (value) |
| 141 | { |
| 142 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 143 | "thresholdChanged: deassert", |
| 144 | phosphor::logging::entry("SENSOR=%s", m.get_path())); |
| 145 | value = *ptr; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | }); |
| 150 | |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 151 | static void getSensorMaxMin(const SensorMap &sensorMap, double &max, |
| 152 | double &min) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 153 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 154 | max = 127; |
| 155 | min = -128; |
| 156 | |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 157 | auto sensorObject = sensorMap.find("xyz.openbmc_project.Sensor.Value"); |
| 158 | auto critical = |
| 159 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 160 | auto warning = |
| 161 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 162 | |
| 163 | if (sensorObject != sensorMap.end()) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 164 | { |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 165 | auto maxMap = sensorObject->second.find("MaxValue"); |
| 166 | auto minMap = sensorObject->second.find("MinValue"); |
| 167 | |
| 168 | if (maxMap != sensorObject->second.end()) |
| 169 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 170 | max = std::visit(VariantToDoubleVisitor(), maxMap->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 171 | } |
| 172 | if (minMap != sensorObject->second.end()) |
| 173 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 174 | min = std::visit(VariantToDoubleVisitor(), minMap->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 175 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 176 | } |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 177 | if (critical != sensorMap.end()) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 178 | { |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 179 | auto lower = critical->second.find("CriticalLow"); |
| 180 | auto upper = critical->second.find("CriticalHigh"); |
| 181 | if (lower != critical->second.end()) |
| 182 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 183 | double value = std::visit(VariantToDoubleVisitor(), lower->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 184 | min = std::min(value, min); |
| 185 | } |
| 186 | if (upper != critical->second.end()) |
| 187 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 188 | double value = std::visit(VariantToDoubleVisitor(), upper->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 189 | max = std::max(value, max); |
| 190 | } |
| 191 | } |
| 192 | if (warning != sensorMap.end()) |
| 193 | { |
| 194 | |
| 195 | auto lower = warning->second.find("WarningLow"); |
| 196 | auto upper = warning->second.find("WarningHigh"); |
| 197 | if (lower != warning->second.end()) |
| 198 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 199 | double value = std::visit(VariantToDoubleVisitor(), lower->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 200 | min = std::min(value, min); |
| 201 | } |
| 202 | if (upper != warning->second.end()) |
| 203 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 204 | double value = std::visit(VariantToDoubleVisitor(), upper->second); |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 205 | max = std::max(value, max); |
| 206 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 210 | static bool getSensorMap(std::string sensorConnection, std::string sensorPath, |
| 211 | SensorMap &sensorMap) |
| 212 | { |
| 213 | static boost::container::flat_map< |
| 214 | std::string, std::chrono::time_point<std::chrono::steady_clock>> |
| 215 | updateTimeMap; |
| 216 | |
| 217 | auto updateFind = updateTimeMap.find(sensorConnection); |
| 218 | auto lastUpdate = std::chrono::time_point<std::chrono::steady_clock>(); |
| 219 | if (updateFind != updateTimeMap.end()) |
| 220 | { |
| 221 | lastUpdate = updateFind->second; |
| 222 | } |
| 223 | |
| 224 | auto now = std::chrono::steady_clock::now(); |
| 225 | |
| 226 | if (std::chrono::duration_cast<std::chrono::seconds>(now - lastUpdate) |
| 227 | .count() > sensorMapUpdatePeriod) |
| 228 | { |
| 229 | updateTimeMap[sensorConnection] = now; |
| 230 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 231 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 232 | auto managedObj = dbus->new_method_call( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 233 | sensorConnection.c_str(), "/", "org.freedesktop.DBus.ObjectManager", |
| 234 | "GetManagedObjects"); |
| 235 | |
| 236 | ManagedObjectType managedObjects; |
| 237 | try |
| 238 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 239 | auto reply = dbus->call(managedObj); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 240 | reply.read(managedObjects); |
| 241 | } |
| 242 | catch (sdbusplus::exception_t &) |
| 243 | { |
| 244 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 245 | "Error getting managed objects from connection", |
| 246 | phosphor::logging::entry("CONNECTION=%s", |
| 247 | sensorConnection.c_str())); |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | SensorCache[sensorConnection] = managedObjects; |
| 252 | } |
| 253 | auto connection = SensorCache.find(sensorConnection); |
| 254 | if (connection == SensorCache.end()) |
| 255 | { |
| 256 | return false; |
| 257 | } |
| 258 | auto path = connection->second.find(sensorPath); |
| 259 | if (path == connection->second.end()) |
| 260 | { |
| 261 | return false; |
| 262 | } |
| 263 | sensorMap = path->second; |
| 264 | |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | /* sensor commands */ |
| 269 | ipmi_ret_t ipmiSensorWildcardHandler(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 270 | ipmi_request_t request, |
| 271 | ipmi_response_t response, |
| 272 | ipmi_data_len_t dataLen, |
| 273 | ipmi_context_t context) |
| 274 | { |
| 275 | *dataLen = 0; |
| 276 | printCommand(+netfn, +cmd); |
| 277 | return IPMI_CC_INVALID; |
| 278 | } |
| 279 | |
James Feist | 7aaf3fe | 2019-06-25 11:52:11 -0700 | [diff] [blame] | 280 | namespace meHealth |
| 281 | { |
| 282 | constexpr const char *busname = "xyz.openbmc_project.NodeManagerProxy"; |
| 283 | constexpr const char *path = "/xyz/openbmc_project/status/me"; |
| 284 | constexpr const char *interface = "xyz.openbmc_project.SetHealth"; |
| 285 | constexpr const char *method = "SetHealth"; |
| 286 | constexpr const char *critical = "critical"; |
| 287 | constexpr const char *warning = "warning"; |
| 288 | constexpr const char *ok = "ok"; |
| 289 | } // namespace meHealth |
| 290 | |
| 291 | static void setMeStatus(uint8_t eventData2, uint8_t eventData3, bool disable) |
| 292 | { |
| 293 | constexpr const std::array<uint8_t, 10> critical = { |
| 294 | 0x1, 0x2, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xD, 0xE}; |
| 295 | constexpr const std::array<uint8_t, 5> warning = {0x3, 0xA, 0x13, 0x19, |
| 296 | 0x1A}; |
| 297 | |
| 298 | std::string state; |
| 299 | if (std::find(critical.begin(), critical.end(), eventData2) != |
| 300 | critical.end()) |
| 301 | { |
| 302 | state = meHealth::critical; |
| 303 | } |
| 304 | // special case 0x3 as we only care about a few states |
| 305 | else if (eventData2 == 0x3) |
| 306 | { |
| 307 | if (eventData3 <= 0x2) |
| 308 | { |
| 309 | state = meHealth::warning; |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | return; |
| 314 | } |
| 315 | } |
| 316 | else if (std::find(warning.begin(), warning.end(), eventData2) != |
| 317 | warning.end()) |
| 318 | { |
| 319 | state = meHealth::warning; |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | return; |
| 324 | } |
| 325 | if (disable) |
| 326 | { |
| 327 | state = meHealth::ok; |
| 328 | } |
| 329 | |
| 330 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 331 | auto setHealth = |
| 332 | dbus->new_method_call(meHealth::busname, meHealth::path, |
| 333 | meHealth::interface, meHealth::method); |
| 334 | setHealth.append(std::to_string(static_cast<size_t>(eventData2)), state); |
| 335 | try |
| 336 | { |
| 337 | dbus->call(setHealth); |
| 338 | } |
| 339 | catch (sdbusplus::exception_t &) |
| 340 | { |
| 341 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 342 | "Failed to set ME Health"); |
| 343 | } |
| 344 | } |
| 345 | |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 346 | ipmi::RspType<> ipmiSenPlatformEvent(ipmi::message::Payload &p) |
| 347 | { |
James Feist | 7aaf3fe | 2019-06-25 11:52:11 -0700 | [diff] [blame] | 348 | constexpr const uint8_t meId = 0x2C; |
| 349 | constexpr const uint8_t meSensorNum = 0x17; |
| 350 | constexpr const uint8_t disabled = 0x80; |
| 351 | |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 352 | uint8_t generatorID = 0; |
| 353 | uint8_t evmRev = 0; |
| 354 | uint8_t sensorType = 0; |
| 355 | uint8_t sensorNum = 0; |
| 356 | uint8_t eventType = 0; |
| 357 | uint8_t eventData1 = 0; |
| 358 | std::optional<uint8_t> eventData2 = 0; |
| 359 | std::optional<uint8_t> eventData3 = 0; |
| 360 | |
| 361 | // todo: This check is supposed to be based on the incoming channel. |
| 362 | // e.g. system channel will provide upto 8 bytes including generator |
| 363 | // ID, but ipmb channel will provide only up to 7 bytes without the |
| 364 | // generator ID. |
| 365 | // Support for this check is coming in future patches, so for now just base |
| 366 | // it on if the first byte is the EvMRev (0x04). |
| 367 | if (p.size() && p.data()[0] == 0x04) |
| 368 | { |
| 369 | p.unpack(evmRev, sensorType, sensorNum, eventType, eventData1, |
| 370 | eventData2, eventData3); |
| 371 | // todo: the generator ID for this channel is supposed to come from the |
| 372 | // IPMB requesters slave address. Support for this is coming in future |
| 373 | // patches, so for now just assume it is coming from the ME (0x2C). |
| 374 | generatorID = 0x2C; |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | p.unpack(generatorID, evmRev, sensorType, sensorNum, eventType, |
| 379 | eventData1, eventData2, eventData3); |
| 380 | } |
| 381 | if (!p.fullyUnpacked()) |
| 382 | { |
| 383 | return ipmi::responseReqDataLenInvalid(); |
| 384 | } |
| 385 | |
Jason M. Bills | 6dd8f04 | 2019-04-11 10:39:02 -0700 | [diff] [blame] | 386 | // Send this request to the Redfish hooks to log it as a Redfish message |
| 387 | // instead. There is no need to add it to the SEL, so just return success. |
| 388 | intel_oem::ipmi::sel::checkRedfishHooks( |
| 389 | generatorID, evmRev, sensorType, sensorNum, eventType, eventData1, |
| 390 | eventData2.value_or(0xFF), eventData3.value_or(0xFF)); |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 391 | |
James Feist | 7aaf3fe | 2019-06-25 11:52:11 -0700 | [diff] [blame] | 392 | if (generatorID == meId && sensorNum == meSensorNum && eventData2 && |
| 393 | eventData3) |
| 394 | { |
| 395 | setMeStatus(*eventData2, *eventData3, (eventType & disabled)); |
| 396 | } |
| 397 | |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 398 | return ipmi::responseSuccess(); |
| 399 | } |
| 400 | |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 401 | ipmi::RspType<uint8_t, uint8_t, uint8_t, std::optional<uint8_t>> |
| 402 | ipmiSenGetSensorReading(uint8_t sensnum) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 403 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 404 | std::string connection; |
| 405 | std::string path; |
| 406 | |
| 407 | auto status = getSensorConnection(sensnum, connection, path); |
| 408 | if (status) |
| 409 | { |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 410 | return ipmi::response(status); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | SensorMap sensorMap; |
| 414 | if (!getSensorMap(connection, path, sensorMap)) |
| 415 | { |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 416 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 417 | } |
| 418 | auto sensorObject = sensorMap.find("xyz.openbmc_project.Sensor.Value"); |
| 419 | |
| 420 | if (sensorObject == sensorMap.end() || |
| 421 | sensorObject->second.find("Value") == sensorObject->second.end()) |
| 422 | { |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 423 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 424 | } |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 425 | auto &valueVariant = sensorObject->second["Value"]; |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 426 | double reading = std::visit(VariantToDoubleVisitor(), valueVariant); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 427 | |
Yong Li | 1f2eb5e | 2019-05-23 14:07:17 +0800 | [diff] [blame] | 428 | double max = 0; |
| 429 | double min = 0; |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 430 | getSensorMaxMin(sensorMap, max, min); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 431 | |
| 432 | int16_t mValue = 0; |
| 433 | int16_t bValue = 0; |
| 434 | int8_t rExp = 0; |
| 435 | int8_t bExp = 0; |
| 436 | bool bSigned = false; |
| 437 | |
| 438 | if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned)) |
| 439 | { |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 440 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 441 | } |
| 442 | |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 443 | uint8_t value = |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 444 | scaleIPMIValueFromDouble(reading, mValue, rExp, bValue, bExp, bSigned); |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 445 | uint8_t operation = |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 446 | static_cast<uint8_t>(IPMISensorReadingByte2::sensorScanningEnable); |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 447 | operation |= |
James Feist | 81a95c1 | 2019-03-01 15:08:28 -0800 | [diff] [blame] | 448 | static_cast<uint8_t>(IPMISensorReadingByte2::eventMessagesEnable); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 449 | |
James Feist | 0cd014a | 2019-04-08 15:04:33 -0700 | [diff] [blame] | 450 | uint8_t thresholds = 0; |
| 451 | |
| 452 | auto warningObject = |
| 453 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 454 | if (warningObject != sensorMap.end()) |
| 455 | { |
| 456 | auto alarmHigh = warningObject->second.find("WarningAlarmHigh"); |
| 457 | auto alarmLow = warningObject->second.find("WarningAlarmLow"); |
| 458 | if (alarmHigh != warningObject->second.end()) |
| 459 | { |
| 460 | if (std::get<bool>(alarmHigh->second)) |
| 461 | { |
| 462 | thresholds |= static_cast<uint8_t>( |
| 463 | IPMISensorReadingByte3::upperNonCritical); |
| 464 | } |
| 465 | } |
| 466 | if (alarmLow != warningObject->second.end()) |
| 467 | { |
| 468 | if (std::get<bool>(alarmLow->second)) |
| 469 | { |
| 470 | thresholds |= static_cast<uint8_t>( |
| 471 | IPMISensorReadingByte3::lowerNonCritical); |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | auto criticalObject = |
| 477 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 478 | if (criticalObject != sensorMap.end()) |
| 479 | { |
| 480 | auto alarmHigh = criticalObject->second.find("CriticalAlarmHigh"); |
| 481 | auto alarmLow = criticalObject->second.find("CriticalAlarmLow"); |
| 482 | if (alarmHigh != criticalObject->second.end()) |
| 483 | { |
| 484 | if (std::get<bool>(alarmHigh->second)) |
| 485 | { |
| 486 | thresholds |= |
| 487 | static_cast<uint8_t>(IPMISensorReadingByte3::upperCritical); |
| 488 | } |
| 489 | } |
| 490 | if (alarmLow != criticalObject->second.end()) |
| 491 | { |
| 492 | if (std::get<bool>(alarmLow->second)) |
| 493 | { |
| 494 | thresholds |= |
| 495 | static_cast<uint8_t>(IPMISensorReadingByte3::lowerCritical); |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // no discrete as of today so optional byte is never returned |
| 501 | return ipmi::responseSuccess(value, operation, thresholds, std::nullopt); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 502 | } |
| 503 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 504 | /** @brief implements the Set Sensor threshold command |
| 505 | * @param sensorNumber - sensor number |
| 506 | * @param lowerNonCriticalThreshMask |
| 507 | * @param lowerCriticalThreshMask |
| 508 | * @param lowerNonRecovThreshMask |
| 509 | * @param upperNonCriticalThreshMask |
| 510 | * @param upperCriticalThreshMask |
| 511 | * @param upperNonRecovThreshMask |
| 512 | * @param reserved |
| 513 | * @param lowerNonCritical - lower non-critical threshold |
| 514 | * @param lowerCritical - Lower critical threshold |
| 515 | * @param lowerNonRecoverable - Lower non recovarable threshold |
| 516 | * @param upperNonCritical - Upper non-critical threshold |
| 517 | * @param upperCritical - Upper critical |
| 518 | * @param upperNonRecoverable - Upper Non-recoverable |
| 519 | * |
| 520 | * @returns IPMI completion code |
| 521 | */ |
| 522 | ipmi::RspType<> ipmiSenSetSensorThresholds( |
| 523 | uint8_t sensorNum, bool lowerNonCriticalThreshMask, |
| 524 | bool lowerCriticalThreshMask, bool lowerNonRecovThreshMask, |
| 525 | bool upperNonCriticalThreshMask, bool upperCriticalThreshMask, |
| 526 | bool upperNonRecovThreshMask, uint2_t reserved, uint8_t lowerNonCritical, |
| 527 | uint8_t lowerCritical, uint8_t lowerNonRecoverable, |
| 528 | uint8_t upperNonCritical, uint8_t upperCritical, |
| 529 | uint8_t upperNonRecoverable) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 530 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 531 | constexpr uint8_t thresholdMask = 0xFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 532 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 533 | if (reserved) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 534 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 535 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | // lower nc and upper nc not suppported on any sensor |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 539 | if (lowerNonRecovThreshMask || upperNonRecovThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 540 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 541 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 542 | } |
| 543 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 544 | // if none of the threshold mask are set, nothing to do |
| 545 | if (!(lowerNonCriticalThreshMask | lowerCriticalThreshMask | |
| 546 | lowerNonRecovThreshMask | upperNonCriticalThreshMask | |
| 547 | upperCriticalThreshMask | upperNonRecovThreshMask)) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 548 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 549 | return ipmi::responseSuccess(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | std::string connection; |
| 553 | std::string path; |
| 554 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 555 | ipmi::Cc status = getSensorConnection(sensorNum, connection, path); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 556 | if (status) |
| 557 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 558 | return ipmi::response(status); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 559 | } |
| 560 | SensorMap sensorMap; |
| 561 | if (!getSensorMap(connection, path, sensorMap)) |
| 562 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 563 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 566 | double max = 0; |
| 567 | double min = 0; |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 568 | getSensorMaxMin(sensorMap, max, min); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 569 | |
| 570 | int16_t mValue = 0; |
| 571 | int16_t bValue = 0; |
| 572 | int8_t rExp = 0; |
| 573 | int8_t bExp = 0; |
| 574 | bool bSigned = false; |
| 575 | |
| 576 | if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned)) |
| 577 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 578 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 581 | // store a vector of property name, value to set, and interface |
| 582 | std::vector<std::tuple<std::string, uint8_t, std::string>> thresholdsToSet; |
| 583 | |
| 584 | // define the indexes of the tuple |
| 585 | constexpr uint8_t propertyName = 0; |
| 586 | constexpr uint8_t thresholdValue = 1; |
| 587 | constexpr uint8_t interface = 2; |
| 588 | // verifiy all needed fields are present |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 589 | if (lowerCriticalThreshMask || upperCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 590 | { |
| 591 | auto findThreshold = |
| 592 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 593 | if (findThreshold == sensorMap.end()) |
| 594 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 595 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 596 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 597 | if (lowerCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 598 | { |
| 599 | auto findLower = findThreshold->second.find("CriticalLow"); |
| 600 | if (findLower == findThreshold->second.end()) |
| 601 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 602 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 603 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 604 | thresholdsToSet.emplace_back("CriticalLow", lowerCritical, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 605 | findThreshold->first); |
| 606 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 607 | if (upperCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 608 | { |
| 609 | auto findUpper = findThreshold->second.find("CriticalHigh"); |
| 610 | if (findUpper == findThreshold->second.end()) |
| 611 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 612 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 613 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 614 | thresholdsToSet.emplace_back("CriticalHigh", upperCritical, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 615 | findThreshold->first); |
| 616 | } |
| 617 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 618 | if (lowerNonCriticalThreshMask || upperNonCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 619 | { |
| 620 | auto findThreshold = |
| 621 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 622 | if (findThreshold == sensorMap.end()) |
| 623 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 624 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 625 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 626 | if (lowerNonCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 627 | { |
| 628 | auto findLower = findThreshold->second.find("WarningLow"); |
| 629 | if (findLower == findThreshold->second.end()) |
| 630 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 631 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 632 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 633 | thresholdsToSet.emplace_back("WarningLow", lowerNonCritical, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 634 | findThreshold->first); |
| 635 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 636 | if (upperNonCriticalThreshMask) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 637 | { |
| 638 | auto findUpper = findThreshold->second.find("WarningHigh"); |
| 639 | if (findUpper == findThreshold->second.end()) |
| 640 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 641 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 642 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 643 | thresholdsToSet.emplace_back("WarningHigh", upperNonCritical, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 644 | findThreshold->first); |
| 645 | } |
| 646 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 647 | for (const auto &property : thresholdsToSet) |
| 648 | { |
| 649 | // from section 36.3 in the IPMI Spec, assume all linear |
| 650 | double valueToSet = ((mValue * std::get<thresholdValue>(property)) + |
| 651 | (bValue * std::pow(10, bExp))) * |
| 652 | std::pow(10, rExp); |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 653 | setDbusProperty( |
| 654 | *getSdBus(), connection, path, std::get<interface>(property), |
| 655 | std::get<propertyName>(property), ipmi::Value(valueToSet)); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 656 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 657 | return ipmi::responseSuccess(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 658 | } |
| 659 | |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 660 | IPMIThresholds getIPMIThresholds(const SensorMap &sensorMap) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 661 | { |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 662 | IPMIThresholds resp; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 663 | auto warningInterface = |
| 664 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 665 | auto criticalInterface = |
| 666 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 667 | |
| 668 | if ((warningInterface != sensorMap.end()) || |
| 669 | (criticalInterface != sensorMap.end())) |
| 670 | { |
| 671 | auto sensorPair = sensorMap.find("xyz.openbmc_project.Sensor.Value"); |
| 672 | |
| 673 | if (sensorPair == sensorMap.end()) |
| 674 | { |
| 675 | // should not have been able to find a sensor not implementing |
| 676 | // the sensor object |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 677 | throw std::runtime_error("Invalid sensor map"); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Chen,Yugang | 606dd9f | 2019-07-01 10:37:30 +0800 | [diff] [blame] | 680 | double max = 0; |
| 681 | double min = 0; |
James Feist | aecaef7 | 2019-04-26 10:30:32 -0700 | [diff] [blame] | 682 | getSensorMaxMin(sensorMap, max, min); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 683 | |
| 684 | int16_t mValue = 0; |
| 685 | int16_t bValue = 0; |
| 686 | int8_t rExp = 0; |
| 687 | int8_t bExp = 0; |
| 688 | bool bSigned = false; |
| 689 | |
| 690 | if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned)) |
| 691 | { |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 692 | throw std::runtime_error("Invalid sensor atrributes"); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 693 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 694 | if (warningInterface != sensorMap.end()) |
| 695 | { |
| 696 | auto &warningMap = warningInterface->second; |
| 697 | |
| 698 | auto warningHigh = warningMap.find("WarningHigh"); |
| 699 | auto warningLow = warningMap.find("WarningLow"); |
| 700 | |
| 701 | if (warningHigh != warningMap.end()) |
| 702 | { |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 703 | |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 704 | double value = |
| 705 | std::visit(VariantToDoubleVisitor(), warningHigh->second); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 706 | resp.warningHigh = scaleIPMIValueFromDouble( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 707 | value, mValue, rExp, bValue, bExp, bSigned); |
| 708 | } |
| 709 | if (warningLow != warningMap.end()) |
| 710 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 711 | double value = |
| 712 | std::visit(VariantToDoubleVisitor(), warningLow->second); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 713 | resp.warningLow = scaleIPMIValueFromDouble( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 714 | value, mValue, rExp, bValue, bExp, bSigned); |
| 715 | } |
| 716 | } |
| 717 | if (criticalInterface != sensorMap.end()) |
| 718 | { |
| 719 | auto &criticalMap = criticalInterface->second; |
| 720 | |
| 721 | auto criticalHigh = criticalMap.find("CriticalHigh"); |
| 722 | auto criticalLow = criticalMap.find("CriticalLow"); |
| 723 | |
| 724 | if (criticalHigh != criticalMap.end()) |
| 725 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 726 | double value = |
| 727 | std::visit(VariantToDoubleVisitor(), criticalHigh->second); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 728 | resp.criticalHigh = scaleIPMIValueFromDouble( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 729 | value, mValue, rExp, bValue, bExp, bSigned); |
| 730 | } |
| 731 | if (criticalLow != criticalMap.end()) |
| 732 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 733 | double value = |
| 734 | std::visit(VariantToDoubleVisitor(), criticalLow->second); |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 735 | resp.criticalLow = scaleIPMIValueFromDouble( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 736 | value, mValue, rExp, bValue, bExp, bSigned); |
| 737 | } |
| 738 | } |
| 739 | } |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 740 | return resp; |
| 741 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 742 | |
James Feist | 902c4c5 | 2019-04-16 14:51:31 -0700 | [diff] [blame] | 743 | ipmi::RspType<uint8_t, // readable |
| 744 | uint8_t, // lowerNCrit |
| 745 | uint8_t, // lowerCrit |
| 746 | uint8_t, // lowerNrecoverable |
| 747 | uint8_t, // upperNC |
| 748 | uint8_t, // upperCrit |
| 749 | uint8_t> // upperNRecoverable |
| 750 | ipmiSenGetSensorThresholds(uint8_t sensorNumber) |
| 751 | { |
| 752 | std::string connection; |
| 753 | std::string path; |
| 754 | |
| 755 | auto status = getSensorConnection(sensorNumber, connection, path); |
| 756 | if (status) |
| 757 | { |
| 758 | return ipmi::response(status); |
| 759 | } |
| 760 | |
| 761 | SensorMap sensorMap; |
| 762 | if (!getSensorMap(connection, path, sensorMap)) |
| 763 | { |
| 764 | return ipmi::responseResponseError(); |
| 765 | } |
| 766 | |
| 767 | IPMIThresholds thresholdData; |
| 768 | try |
| 769 | { |
| 770 | thresholdData = getIPMIThresholds(sensorMap); |
| 771 | } |
| 772 | catch (std::exception &) |
| 773 | { |
| 774 | return ipmi::responseResponseError(); |
| 775 | } |
| 776 | |
| 777 | uint8_t readable = 0; |
| 778 | uint8_t lowerNC = 0; |
| 779 | uint8_t lowerCritical = 0; |
| 780 | uint8_t lowerNonRecoverable = 0; |
| 781 | uint8_t upperNC = 0; |
| 782 | uint8_t upperCritical = 0; |
| 783 | uint8_t upperNonRecoverable = 0; |
| 784 | |
| 785 | if (thresholdData.warningHigh) |
| 786 | { |
| 787 | readable |= |
| 788 | 1 << static_cast<uint8_t>(IPMIThresholdRespBits::upperNonCritical); |
| 789 | upperNC = *thresholdData.warningHigh; |
| 790 | } |
| 791 | if (thresholdData.warningLow) |
| 792 | { |
| 793 | readable |= |
| 794 | 1 << static_cast<uint8_t>(IPMIThresholdRespBits::lowerNonCritical); |
| 795 | lowerNC = *thresholdData.warningLow; |
| 796 | } |
| 797 | |
| 798 | if (thresholdData.criticalHigh) |
| 799 | { |
| 800 | readable |= |
| 801 | 1 << static_cast<uint8_t>(IPMIThresholdRespBits::upperCritical); |
| 802 | upperCritical = *thresholdData.criticalHigh; |
| 803 | } |
| 804 | if (thresholdData.criticalLow) |
| 805 | { |
| 806 | readable |= |
| 807 | 1 << static_cast<uint8_t>(IPMIThresholdRespBits::lowerCritical); |
| 808 | lowerCritical = *thresholdData.criticalLow; |
| 809 | } |
| 810 | |
| 811 | return ipmi::responseSuccess(readable, lowerNC, lowerCritical, |
| 812 | lowerNonRecoverable, upperNC, upperCritical, |
| 813 | upperNonRecoverable); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 814 | } |
| 815 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 816 | /** @brief implements the get Sensor event enable command |
| 817 | * @param sensorNumber - sensor number |
| 818 | * |
| 819 | * @returns IPMI completion code plus response data |
| 820 | * - enabled - Sensor Event messages |
| 821 | * - assertionEnabledLsb - Assertion event messages |
| 822 | * - assertionEnabledMsb - Assertion event messages |
| 823 | * - deassertionEnabledLsb - Deassertion event messages |
| 824 | * - deassertionEnabledMsb - Deassertion event messages |
| 825 | */ |
| 826 | |
| 827 | ipmi::RspType<uint8_t, // enabled |
| 828 | uint8_t, // assertionEnabledLsb |
| 829 | uint8_t, // assertionEnabledMsb |
| 830 | uint8_t, // deassertionEnabledLsb |
| 831 | uint8_t> // deassertionEnabledMsb |
| 832 | ipmiSenGetSensorEventEnable(uint8_t sensorNum) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 833 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 834 | std::string connection; |
| 835 | std::string path; |
| 836 | |
Patrick Venture | a41714c | 2019-09-25 16:59:41 -0700 | [diff] [blame] | 837 | uint8_t enabled = 0; |
| 838 | uint8_t assertionEnabledLsb = 0; |
| 839 | uint8_t assertionEnabledMsb = 0; |
| 840 | uint8_t deassertionEnabledLsb = 0; |
| 841 | uint8_t deassertionEnabledMsb = 0; |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 842 | |
| 843 | auto status = getSensorConnection(sensorNum, connection, path); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 844 | if (status) |
| 845 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 846 | return ipmi::response(status); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | SensorMap sensorMap; |
| 850 | if (!getSensorMap(connection, path, sensorMap)) |
| 851 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 852 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | auto warningInterface = |
| 856 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 857 | auto criticalInterface = |
| 858 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 859 | if ((warningInterface != sensorMap.end()) || |
| 860 | (criticalInterface != sensorMap.end())) |
| 861 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 862 | enabled = static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 863 | IPMISensorEventEnableByte2::sensorScanningEnable); |
| 864 | if (warningInterface != sensorMap.end()) |
| 865 | { |
| 866 | auto &warningMap = warningInterface->second; |
| 867 | |
| 868 | auto warningHigh = warningMap.find("WarningHigh"); |
| 869 | auto warningLow = warningMap.find("WarningLow"); |
| 870 | if (warningHigh != warningMap.end()) |
| 871 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 872 | assertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 873 | IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh); |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 874 | deassertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 875 | IPMISensorEventEnableThresholds::upperNonCriticalGoingLow); |
| 876 | } |
| 877 | if (warningLow != warningMap.end()) |
| 878 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 879 | assertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 880 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow); |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 881 | deassertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 882 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingHigh); |
| 883 | } |
| 884 | } |
| 885 | if (criticalInterface != sensorMap.end()) |
| 886 | { |
| 887 | auto &criticalMap = criticalInterface->second; |
| 888 | |
| 889 | auto criticalHigh = criticalMap.find("CriticalHigh"); |
| 890 | auto criticalLow = criticalMap.find("CriticalLow"); |
| 891 | |
| 892 | if (criticalHigh != criticalMap.end()) |
| 893 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 894 | assertionEnabledMsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 895 | IPMISensorEventEnableThresholds::upperCriticalGoingHigh); |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 896 | deassertionEnabledMsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 897 | IPMISensorEventEnableThresholds::upperCriticalGoingLow); |
| 898 | } |
| 899 | if (criticalLow != criticalMap.end()) |
| 900 | { |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 901 | assertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 902 | IPMISensorEventEnableThresholds::lowerCriticalGoingLow); |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 903 | deassertionEnabledLsb |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 904 | IPMISensorEventEnableThresholds::lowerCriticalGoingHigh); |
| 905 | } |
| 906 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 907 | } |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 908 | |
| 909 | return ipmi::responseSuccess(enabled, assertionEnabledLsb, |
| 910 | assertionEnabledMsb, deassertionEnabledLsb, |
| 911 | deassertionEnabledMsb); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | ipmi_ret_t ipmiSenGetSensorEventStatus(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 915 | ipmi_request_t request, |
| 916 | ipmi_response_t response, |
| 917 | ipmi_data_len_t dataLen, |
| 918 | ipmi_context_t context) |
| 919 | { |
| 920 | if (*dataLen != 1) |
| 921 | { |
| 922 | *dataLen = 0; |
| 923 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 924 | } |
| 925 | *dataLen = 0; // default to 0 in case of an error |
| 926 | |
| 927 | uint8_t sensnum = *(static_cast<uint8_t *>(request)); |
| 928 | |
| 929 | std::string connection; |
| 930 | std::string path; |
| 931 | |
| 932 | auto status = getSensorConnection(sensnum, connection, path); |
| 933 | if (status) |
| 934 | { |
| 935 | return status; |
| 936 | } |
| 937 | |
| 938 | SensorMap sensorMap; |
| 939 | if (!getSensorMap(connection, path, sensorMap)) |
| 940 | { |
| 941 | return IPMI_CC_RESPONSE_ERROR; |
| 942 | } |
| 943 | |
| 944 | auto warningInterface = |
| 945 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 946 | auto criticalInterface = |
| 947 | sensorMap.find("xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 948 | |
| 949 | // zero out response buff |
| 950 | auto responseClear = static_cast<uint8_t *>(response); |
| 951 | std::fill(responseClear, responseClear + sizeof(SensorEventStatusResp), 0); |
| 952 | auto resp = static_cast<SensorEventStatusResp *>(response); |
| 953 | resp->enabled = |
| 954 | static_cast<uint8_t>(IPMISensorEventEnableByte2::sensorScanningEnable); |
| 955 | |
James Feist | 392786a | 2019-03-19 13:36:10 -0700 | [diff] [blame] | 956 | std::optional<bool> criticalDeassertHigh = |
| 957 | thresholdDeassertMap[path]["CriticalAlarmHigh"]; |
| 958 | std::optional<bool> criticalDeassertLow = |
| 959 | thresholdDeassertMap[path]["CriticalAlarmLow"]; |
| 960 | std::optional<bool> warningDeassertHigh = |
| 961 | thresholdDeassertMap[path]["WarningAlarmHigh"]; |
| 962 | std::optional<bool> warningDeassertLow = |
| 963 | thresholdDeassertMap[path]["WarningAlarmLow"]; |
| 964 | |
| 965 | if (criticalDeassertHigh && !*criticalDeassertHigh) |
| 966 | { |
| 967 | resp->deassertionsMSB |= static_cast<uint8_t>( |
| 968 | IPMISensorEventEnableThresholds::upperCriticalGoingHigh); |
| 969 | } |
| 970 | if (criticalDeassertLow && !*criticalDeassertLow) |
| 971 | { |
| 972 | resp->deassertionsMSB |= static_cast<uint8_t>( |
| 973 | IPMISensorEventEnableThresholds::upperCriticalGoingLow); |
| 974 | } |
| 975 | if (warningDeassertHigh && !*warningDeassertHigh) |
| 976 | { |
| 977 | resp->deassertionsLSB |= static_cast<uint8_t>( |
| 978 | IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh); |
| 979 | } |
| 980 | if (warningDeassertLow && !*warningDeassertLow) |
| 981 | { |
| 982 | resp->deassertionsLSB |= static_cast<uint8_t>( |
| 983 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingHigh); |
| 984 | } |
| 985 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 986 | if ((warningInterface != sensorMap.end()) || |
| 987 | (criticalInterface != sensorMap.end())) |
| 988 | { |
| 989 | resp->enabled = static_cast<uint8_t>( |
| 990 | IPMISensorEventEnableByte2::eventMessagesEnable); |
| 991 | if (warningInterface != sensorMap.end()) |
| 992 | { |
| 993 | auto &warningMap = warningInterface->second; |
| 994 | |
| 995 | auto warningHigh = warningMap.find("WarningAlarmHigh"); |
| 996 | auto warningLow = warningMap.find("WarningAlarmLow"); |
| 997 | auto warningHighAlarm = false; |
| 998 | auto warningLowAlarm = false; |
| 999 | |
| 1000 | if (warningHigh != warningMap.end()) |
| 1001 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1002 | warningHighAlarm = std::get<bool>(warningHigh->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1003 | } |
| 1004 | if (warningLow != warningMap.end()) |
| 1005 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1006 | warningLowAlarm = std::get<bool>(warningLow->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1007 | } |
| 1008 | if (warningHighAlarm) |
| 1009 | { |
| 1010 | resp->assertionsLSB |= static_cast<uint8_t>( |
| 1011 | IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh); |
| 1012 | } |
| 1013 | if (warningLowAlarm) |
| 1014 | { |
| 1015 | resp->assertionsLSB |= 1; // lower nc going low |
| 1016 | } |
| 1017 | } |
| 1018 | if (criticalInterface != sensorMap.end()) |
| 1019 | { |
| 1020 | auto &criticalMap = criticalInterface->second; |
| 1021 | |
| 1022 | auto criticalHigh = criticalMap.find("CriticalAlarmHigh"); |
| 1023 | auto criticalLow = criticalMap.find("CriticalAlarmLow"); |
| 1024 | auto criticalHighAlarm = false; |
| 1025 | auto criticalLowAlarm = false; |
| 1026 | |
| 1027 | if (criticalHigh != criticalMap.end()) |
| 1028 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1029 | criticalHighAlarm = std::get<bool>(criticalHigh->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1030 | } |
| 1031 | if (criticalLow != criticalMap.end()) |
| 1032 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1033 | criticalLowAlarm = std::get<bool>(criticalLow->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1034 | } |
| 1035 | if (criticalHighAlarm) |
| 1036 | { |
| 1037 | resp->assertionsMSB |= static_cast<uint8_t>( |
| 1038 | IPMISensorEventEnableThresholds::upperCriticalGoingHigh); |
| 1039 | } |
| 1040 | if (criticalLowAlarm) |
| 1041 | { |
| 1042 | resp->assertionsLSB |= static_cast<uint8_t>( |
| 1043 | IPMISensorEventEnableThresholds::lowerCriticalGoingLow); |
| 1044 | } |
| 1045 | } |
| 1046 | *dataLen = sizeof(SensorEventStatusResp); |
| 1047 | } |
| 1048 | |
| 1049 | // no thresholds enabled, don't need assertionMSB |
| 1050 | else |
| 1051 | { |
| 1052 | *dataLen = sizeof(SensorEventStatusResp) - 1; |
| 1053 | } |
| 1054 | |
| 1055 | return IPMI_CC_OK; |
| 1056 | } |
| 1057 | |
| 1058 | /* end sensor commands */ |
| 1059 | |
| 1060 | /* storage commands */ |
| 1061 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1062 | ipmi::RspType<uint8_t, // sdr version |
| 1063 | uint16_t, // record count |
| 1064 | uint16_t, // free space |
| 1065 | uint32_t, // most recent addition |
| 1066 | uint32_t, // most recent erase |
| 1067 | uint8_t // operationSupport |
| 1068 | > |
| 1069 | ipmiStorageGetSDRRepositoryInfo(void) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1070 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1071 | constexpr const uint16_t unspecifiedFreeSpace = 0xFFFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1072 | if (sensorTree.empty() && !getSensorSubtree(sensorTree)) |
| 1073 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1074 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1077 | size_t fruCount = 0; |
| 1078 | ipmi::Cc ret = ipmi::storage::getFruSdrCount(fruCount); |
| 1079 | if (ret != ipmi::ccSuccess) |
| 1080 | { |
| 1081 | return ipmi::response(ret); |
| 1082 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1083 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1084 | uint16_t recordCount = |
| 1085 | sensorTree.size() + fruCount + ipmi::storage::type12Count; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1086 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1087 | uint8_t operationSupport = static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1088 | SdrRepositoryInfoOps::overflow); // write not supported |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1089 | |
| 1090 | operationSupport |= |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1091 | static_cast<uint8_t>(SdrRepositoryInfoOps::allocCommandSupported); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1092 | operationSupport |= static_cast<uint8_t>( |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1093 | SdrRepositoryInfoOps::reserveSDRRepositoryCommandSupported); |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1094 | return ipmi::responseSuccess(ipmiSdrVersion, recordCount, |
| 1095 | unspecifiedFreeSpace, sdrLastAdd, |
| 1096 | sdrLastRemove, operationSupport); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1099 | /** @brief implements the get SDR allocation info command |
| 1100 | * |
| 1101 | * @returns IPMI completion code plus response data |
| 1102 | * - allocUnits - Number of possible allocation units |
| 1103 | * - allocUnitSize - Allocation unit size in bytes. |
| 1104 | * - allocUnitFree - Number of free allocation units |
| 1105 | * - allocUnitLargestFree - Largest free block in allocation units |
| 1106 | * - maxRecordSize - Maximum record size in allocation units. |
| 1107 | */ |
| 1108 | ipmi::RspType<uint16_t, // allocUnits |
| 1109 | uint16_t, // allocUnitSize |
| 1110 | uint16_t, // allocUnitFree |
| 1111 | uint16_t, // allocUnitLargestFree |
| 1112 | uint8_t // maxRecordSize |
| 1113 | > |
| 1114 | ipmiStorageGetSDRAllocationInfo() |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1115 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1116 | // 0000h unspecified number of alloc units |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1117 | constexpr uint16_t allocUnits = 0; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1118 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1119 | constexpr uint16_t allocUnitFree = 0; |
| 1120 | constexpr uint16_t allocUnitLargestFree = 0; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1121 | // only allow one block at a time |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1122 | constexpr uint8_t maxRecordSize = 1; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1123 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1124 | return ipmi::responseSuccess(allocUnits, maxSDRTotalSize, allocUnitFree, |
| 1125 | allocUnitLargestFree, maxRecordSize); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1128 | /** @brief implements the reserve SDR command |
| 1129 | * @returns IPMI completion code plus response data |
| 1130 | * - sdrReservationID |
| 1131 | */ |
| 1132 | ipmi::RspType<uint16_t> ipmiStorageReserveSDR() |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1133 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1134 | sdrReservationID++; |
James Feist | a80cb90 | 2019-02-14 13:05:25 -0800 | [diff] [blame] | 1135 | if (sdrReservationID == 0) |
| 1136 | { |
| 1137 | sdrReservationID++; |
| 1138 | } |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1139 | |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1140 | return ipmi::responseSuccess(sdrReservationID); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1143 | ipmi::RspType<uint16_t, // next record ID |
| 1144 | std::vector<uint8_t> // payload |
| 1145 | > |
| 1146 | ipmiStorageGetSDR(uint16_t reservationID, uint16_t recordID, uint8_t offset, |
| 1147 | uint8_t bytesToRead) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1148 | { |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1149 | constexpr uint16_t lastRecordIndex = 0xFFFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1150 | |
| 1151 | // reservation required for partial reads with non zero offset into |
| 1152 | // record |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1153 | if ((sdrReservationID == 0 || reservationID != sdrReservationID) && offset) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1154 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1155 | return ipmi::responseInvalidReservationId(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | if (sensorTree.empty() && !getSensorSubtree(sensorTree)) |
| 1159 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1160 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | size_t fruCount = 0; |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1164 | ipmi::Cc ret = ipmi::storage::getFruSdrCount(fruCount); |
| 1165 | if (ret != ipmi::ccSuccess) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1166 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1167 | return ipmi::response(ret); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1170 | size_t lastRecord = |
| 1171 | sensorTree.size() + fruCount + ipmi::storage::type12Count - 1; |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1172 | if (recordID == lastRecordIndex) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1173 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1174 | recordID = lastRecord; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1175 | } |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1176 | if (recordID > lastRecord) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1177 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1178 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1181 | uint16_t nextRecordId = lastRecord > recordID ? recordID + 1 : 0XFFFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1182 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1183 | if (recordID >= sensorTree.size()) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1184 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1185 | std::vector<uint8_t> recordData; |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1186 | size_t fruIndex = recordID - sensorTree.size(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1187 | if (fruIndex >= fruCount) |
| 1188 | { |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1189 | // handle type 12 hardcoded records |
| 1190 | size_t type12Index = fruIndex - fruCount; |
| 1191 | if (type12Index >= ipmi::storage::type12Count || |
| 1192 | offset > sizeof(Type12Record)) |
| 1193 | { |
| 1194 | return ipmi::responseInvalidFieldRequest(); |
| 1195 | } |
| 1196 | std::vector<uint8_t> record = |
| 1197 | ipmi::storage::getType12SDRs(type12Index, recordID); |
| 1198 | if (record.size() < (offset + bytesToRead)) |
| 1199 | { |
| 1200 | bytesToRead = record.size() - offset; |
| 1201 | } |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1202 | |
James Feist | 74c50c6 | 2019-08-14 14:18:41 -0700 | [diff] [blame] | 1203 | recordData.insert(recordData.end(), record.begin() + offset, |
| 1204 | record.begin() + offset + bytesToRead); |
| 1205 | } |
| 1206 | else |
| 1207 | { |
| 1208 | // handle fru records |
| 1209 | get_sdr::SensorDataFruRecord data; |
| 1210 | if (offset > sizeof(data)) |
| 1211 | { |
| 1212 | return ipmi::responseInvalidFieldRequest(); |
| 1213 | } |
| 1214 | ret = ipmi::storage::getFruSdrs(fruIndex, data); |
| 1215 | if (ret != IPMI_CC_OK) |
| 1216 | { |
| 1217 | return ipmi::response(ret); |
| 1218 | } |
| 1219 | data.header.record_id_msb = recordID << 8; |
| 1220 | data.header.record_id_lsb = recordID & 0xFF; |
| 1221 | if (sizeof(data) < (offset + bytesToRead)) |
| 1222 | { |
| 1223 | bytesToRead = sizeof(data) - offset; |
| 1224 | } |
| 1225 | |
| 1226 | uint8_t *respStart = reinterpret_cast<uint8_t *>(&data) + offset; |
| 1227 | recordData.insert(recordData.end(), respStart, |
| 1228 | respStart + bytesToRead); |
| 1229 | } |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1230 | |
| 1231 | return ipmi::responseSuccess(nextRecordId, recordData); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | std::string connection; |
| 1235 | std::string path; |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1236 | uint16_t sensorIndex = recordID; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1237 | for (const auto &sensor : sensorTree) |
| 1238 | { |
| 1239 | if (sensorIndex-- == 0) |
| 1240 | { |
| 1241 | if (!sensor.second.size()) |
| 1242 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1243 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1244 | } |
| 1245 | connection = sensor.second.begin()->first; |
| 1246 | path = sensor.first; |
| 1247 | break; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | SensorMap sensorMap; |
| 1252 | if (!getSensorMap(connection, path, sensorMap)) |
| 1253 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1254 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1255 | } |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1256 | uint8_t sensornumber = (recordID & 0xFF); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1257 | get_sdr::SensorDataFullRecord record = {0}; |
| 1258 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1259 | record.header.record_id_msb = recordID << 8; |
| 1260 | record.header.record_id_lsb = recordID & 0xFF; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1261 | record.header.sdr_version = ipmiSdrVersion; |
| 1262 | record.header.record_type = get_sdr::SENSOR_DATA_FULL_RECORD; |
| 1263 | record.header.record_length = sizeof(get_sdr::SensorDataFullRecord) - |
| 1264 | sizeof(get_sdr::SensorDataRecordHeader); |
| 1265 | record.key.owner_id = 0x20; |
| 1266 | record.key.owner_lun = 0x0; |
| 1267 | record.key.sensor_number = sensornumber; |
| 1268 | |
| 1269 | record.body.entity_id = 0x0; |
| 1270 | record.body.entity_instance = 0x01; |
James Feist | 7086a88 | 2019-03-13 10:46:00 -0700 | [diff] [blame] | 1271 | record.body.sensor_capabilities = 0x68; // auto rearm - todo hysteresis |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1272 | record.body.sensor_type = getSensorTypeFromPath(path); |
| 1273 | std::string type = getSensorTypeStringFromPath(path); |
| 1274 | auto typeCstr = type.c_str(); |
| 1275 | auto findUnits = sensorUnits.find(typeCstr); |
| 1276 | if (findUnits != sensorUnits.end()) |
| 1277 | { |
| 1278 | record.body.sensor_units_2_base = |
| 1279 | static_cast<uint8_t>(findUnits->second); |
| 1280 | } // else default 0x0 unspecified |
| 1281 | |
| 1282 | record.body.event_reading_type = getSensorEventTypeFromPath(path); |
| 1283 | |
| 1284 | auto sensorObject = sensorMap.find("xyz.openbmc_project.Sensor.Value"); |
| 1285 | if (sensorObject == sensorMap.end()) |
| 1286 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1287 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | auto maxObject = sensorObject->second.find("MaxValue"); |
| 1291 | auto minObject = sensorObject->second.find("MinValue"); |
| 1292 | double max = 128; |
| 1293 | double min = -127; |
| 1294 | if (maxObject != sensorObject->second.end()) |
| 1295 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1296 | max = std::visit(VariantToDoubleVisitor(), maxObject->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | if (minObject != sensorObject->second.end()) |
| 1300 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1301 | min = std::visit(VariantToDoubleVisitor(), minObject->second); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Yong Li | 1f2eb5e | 2019-05-23 14:07:17 +0800 | [diff] [blame] | 1304 | int16_t mValue = 0; |
| 1305 | int8_t rExp = 0; |
| 1306 | int16_t bValue = 0; |
| 1307 | int8_t bExp = 0; |
| 1308 | bool bSigned = false; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1309 | |
| 1310 | if (!getSensorAttributes(max, min, mValue, rExp, bValue, bExp, bSigned)) |
| 1311 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1312 | return ipmi::responseResponseError(); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | // apply M, B, and exponents, M and B are 10 bit values, exponents are 4 |
| 1316 | record.body.m_lsb = mValue & 0xFF; |
| 1317 | |
| 1318 | // move the smallest bit of the MSB into place (bit 9) |
| 1319 | // the MSbs are bits 7:8 in m_msb_and_tolerance |
| 1320 | uint8_t mMsb = (mValue & (1 << 8)) > 0 ? (1 << 6) : 0; |
| 1321 | |
| 1322 | // assign the negative |
| 1323 | if (mValue < 0) |
| 1324 | { |
| 1325 | mMsb |= (1 << 7); |
| 1326 | } |
| 1327 | record.body.m_msb_and_tolerance = mMsb; |
| 1328 | |
| 1329 | record.body.b_lsb = bValue & 0xFF; |
| 1330 | |
| 1331 | // move the smallest bit of the MSB into place |
| 1332 | // the MSbs are bits 7:8 in b_msb_and_accuracy_lsb |
| 1333 | uint8_t bMsb = (bValue & (1 << 8)) > 0 ? (1 << 6) : 0; |
| 1334 | |
| 1335 | // assign the negative |
| 1336 | if (bValue < 0) |
| 1337 | { |
| 1338 | bMsb |= (1 << 7); |
| 1339 | } |
| 1340 | record.body.b_msb_and_accuracy_lsb = bMsb; |
| 1341 | |
| 1342 | record.body.r_b_exponents = bExp & 0x7; |
| 1343 | if (bExp < 0) |
| 1344 | { |
| 1345 | record.body.r_b_exponents |= 1 << 3; |
| 1346 | } |
| 1347 | record.body.r_b_exponents = (rExp & 0x7) << 4; |
| 1348 | if (rExp < 0) |
| 1349 | { |
| 1350 | record.body.r_b_exponents |= 1 << 7; |
| 1351 | } |
| 1352 | |
| 1353 | // todo fill out rest of units |
| 1354 | if (bSigned) |
| 1355 | { |
| 1356 | record.body.sensor_units_1 = 1 << 7; |
| 1357 | } |
| 1358 | |
| 1359 | // populate sensor name from path |
| 1360 | std::string name; |
| 1361 | size_t nameStart = path.rfind("/"); |
| 1362 | if (nameStart != std::string::npos) |
| 1363 | { |
| 1364 | name = path.substr(nameStart + 1, std::string::npos - nameStart); |
| 1365 | } |
| 1366 | |
| 1367 | std::replace(name.begin(), name.end(), '_', ' '); |
| 1368 | if (name.size() > FULL_RECORD_ID_STR_MAX_LENGTH) |
| 1369 | { |
James Feist | 979a232 | 2019-05-15 09:06:54 -0700 | [diff] [blame] | 1370 | // try to not truncate by replacing common words |
| 1371 | constexpr std::array<std::pair<const char *, const char *>, 2> |
| 1372 | replaceWords = {std::make_pair("Output", "Out"), |
| 1373 | std::make_pair("Input", "In")}; |
| 1374 | for (const auto &[find, replace] : replaceWords) |
| 1375 | { |
| 1376 | boost::replace_all(name, find, replace); |
| 1377 | } |
| 1378 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1379 | name.resize(FULL_RECORD_ID_STR_MAX_LENGTH); |
| 1380 | } |
| 1381 | record.body.id_string_info = name.size(); |
| 1382 | std::strncpy(record.body.id_string, name.c_str(), |
| 1383 | sizeof(record.body.id_string)); |
| 1384 | |
James Feist | c4b15bc | 2019-04-16 15:41:39 -0700 | [diff] [blame] | 1385 | IPMIThresholds thresholdData; |
| 1386 | try |
| 1387 | { |
| 1388 | thresholdData = getIPMIThresholds(sensorMap); |
| 1389 | } |
| 1390 | catch (std::exception &) |
| 1391 | { |
| 1392 | return ipmi::responseResponseError(); |
| 1393 | } |
| 1394 | |
| 1395 | if (thresholdData.criticalHigh) |
| 1396 | { |
| 1397 | record.body.upper_critical_threshold = *thresholdData.criticalHigh; |
| 1398 | record.body.supported_deassertions[1] |= static_cast<uint8_t>( |
| 1399 | IPMISensorEventEnableThresholds::upperCriticalGoingHigh); |
| 1400 | record.body.supported_assertions[1] |= static_cast<uint8_t>( |
| 1401 | IPMISensorEventEnableThresholds::upperCriticalGoingHigh); |
| 1402 | record.body.discrete_reading_setting_mask[0] |= |
| 1403 | static_cast<uint8_t>(IPMISensorReadingByte3::upperCritical); |
| 1404 | } |
| 1405 | if (thresholdData.warningHigh) |
| 1406 | { |
| 1407 | record.body.upper_noncritical_threshold = *thresholdData.warningHigh; |
| 1408 | record.body.supported_deassertions[0] |= static_cast<uint8_t>( |
| 1409 | IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh); |
| 1410 | record.body.supported_assertions[0] |= static_cast<uint8_t>( |
| 1411 | IPMISensorEventEnableThresholds::upperNonCriticalGoingHigh); |
| 1412 | record.body.discrete_reading_setting_mask[0] |= |
| 1413 | static_cast<uint8_t>(IPMISensorReadingByte3::upperNonCritical); |
| 1414 | } |
| 1415 | if (thresholdData.criticalLow) |
| 1416 | { |
| 1417 | record.body.lower_critical_threshold = *thresholdData.criticalLow; |
| 1418 | record.body.supported_deassertions[0] |= static_cast<uint8_t>( |
| 1419 | IPMISensorEventEnableThresholds::lowerCriticalGoingLow); |
| 1420 | record.body.supported_assertions[0] |= static_cast<uint8_t>( |
| 1421 | IPMISensorEventEnableThresholds::lowerCriticalGoingLow); |
| 1422 | record.body.discrete_reading_setting_mask[0] |= |
| 1423 | static_cast<uint8_t>(IPMISensorReadingByte3::lowerCritical); |
| 1424 | } |
| 1425 | if (thresholdData.warningLow) |
| 1426 | { |
| 1427 | record.body.lower_noncritical_threshold = *thresholdData.warningLow; |
| 1428 | record.body.supported_deassertions[0] |= static_cast<uint8_t>( |
| 1429 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow); |
| 1430 | record.body.supported_assertions[0] |= static_cast<uint8_t>( |
| 1431 | IPMISensorEventEnableThresholds::lowerNonCriticalGoingLow); |
| 1432 | record.body.discrete_reading_setting_mask[0] |= |
| 1433 | static_cast<uint8_t>(IPMISensorReadingByte3::lowerNonCritical); |
| 1434 | } |
| 1435 | |
| 1436 | // everything that is readable is setable |
| 1437 | record.body.discrete_reading_setting_mask[1] = |
| 1438 | record.body.discrete_reading_setting_mask[0]; |
| 1439 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1440 | if (sizeof(get_sdr::SensorDataFullRecord) < (offset + bytesToRead)) |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1441 | { |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1442 | bytesToRead = sizeof(get_sdr::SensorDataFullRecord) - offset; |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1445 | uint8_t *respStart = reinterpret_cast<uint8_t *>(&record) + offset; |
| 1446 | std::vector<uint8_t> recordData(respStart, respStart + bytesToRead); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1447 | |
James Feist | b49a98a | 2019-04-16 13:48:09 -0700 | [diff] [blame] | 1448 | return ipmi::responseSuccess(nextRecordId, recordData); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1449 | } |
| 1450 | /* end storage commands */ |
| 1451 | |
| 1452 | void registerSensorFunctions() |
| 1453 | { |
| 1454 | // get firmware version information |
| 1455 | ipmiPrintAndRegister(NETFUN_SENSOR, IPMI_CMD_WILDCARD, nullptr, |
| 1456 | ipmiSensorWildcardHandler, PRIVILEGE_USER); |
| 1457 | |
| 1458 | // <Get Sensor Type> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1459 | ipmiPrintAndRegister(NETFUN_SENSOR, ipmi::sensor_event::cmdGetSensorType, |
| 1460 | nullptr, ipmiSensorWildcardHandler, PRIVILEGE_USER); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1461 | |
| 1462 | // <Set Sensor Reading and Event Status> |
| 1463 | ipmiPrintAndRegister( |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1464 | NETFUN_SENSOR, ipmi::sensor_event::cmdSetSensorReadingAndEvtSts, |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1465 | nullptr, ipmiSensorWildcardHandler, PRIVILEGE_OPERATOR); |
| 1466 | |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 1467 | // <Platform Event> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1468 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1469 | ipmi::sensor_event::cmdPlatformEvent, |
| 1470 | ipmi::Privilege::Operator, ipmiSenPlatformEvent); |
Jason M. Bills | ae6bdb1 | 2019-04-02 12:00:04 -0700 | [diff] [blame] | 1471 | |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1472 | // <Get Sensor Reading> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1473 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1474 | ipmi::sensor_event::cmdGetSensorReading, |
| 1475 | ipmi::Privilege::User, ipmiSenGetSensorReading); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1476 | |
| 1477 | // <Get Sensor Threshold> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1478 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1479 | ipmi::sensor_event::cmdGetSensorThreshold, |
| 1480 | ipmi::Privilege::User, ipmiSenGetSensorThresholds); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1481 | |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 1482 | // <Set Sensor Threshold> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1483 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1484 | ipmi::sensor_event::cmdSetSensorThreshold, |
| 1485 | ipmi::Privilege::Operator, |
| 1486 | ipmiSenSetSensorThresholds); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1487 | |
| 1488 | // <Get Sensor Event Enable> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1489 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1490 | ipmi::sensor_event::cmdGetSensorEventEnable, |
jayaprakash Mutyala | 39fa93f | 2019-05-13 12:16:30 +0000 | [diff] [blame] | 1491 | ipmi::Privilege::User, ipmiSenGetSensorEventEnable); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1492 | |
| 1493 | // <Get Sensor Event Status> |
| 1494 | ipmiPrintAndRegister(NETFUN_SENSOR, |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1495 | ipmi::sensor_event::cmdGetSensorEventStatus, nullptr, |
| 1496 | ipmiSenGetSensorEventStatus, PRIVILEGE_USER); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1497 | |
| 1498 | // register all storage commands for both Sensor and Storage command |
| 1499 | // versions |
| 1500 | |
| 1501 | // <Get SDR Repository Info> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1502 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1503 | ipmi::storage::cmdGetSdrRepositoryInfo, |
| 1504 | ipmi::Privilege::User, |
| 1505 | ipmiStorageGetSDRRepositoryInfo); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1506 | |
| 1507 | // <Get SDR Allocation Info> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1508 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1509 | ipmi::storage::cmdGetSdrRepositoryAllocInfo, |
| 1510 | ipmi::Privilege::User, |
| 1511 | ipmiStorageGetSDRAllocationInfo); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1512 | |
| 1513 | // <Reserve SDR Repo> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1514 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1515 | ipmi::sensor_event::cmdReserveDeviceSdrRepository, |
jayaprakash Mutyala | 6ae0818 | 2019-05-13 18:56:11 +0000 | [diff] [blame] | 1516 | ipmi::Privilege::User, ipmiStorageReserveSDR); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1517 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1518 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1519 | ipmi::storage::cmdReserveSdrRepository, |
| 1520 | ipmi::Privilege::User, ipmiStorageReserveSDR); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1521 | |
| 1522 | // <Get Sdr> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1523 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnSensor, |
| 1524 | ipmi::sensor_event::cmdGetDeviceSdr, |
| 1525 | ipmi::Privilege::User, ipmiStorageGetSDR); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1526 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1527 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage, |
| 1528 | ipmi::storage::cmdGetSdr, ipmi::Privilege::User, |
| 1529 | ipmiStorageGetSDR); |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 1530 | } |
| 1531 | } // namespace ipmi |