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