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