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