Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 1 | #include "sensordatahandler.hpp" |
| 2 | |
| 3 | #include "sensorhandler.hpp" |
| 4 | #include "types.hpp" |
| 5 | #include "utils.hpp" |
| 6 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 7 | #include <bitset> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 8 | #include <optional> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 9 | #include <phosphor-logging/elog-errors.hpp> |
| 10 | #include <phosphor-logging/log.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 11 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Common/error.hpp> |
| 13 | |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 14 | #if __has_include(<filesystem>) |
| 15 | #include <filesystem> |
| 16 | #elif __has_include(<experimental/filesystem>) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 17 | #include <experimental/filesystem> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 18 | namespace std |
| 19 | { |
| 20 | // splice experimental::filesystem into std |
| 21 | namespace filesystem = std::experimental::filesystem; |
| 22 | } // namespace std |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 23 | #else |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 24 | #error filesystem not available |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 25 | #endif |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 26 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 27 | namespace ipmi |
| 28 | { |
| 29 | namespace sensor |
| 30 | { |
| 31 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 32 | namespace variant_ns = sdbusplus::message::variant_ns; |
| 33 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 34 | using namespace phosphor::logging; |
| 35 | using InternalFailure = |
| 36 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 37 | |
| 38 | static constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 39 | static constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 40 | static constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 41 | |
| 42 | /** @brief get the D-Bus service and service path |
| 43 | * @param[in] bus - The Dbus bus object |
| 44 | * @param[in] interface - interface to the service |
| 45 | * @param[in] path - interested path in the list of objects |
| 46 | * @return pair of service path and service |
| 47 | */ |
| 48 | ServicePath getServiceAndPath(sdbusplus::bus::bus& bus, |
| 49 | const std::string& interface, |
| 50 | const std::string& path) |
| 51 | { |
| 52 | auto depth = 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 53 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 54 | MAPPER_INTERFACE, "GetSubTree"); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 55 | mapperCall.append("/"); |
| 56 | mapperCall.append(depth); |
| 57 | mapperCall.append(std::vector<Interface>({interface})); |
| 58 | |
| 59 | auto mapperResponseMsg = bus.call(mapperCall); |
| 60 | if (mapperResponseMsg.is_method_error()) |
| 61 | { |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 62 | log<level::ERR>("Mapper GetSubTree failed", |
Joseph Reynolds | 510eb9c | 2018-05-30 11:51:28 -0500 | [diff] [blame] | 63 | entry("PATH=%s", path.c_str()), |
| 64 | entry("INTERFACE=%s", interface.c_str())); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 65 | elog<InternalFailure>(); |
| 66 | } |
| 67 | |
| 68 | MapperResponseType mapperResponse; |
| 69 | mapperResponseMsg.read(mapperResponse); |
| 70 | if (mapperResponse.empty()) |
| 71 | { |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 72 | log<level::ERR>("Invalid mapper response", |
Joseph Reynolds | 510eb9c | 2018-05-30 11:51:28 -0500 | [diff] [blame] | 73 | entry("PATH=%s", path.c_str()), |
| 74 | entry("INTERFACE=%s", interface.c_str())); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 75 | elog<InternalFailure>(); |
| 76 | } |
| 77 | |
| 78 | if (path.empty()) |
| 79 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 80 | // Get the first one if the path is not in list. |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 81 | return std::make_pair(mapperResponse.begin()->first, |
| 82 | mapperResponse.begin()->second.begin()->first); |
| 83 | } |
| 84 | const auto& iter = mapperResponse.find(path); |
| 85 | if (iter == mapperResponse.end()) |
| 86 | { |
Gunnar Mills | c9fa69e | 2018-04-08 16:35:25 -0500 | [diff] [blame] | 87 | log<level::ERR>("Couldn't find D-Bus path", |
Joseph Reynolds | 510eb9c | 2018-05-30 11:51:28 -0500 | [diff] [blame] | 88 | entry("PATH=%s", path.c_str()), |
| 89 | entry("INTERFACE=%s", interface.c_str())); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 90 | elog<InternalFailure>(); |
| 91 | } |
| 92 | return std::make_pair(iter->first, iter->second.begin()->first); |
| 93 | } |
| 94 | |
| 95 | AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData) |
| 96 | { |
| 97 | Assertion assertionStates = |
| 98 | (static_cast<Assertion>(cmdData.assertOffset8_14)) << 8 | |
| 99 | cmdData.assertOffset0_7; |
| 100 | Deassertion deassertionStates = |
| 101 | (static_cast<Deassertion>(cmdData.deassertOffset8_14)) << 8 | |
| 102 | cmdData.deassertOffset0_7; |
| 103 | return std::make_pair(assertionStates, deassertionStates); |
| 104 | } |
| 105 | |
| 106 | ipmi_ret_t updateToDbus(IpmiUpdateData& msg) |
| 107 | { |
| 108 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 109 | try |
| 110 | { |
| 111 | auto serviceResponseMsg = bus.call(msg); |
| 112 | if (serviceResponseMsg.is_method_error()) |
| 113 | { |
| 114 | log<level::ERR>("Error in D-Bus call"); |
| 115 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 116 | } |
| 117 | } |
| 118 | catch (InternalFailure& e) |
| 119 | { |
| 120 | commit<InternalFailure>(); |
| 121 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 122 | } |
| 123 | return IPMI_CC_OK; |
| 124 | } |
| 125 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 126 | namespace get |
| 127 | { |
| 128 | |
Tom Joseph | b0adbcd | 2018-01-24 11:51:29 +0530 | [diff] [blame] | 129 | SensorName nameParentLeaf(const Info& sensorInfo) |
| 130 | { |
| 131 | const auto pos = sensorInfo.sensorPath.find_last_of('/'); |
| 132 | const auto leaf = sensorInfo.sensorPath.substr(pos + 1); |
| 133 | |
| 134 | const auto remaining = sensorInfo.sensorPath.substr(0, pos); |
| 135 | |
| 136 | const auto parentPos = remaining.find_last_of('/'); |
| 137 | auto parent = remaining.substr(parentPos + 1); |
| 138 | |
| 139 | parent += "_" + leaf; |
| 140 | return parent; |
| 141 | } |
| 142 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 143 | GetSensorResponse mapDbusToAssertion(const Info& sensorInfo, |
| 144 | const InstancePath& path, |
| 145 | const DbusInterface& interface) |
| 146 | { |
| 147 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 148 | GetSensorResponse response{}; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 149 | auto responseData = reinterpret_cast<GetReadingResponse*>(response.data()); |
| 150 | |
| 151 | auto service = ipmi::getService(bus, interface, path); |
| 152 | |
| 153 | const auto& interfaceList = sensorInfo.propertyInterfaces; |
| 154 | |
| 155 | for (const auto& interface : interfaceList) |
| 156 | { |
| 157 | for (const auto& property : interface.second) |
| 158 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 159 | auto propValue = ipmi::getDbusProperty( |
| 160 | bus, service, path, interface.first, property.first); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 161 | |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 162 | for (const auto& value : std::get<OffsetValueMap>(property.second)) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 163 | { |
| 164 | if (propValue == value.second.assert) |
| 165 | { |
| 166 | setOffset(value.first, responseData); |
| 167 | break; |
| 168 | } |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return response; |
| 174 | } |
| 175 | |
| 176 | GetSensorResponse assertion(const Info& sensorInfo) |
| 177 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 178 | return mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath, |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 179 | sensorInfo.sensorInterface); |
| 180 | } |
| 181 | |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 182 | GetSensorResponse eventdata2(const Info& sensorInfo) |
| 183 | { |
| 184 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 185 | GetSensorResponse response{}; |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 186 | auto responseData = reinterpret_cast<GetReadingResponse*>(response.data()); |
| 187 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 188 | auto service = ipmi::getService(bus, sensorInfo.sensorInterface, |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 189 | sensorInfo.sensorPath); |
| 190 | |
| 191 | const auto& interfaceList = sensorInfo.propertyInterfaces; |
| 192 | |
| 193 | for (const auto& interface : interfaceList) |
| 194 | { |
| 195 | for (const auto& property : interface.second) |
| 196 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 197 | auto propValue = |
| 198 | ipmi::getDbusProperty(bus, service, sensorInfo.sensorPath, |
| 199 | interface.first, property.first); |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 200 | |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 201 | for (const auto& value : std::get<OffsetValueMap>(property.second)) |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 202 | { |
| 203 | if (propValue == value.second.assert) |
| 204 | { |
| 205 | setReading(value.first, responseData); |
| 206 | break; |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | return response; |
| 213 | } |
| 214 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 215 | } // namespace get |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 216 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 217 | namespace set |
| 218 | { |
| 219 | |
| 220 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
| 221 | const std::string& sensorPath, |
| 222 | const std::string& command, |
| 223 | const std::string& sensorInterface) |
| 224 | { |
| 225 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 226 | using namespace std::string_literals; |
| 227 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 228 | auto dbusService = getService(bus, sensorInterface, sensorPath); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 229 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 230 | return bus.new_method_call(dbusService.c_str(), sensorPath.c_str(), |
| 231 | updateInterface.c_str(), command.c_str()); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 232 | } |
| 233 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 234 | ipmi_ret_t eventdata(const SetSensorReadingReq& cmdData, const Info& sensorInfo, |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 235 | uint8_t data) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 236 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 237 | auto msg = |
| 238 | makeDbusMsg("org.freedesktop.DBus.Properties", sensorInfo.sensorPath, |
| 239 | "Set", sensorInfo.sensorInterface); |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 240 | |
| 241 | const auto& interface = sensorInfo.propertyInterfaces.begin(); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 242 | msg.append(interface->first); |
| 243 | for (const auto& property : interface->second) |
| 244 | { |
| 245 | msg.append(property.first); |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 246 | const auto& iter = std::get<OffsetValueMap>(property.second).find(data); |
| 247 | if (iter == std::get<OffsetValueMap>(property.second).end()) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 248 | { |
| 249 | log<level::ERR>("Invalid event data"); |
| 250 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 251 | } |
| 252 | msg.append(iter->second.assert); |
| 253 | } |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 254 | return updateToDbus(msg); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 255 | } |
| 256 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 257 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 258 | { |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 259 | std::bitset<16> assertionSet(getAssertionSet(cmdData).first); |
| 260 | std::bitset<16> deassertionSet(getAssertionSet(cmdData).second); |
| 261 | auto bothSet = assertionSet ^ deassertionSet; |
| 262 | |
| 263 | const auto& interface = sensorInfo.propertyInterfaces.begin(); |
| 264 | |
| 265 | for (const auto& property : interface->second) |
| 266 | { |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 267 | std::optional<Value> tmp; |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 268 | for (const auto& value : std::get<OffsetValueMap>(property.second)) |
| 269 | { |
| 270 | if (bothSet.size() <= value.first || !bothSet.test(value.first)) |
| 271 | { |
| 272 | // A BIOS shouldn't do this but ignore if they do. |
| 273 | continue; |
| 274 | } |
| 275 | |
| 276 | if (assertionSet.test(value.first)) |
| 277 | { |
| 278 | tmp = value.second.assert; |
| 279 | break; |
| 280 | } |
| 281 | if (deassertionSet.test(value.first)) |
| 282 | { |
| 283 | tmp = value.second.deassert; |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 288 | if (tmp) |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 289 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 290 | auto msg = makeDbusMsg("org.freedesktop.DBus.Properties", |
| 291 | sensorInfo.sensorPath, "Set", |
| 292 | sensorInfo.sensorInterface); |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 293 | msg.append(interface->first); |
| 294 | msg.append(property.first); |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 295 | msg.append(*tmp); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 296 | |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 297 | auto rc = updateToDbus(msg); |
| 298 | if (rc) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 299 | { |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 300 | return rc; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 304 | |
| 305 | return IPMI_CC_OK; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 306 | } |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 307 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 308 | } // namespace set |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 309 | |
| 310 | namespace notify |
| 311 | { |
| 312 | |
| 313 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
| 314 | const std::string& sensorPath, |
| 315 | const std::string& command, |
| 316 | const std::string& sensorInterface) |
| 317 | { |
| 318 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 319 | using namespace std::string_literals; |
| 320 | |
Dhruvaraj Subhashchandran | f915f85 | 2017-09-14 07:01:48 -0500 | [diff] [blame] | 321 | static const auto dbusPath = "/xyz/openbmc_project/inventory"s; |
| 322 | std::string dbusService = ipmi::getService(bus, updateInterface, dbusPath); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 323 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 324 | return bus.new_method_call(dbusService.c_str(), dbusPath.c_str(), |
| 325 | updateInterface.c_str(), command.c_str()); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 326 | } |
| 327 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 328 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 329 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 330 | auto msg = makeDbusMsg(sensorInfo.sensorInterface, sensorInfo.sensorPath, |
| 331 | "Notify", sensorInfo.sensorInterface); |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 332 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 333 | std::bitset<16> assertionSet(getAssertionSet(cmdData).first); |
| 334 | std::bitset<16> deassertionSet(getAssertionSet(cmdData).second); |
| 335 | ipmi::sensor::ObjectMap objects; |
| 336 | ipmi::sensor::InterfaceMap interfaces; |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 337 | for (const auto& interface : sensorInfo.propertyInterfaces) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 338 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 339 | // For a property like functional state the result will be |
| 340 | // calculated based on the true value of all conditions. |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 341 | for (const auto& property : interface.second) |
| 342 | { |
| 343 | ipmi::sensor::PropertyMap props; |
| 344 | bool valid = false; |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 345 | auto result = true; |
| 346 | for (const auto& value : std::get<OffsetValueMap>(property.second)) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 347 | { |
| 348 | if (assertionSet.test(value.first)) |
| 349 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 350 | // Skip update if skipOn is ASSERT |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 351 | if (SkipAssertion::ASSERT == value.second.skip) |
| 352 | { |
| 353 | return IPMI_CC_OK; |
| 354 | } |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 355 | result = |
| 356 | result && variant_ns::get<bool>(value.second.assert); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 357 | valid = true; |
| 358 | } |
| 359 | else if (deassertionSet.test(value.first)) |
| 360 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 361 | // Skip update if skipOn is DEASSERT |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 362 | if (SkipAssertion::DEASSERT == value.second.skip) |
| 363 | { |
| 364 | return IPMI_CC_OK; |
| 365 | } |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 366 | result = |
| 367 | result && variant_ns::get<bool>(value.second.deassert); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 368 | valid = true; |
| 369 | } |
| 370 | } |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 371 | for (const auto& value : |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 372 | std::get<PreReqOffsetValueMap>(property.second)) |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 373 | { |
| 374 | if (assertionSet.test(value.first)) |
| 375 | { |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 376 | result = |
| 377 | result && variant_ns::get<bool>(value.second.assert); |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 378 | } |
| 379 | else if (deassertionSet.test(value.first)) |
| 380 | { |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 381 | result = |
| 382 | result && variant_ns::get<bool>(value.second.deassert); |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 383 | } |
| 384 | } |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 385 | if (valid) |
| 386 | { |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 387 | props.emplace(property.first, result); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 388 | interfaces.emplace(interface.first, std::move(props)); |
| 389 | } |
| 390 | } |
| 391 | } |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 392 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 393 | objects.emplace(sensorInfo.sensorPath, std::move(interfaces)); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 394 | msg.append(std::move(objects)); |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 395 | return updateToDbus(msg); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 396 | } |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 397 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 398 | } // namespace notify |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 399 | |
| 400 | namespace inventory |
| 401 | { |
| 402 | |
| 403 | namespace get |
| 404 | { |
| 405 | |
| 406 | GetSensorResponse assertion(const Info& sensorInfo) |
| 407 | { |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 408 | namespace fs = std::filesystem; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 409 | |
| 410 | fs::path path{ipmi::sensor::inventoryRoot}; |
| 411 | path += sensorInfo.sensorPath; |
| 412 | |
| 413 | return ipmi::sensor::get::mapDbusToAssertion( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 414 | sensorInfo, path.string(), |
| 415 | sensorInfo.propertyInterfaces.begin()->first); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 416 | } |
| 417 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 418 | } // namespace get |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 419 | |
| 420 | } // namespace inventory |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 421 | } // namespace sensor |
| 422 | } // namespace ipmi |