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