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 | |
| 20 | using namespace phosphor::logging; |
| 21 | using InternalFailure = |
| 22 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 23 | |
| 24 | static constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 25 | static constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 26 | static constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 27 | |
| 28 | /** @brief get the D-Bus service and service path |
| 29 | * @param[in] bus - The Dbus bus object |
| 30 | * @param[in] interface - interface to the service |
| 31 | * @param[in] path - interested path in the list of objects |
| 32 | * @return pair of service path and service |
| 33 | */ |
| 34 | ServicePath getServiceAndPath(sdbusplus::bus::bus& bus, |
| 35 | const std::string& interface, |
| 36 | const std::string& path) |
| 37 | { |
| 38 | auto depth = 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 39 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 40 | MAPPER_INTERFACE, "GetSubTree"); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 41 | mapperCall.append("/"); |
| 42 | mapperCall.append(depth); |
| 43 | mapperCall.append(std::vector<Interface>({interface})); |
| 44 | |
| 45 | auto mapperResponseMsg = bus.call(mapperCall); |
| 46 | if (mapperResponseMsg.is_method_error()) |
| 47 | { |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 48 | log<level::ERR>("Mapper GetSubTree failed", |
Joseph Reynolds | 510eb9c | 2018-05-30 11:51:28 -0500 | [diff] [blame] | 49 | entry("PATH=%s", path.c_str()), |
| 50 | entry("INTERFACE=%s", interface.c_str())); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 51 | elog<InternalFailure>(); |
| 52 | } |
| 53 | |
| 54 | MapperResponseType mapperResponse; |
| 55 | mapperResponseMsg.read(mapperResponse); |
| 56 | if (mapperResponse.empty()) |
| 57 | { |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 58 | log<level::ERR>("Invalid mapper response", |
Joseph Reynolds | 510eb9c | 2018-05-30 11:51:28 -0500 | [diff] [blame] | 59 | entry("PATH=%s", path.c_str()), |
| 60 | entry("INTERFACE=%s", interface.c_str())); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 61 | elog<InternalFailure>(); |
| 62 | } |
| 63 | |
| 64 | if (path.empty()) |
| 65 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 66 | // Get the first one if the path is not in list. |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 67 | return std::make_pair(mapperResponse.begin()->first, |
| 68 | mapperResponse.begin()->second.begin()->first); |
| 69 | } |
| 70 | const auto& iter = mapperResponse.find(path); |
| 71 | if (iter == mapperResponse.end()) |
| 72 | { |
Gunnar Mills | c9fa69e | 2018-04-08 16:35:25 -0500 | [diff] [blame] | 73 | log<level::ERR>("Couldn't find D-Bus path", |
Joseph Reynolds | 510eb9c | 2018-05-30 11:51:28 -0500 | [diff] [blame] | 74 | entry("PATH=%s", path.c_str()), |
| 75 | entry("INTERFACE=%s", interface.c_str())); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 76 | elog<InternalFailure>(); |
| 77 | } |
| 78 | return std::make_pair(iter->first, iter->second.begin()->first); |
| 79 | } |
| 80 | |
| 81 | AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData) |
| 82 | { |
| 83 | Assertion assertionStates = |
| 84 | (static_cast<Assertion>(cmdData.assertOffset8_14)) << 8 | |
| 85 | cmdData.assertOffset0_7; |
| 86 | Deassertion deassertionStates = |
| 87 | (static_cast<Deassertion>(cmdData.deassertOffset8_14)) << 8 | |
| 88 | cmdData.deassertOffset0_7; |
| 89 | return std::make_pair(assertionStates, deassertionStates); |
| 90 | } |
| 91 | |
| 92 | ipmi_ret_t updateToDbus(IpmiUpdateData& msg) |
| 93 | { |
| 94 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 95 | try |
| 96 | { |
| 97 | auto serviceResponseMsg = bus.call(msg); |
| 98 | if (serviceResponseMsg.is_method_error()) |
| 99 | { |
| 100 | log<level::ERR>("Error in D-Bus call"); |
| 101 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 102 | } |
| 103 | } |
| 104 | catch (InternalFailure& e) |
| 105 | { |
| 106 | commit<InternalFailure>(); |
| 107 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 108 | } |
| 109 | return IPMI_CC_OK; |
| 110 | } |
| 111 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 112 | namespace get |
| 113 | { |
| 114 | |
Tom Joseph | b0adbcd | 2018-01-24 11:51:29 +0530 | [diff] [blame] | 115 | SensorName nameParentLeaf(const Info& sensorInfo) |
| 116 | { |
| 117 | const auto pos = sensorInfo.sensorPath.find_last_of('/'); |
| 118 | const auto leaf = sensorInfo.sensorPath.substr(pos + 1); |
| 119 | |
| 120 | const auto remaining = sensorInfo.sensorPath.substr(0, pos); |
| 121 | |
| 122 | const auto parentPos = remaining.find_last_of('/'); |
| 123 | auto parent = remaining.substr(parentPos + 1); |
| 124 | |
| 125 | parent += "_" + leaf; |
| 126 | return parent; |
| 127 | } |
| 128 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 129 | GetSensorResponse mapDbusToAssertion(const Info& sensorInfo, |
| 130 | const InstancePath& path, |
| 131 | const DbusInterface& interface) |
| 132 | { |
| 133 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 134 | GetSensorResponse response{}; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 135 | |
Jeremy Kerr | 3dc3558 | 2020-05-17 15:47:07 +0800 | [diff] [blame] | 136 | enableScanning(&response); |
| 137 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 138 | auto service = ipmi::getService(bus, interface, path); |
| 139 | |
| 140 | const auto& interfaceList = sensorInfo.propertyInterfaces; |
| 141 | |
| 142 | for (const auto& interface : interfaceList) |
| 143 | { |
| 144 | for (const auto& property : interface.second) |
| 145 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 146 | auto propValue = ipmi::getDbusProperty( |
| 147 | bus, service, path, interface.first, property.first); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 148 | |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 149 | for (const auto& value : std::get<OffsetValueMap>(property.second)) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 150 | { |
| 151 | if (propValue == value.second.assert) |
| 152 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 153 | setOffset(value.first, &response); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 154 | break; |
| 155 | } |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return response; |
| 161 | } |
| 162 | |
| 163 | GetSensorResponse assertion(const Info& sensorInfo) |
| 164 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 165 | return mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath, |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 166 | sensorInfo.sensorInterface); |
| 167 | } |
| 168 | |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 169 | GetSensorResponse eventdata2(const Info& sensorInfo) |
| 170 | { |
| 171 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 172 | GetSensorResponse response{}; |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 173 | |
Jeremy Kerr | 3dc3558 | 2020-05-17 15:47:07 +0800 | [diff] [blame] | 174 | enableScanning(&response); |
| 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 | { |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 193 | setReading(value.first, &response); |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 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 | { |
Santosh Puranik | bbf8bd6 | 2019-05-01 19:02:52 +0530 | [diff] [blame] | 327 | // An interface with no properties - It is possible that the sensor |
| 328 | // object on DBUS implements a DBUS interface with no properties. |
| 329 | // Make sure we add the interface to the list if interfaces on the |
| 330 | // object with an empty property map. |
| 331 | if (interface.second.empty()) |
| 332 | { |
| 333 | interfaces.emplace(interface.first, ipmi::sensor::PropertyMap{}); |
| 334 | continue; |
| 335 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 336 | // For a property like functional state the result will be |
| 337 | // calculated based on the true value of all conditions. |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 338 | for (const auto& property : interface.second) |
| 339 | { |
| 340 | ipmi::sensor::PropertyMap props; |
| 341 | bool valid = false; |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 342 | auto result = true; |
| 343 | for (const auto& value : std::get<OffsetValueMap>(property.second)) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 344 | { |
| 345 | if (assertionSet.test(value.first)) |
| 346 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 347 | // Skip update if skipOn is ASSERT |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 348 | if (SkipAssertion::ASSERT == value.second.skip) |
| 349 | { |
| 350 | return IPMI_CC_OK; |
| 351 | } |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 352 | result = result && std::get<bool>(value.second.assert); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 353 | valid = true; |
| 354 | } |
| 355 | else if (deassertionSet.test(value.first)) |
| 356 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 357 | // Skip update if skipOn is DEASSERT |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 358 | if (SkipAssertion::DEASSERT == value.second.skip) |
| 359 | { |
| 360 | return IPMI_CC_OK; |
| 361 | } |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 362 | result = result && std::get<bool>(value.second.deassert); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 363 | valid = true; |
| 364 | } |
| 365 | } |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 366 | for (const auto& value : |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 367 | std::get<PreReqOffsetValueMap>(property.second)) |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 368 | { |
| 369 | if (assertionSet.test(value.first)) |
| 370 | { |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 371 | result = result && std::get<bool>(value.second.assert); |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 372 | } |
| 373 | else if (deassertionSet.test(value.first)) |
| 374 | { |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 375 | result = result && std::get<bool>(value.second.deassert); |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 376 | } |
| 377 | } |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 378 | if (valid) |
| 379 | { |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 380 | props.emplace(property.first, result); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 381 | interfaces.emplace(interface.first, std::move(props)); |
| 382 | } |
| 383 | } |
| 384 | } |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 385 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 386 | objects.emplace(sensorInfo.sensorPath, std::move(interfaces)); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 387 | msg.append(std::move(objects)); |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 388 | return updateToDbus(msg); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 389 | } |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 390 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 391 | } // namespace notify |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 392 | |
| 393 | namespace inventory |
| 394 | { |
| 395 | |
| 396 | namespace get |
| 397 | { |
| 398 | |
| 399 | GetSensorResponse assertion(const Info& sensorInfo) |
| 400 | { |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 401 | namespace fs = std::filesystem; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 402 | |
| 403 | fs::path path{ipmi::sensor::inventoryRoot}; |
| 404 | path += sensorInfo.sensorPath; |
| 405 | |
| 406 | return ipmi::sensor::get::mapDbusToAssertion( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 407 | sensorInfo, path.string(), |
| 408 | sensorInfo.propertyInterfaces.begin()->first); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 409 | } |
| 410 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 411 | } // namespace get |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 412 | |
| 413 | } // namespace inventory |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 414 | } // namespace sensor |
| 415 | } // namespace ipmi |