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