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