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