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 | |
George Liu | 23c868c | 2025-07-04 09:31:35 +0800 | [diff] [blame] | 34 | ipmi::Cc updateToDbus(IpmiUpdateData& msg) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 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>(); |
George Liu | 879c1d8 | 2025-07-03 09:36:57 +0800 | [diff] [blame] | 45 | return ipmi::ccUnspecifiedError; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 46 | } |
George Liu | e8a97bd | 2024-12-05 17:26:46 +0800 | [diff] [blame] | 47 | return ipmi::ccSuccess; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 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 | |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 80 | for (const auto& [intf, propertyMap] : interfaceList) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 81 | { |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 82 | for (const auto& [property, values] : propertyMap) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 83 | { |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 84 | try |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 85 | { |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 86 | auto propValue = |
| 87 | ipmi::getDbusProperty(bus, service, path, intf, property); |
| 88 | |
| 89 | for (const auto& value : std::get<OffsetValueMap>(values)) |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 90 | { |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 91 | if (propValue == value.second.assert) |
| 92 | { |
| 93 | setOffset(value.first, &response); |
| 94 | break; |
| 95 | } |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 96 | } |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 97 | } |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 98 | catch (const std::exception& e) |
| 99 | { |
| 100 | lg2::error( |
| 101 | "mapDbusToAssertion: Failed to get property, service: {SERVICE}," |
| 102 | " path: {PATH}, interface: {INTERFACE}, property name: {PRONAME}: {ERROR}", |
| 103 | "SERVICE", service, "PATH", path, "INTERFACE", intf, |
| 104 | "PRONAME", property, "ERROR", e); |
| 105 | } |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | return response; |
| 110 | } |
| 111 | |
Lei YU | a8dc09b | 2021-10-13 18:06:46 +0800 | [diff] [blame] | 112 | GetSensorResponse mapDbusToEventdata2(const Info& sensorInfo) |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 113 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 114 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 115 | GetSensorResponse response{}; |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 116 | |
Jeremy Kerr | 3dc3558 | 2020-05-17 15:47:07 +0800 | [diff] [blame] | 117 | enableScanning(&response); |
| 118 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 119 | auto service = ipmi::getService(bus, sensorInfo.sensorInterface, |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 120 | sensorInfo.sensorPath); |
| 121 | |
| 122 | const auto& interfaceList = sensorInfo.propertyInterfaces; |
| 123 | |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 124 | for (const auto& [intf, propertyMap] : interfaceList) |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 125 | { |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 126 | for (const auto& [property, values] : propertyMap) |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 127 | { |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 128 | try |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 129 | { |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 130 | auto propValue = ipmi::getDbusProperty( |
| 131 | bus, service, sensorInfo.sensorPath, intf, property); |
| 132 | |
| 133 | for (const auto& value : std::get<OffsetValueMap>(values)) |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 134 | { |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 135 | if (propValue == value.second.assert) |
| 136 | { |
| 137 | setReading(value.first, &response); |
| 138 | break; |
| 139 | } |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 140 | } |
| 141 | } |
George Liu | 08d3add | 2024-11-18 15:22:43 +0800 | [diff] [blame] | 142 | catch (const std::exception& e) |
| 143 | { |
| 144 | lg2::error( |
| 145 | "mapDbusToEventdata2: Failed to get property, service: {SERVICE}," |
| 146 | " path: {PATH}, interface: {INTERFACE}, property name: {PRONAME}: {ERROR}", |
| 147 | "SERVICE", service, "PATH", sensorInfo.sensorPath, |
| 148 | "INTERFACE", intf, "PRONAME", property, "ERROR", e); |
| 149 | } |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | return response; |
| 154 | } |
Lei YU | a8dc09b | 2021-10-13 18:06:46 +0800 | [diff] [blame] | 155 | |
| 156 | #ifndef FEATURE_SENSORS_CACHE |
| 157 | GetSensorResponse assertion(const Info& sensorInfo) |
| 158 | { |
| 159 | return mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath, |
| 160 | sensorInfo.sensorInterface); |
| 161 | } |
| 162 | |
| 163 | GetSensorResponse eventdata2(const Info& sensorInfo) |
| 164 | { |
| 165 | return mapDbusToEventdata2(sensorInfo); |
| 166 | } |
Lei YU | 8c2c048 | 2021-09-16 17:28:28 +0800 | [diff] [blame] | 167 | #else |
| 168 | std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo, |
Lei YU | 8e8152c | 2021-12-06 20:11:08 +0800 | [diff] [blame] | 169 | const PropertyMap& /*properties*/) |
Lei YU | 8c2c048 | 2021-09-16 17:28:28 +0800 | [diff] [blame] | 170 | { |
Lei YU | ef960c0 | 2021-10-13 17:54:59 +0800 | [diff] [blame] | 171 | // The assertion may contain multiple properties |
| 172 | // So we have to get the properties from DBus anyway |
| 173 | auto response = mapDbusToAssertion(sensorInfo, sensorInfo.sensorPath, |
| 174 | sensorInfo.sensorInterface); |
| 175 | |
| 176 | if (!sensorCacheMap[id].has_value()) |
| 177 | { |
| 178 | sensorCacheMap[id] = SensorData{}; |
| 179 | } |
| 180 | sensorCacheMap[id]->response = response; |
| 181 | return response; |
Lei YU | 8c2c048 | 2021-09-16 17:28:28 +0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | std::optional<GetSensorResponse> eventdata2(uint8_t id, const Info& sensorInfo, |
Lei YU | 8e8152c | 2021-12-06 20:11:08 +0800 | [diff] [blame] | 185 | const PropertyMap& /*properties*/) |
Lei YU | 8c2c048 | 2021-09-16 17:28:28 +0800 | [diff] [blame] | 186 | { |
Lei YU | a8dc09b | 2021-10-13 18:06:46 +0800 | [diff] [blame] | 187 | // The eventdata2 may contain multiple properties |
| 188 | // So we have to get the properties from DBus anyway |
| 189 | auto response = mapDbusToEventdata2(sensorInfo); |
| 190 | |
| 191 | if (!sensorCacheMap[id].has_value()) |
| 192 | { |
| 193 | sensorCacheMap[id] = SensorData{}; |
| 194 | } |
| 195 | sensorCacheMap[id]->response = response; |
| 196 | return response; |
Lei YU | 8c2c048 | 2021-09-16 17:28:28 +0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | #endif // FEATURE_SENSORS_CACHE |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 200 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 201 | } // namespace get |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 202 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 203 | namespace set |
| 204 | { |
| 205 | |
| 206 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
| 207 | const std::string& sensorPath, |
| 208 | const std::string& command, |
| 209 | const std::string& sensorInterface) |
| 210 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 211 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 212 | using namespace std::string_literals; |
| 213 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 214 | auto dbusService = getService(bus, sensorInterface, sensorPath); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 215 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 216 | return bus.new_method_call(dbusService.c_str(), sensorPath.c_str(), |
| 217 | updateInterface.c_str(), command.c_str()); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 218 | } |
| 219 | |
George Liu | 23c868c | 2025-07-04 09:31:35 +0800 | [diff] [blame] | 220 | ipmi::Cc eventdata(const SetSensorReadingReq&, const Info& sensorInfo, |
| 221 | uint8_t data) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 222 | { |
Patrick Williams | 1318a5e | 2024-08-16 15:19:54 -0400 | [diff] [blame] | 223 | auto msg = |
| 224 | makeDbusMsg("org.freedesktop.DBus.Properties", sensorInfo.sensorPath, |
| 225 | "Set", sensorInfo.sensorInterface); |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 226 | |
| 227 | const auto& interface = sensorInfo.propertyInterfaces.begin(); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 228 | msg.append(interface->first); |
| 229 | for (const auto& property : interface->second) |
| 230 | { |
| 231 | msg.append(property.first); |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 232 | const auto& iter = std::get<OffsetValueMap>(property.second).find(data); |
| 233 | if (iter == std::get<OffsetValueMap>(property.second).end()) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 234 | { |
George Liu | 9b745a8 | 2024-07-19 09:09:36 +0800 | [diff] [blame] | 235 | lg2::error("Invalid event data"); |
George Liu | 879c1d8 | 2025-07-03 09:36:57 +0800 | [diff] [blame] | 236 | return ipmi::ccParmOutOfRange; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 237 | } |
| 238 | msg.append(iter->second.assert); |
| 239 | } |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 240 | return updateToDbus(msg); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 241 | } |
| 242 | |
George Liu | 23c868c | 2025-07-04 09:31:35 +0800 | [diff] [blame] | 243 | ipmi::Cc assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 244 | { |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 245 | std::bitset<16> assertionSet(getAssertionSet(cmdData).first); |
| 246 | std::bitset<16> deassertionSet(getAssertionSet(cmdData).second); |
| 247 | auto bothSet = assertionSet ^ deassertionSet; |
| 248 | |
| 249 | const auto& interface = sensorInfo.propertyInterfaces.begin(); |
| 250 | |
| 251 | for (const auto& property : interface->second) |
| 252 | { |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 253 | std::optional<Value> tmp; |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 254 | for (const auto& value : std::get<OffsetValueMap>(property.second)) |
| 255 | { |
| 256 | if (bothSet.size() <= value.first || !bothSet.test(value.first)) |
| 257 | { |
| 258 | // A BIOS shouldn't do this but ignore if they do. |
| 259 | continue; |
| 260 | } |
| 261 | |
| 262 | if (assertionSet.test(value.first)) |
| 263 | { |
| 264 | tmp = value.second.assert; |
| 265 | break; |
| 266 | } |
| 267 | if (deassertionSet.test(value.first)) |
| 268 | { |
| 269 | tmp = value.second.deassert; |
| 270 | break; |
| 271 | } |
| 272 | } |
| 273 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 274 | if (tmp) |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 275 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 276 | auto msg = makeDbusMsg("org.freedesktop.DBus.Properties", |
| 277 | sensorInfo.sensorPath, "Set", |
| 278 | sensorInfo.sensorInterface); |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 279 | msg.append(interface->first); |
| 280 | msg.append(property.first); |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 281 | msg.append(*tmp); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 282 | |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 283 | auto rc = updateToDbus(msg); |
| 284 | if (rc) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 285 | { |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 286 | return rc; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | } |
Brad Bishop | 06a0abf | 2018-02-26 20:46:00 -0500 | [diff] [blame] | 290 | |
George Liu | e8a97bd | 2024-12-05 17:26:46 +0800 | [diff] [blame] | 291 | return ipmi::ccSuccess; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 292 | } |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 293 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 294 | } // namespace set |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 295 | |
| 296 | namespace notify |
| 297 | { |
| 298 | |
| 299 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 300 | const std::string&, const std::string& command, |
| 301 | const std::string&) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 302 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 303 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 304 | using namespace std::string_literals; |
| 305 | |
Dhruvaraj Subhashchandran | f915f85 | 2017-09-14 07:01:48 -0500 | [diff] [blame] | 306 | static const auto dbusPath = "/xyz/openbmc_project/inventory"s; |
| 307 | std::string dbusService = ipmi::getService(bus, updateInterface, dbusPath); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 308 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 309 | return bus.new_method_call(dbusService.c_str(), dbusPath.c_str(), |
| 310 | updateInterface.c_str(), command.c_str()); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 311 | } |
| 312 | |
George Liu | 23c868c | 2025-07-04 09:31:35 +0800 | [diff] [blame] | 313 | ipmi::Cc assertion(const SetSensorReadingReq& cmdData, const Info& sensorInfo) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 314 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 315 | auto msg = makeDbusMsg(sensorInfo.sensorInterface, sensorInfo.sensorPath, |
| 316 | "Notify", sensorInfo.sensorInterface); |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 317 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 318 | std::bitset<16> assertionSet(getAssertionSet(cmdData).first); |
| 319 | std::bitset<16> deassertionSet(getAssertionSet(cmdData).second); |
| 320 | ipmi::sensor::ObjectMap objects; |
| 321 | ipmi::sensor::InterfaceMap interfaces; |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 322 | for (const auto& interface : sensorInfo.propertyInterfaces) |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 323 | { |
Santosh Puranik | bbf8bd6 | 2019-05-01 19:02:52 +0530 | [diff] [blame] | 324 | // An interface with no properties - It is possible that the sensor |
| 325 | // object on DBUS implements a DBUS interface with no properties. |
| 326 | // Make sure we add the interface to the list if interfaces on the |
| 327 | // object with an empty property map. |
| 328 | if (interface.second.empty()) |
| 329 | { |
| 330 | interfaces.emplace(interface.first, ipmi::sensor::PropertyMap{}); |
| 331 | continue; |
| 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 | { |
George Liu | e8a97bd | 2024-12-05 17:26:46 +0800 | [diff] [blame] | 347 | return ipmi::ccSuccess; |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 348 | } |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 349 | result = result && std::get<bool>(value.second.assert); |
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 | { |
George Liu | e8a97bd | 2024-12-05 17:26:46 +0800 | [diff] [blame] | 357 | return ipmi::ccSuccess; |
Dhruvaraj Subhashchandran | e84841c | 2017-08-22 07:40:27 -0500 | [diff] [blame] | 358 | } |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 359 | result = result && std::get<bool>(value.second.deassert); |
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 | { |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 368 | result = result && std::get<bool>(value.second.assert); |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 369 | } |
| 370 | else if (deassertionSet.test(value.first)) |
| 371 | { |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 372 | result = result && std::get<bool>(value.second.deassert); |
Dhruvaraj Subhashchandran | e245e4e | 2017-10-03 03:58:05 -0500 | [diff] [blame] | 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 | |
Lei YU | ff8c9b4 | 2021-10-15 14:20:57 +0800 | [diff] [blame] | 396 | #ifndef FEATURE_SENSORS_CACHE |
| 397 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 398 | GetSensorResponse assertion(const Info& sensorInfo) |
| 399 | { |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 400 | namespace fs = std::filesystem; |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 401 | |
| 402 | fs::path path{ipmi::sensor::inventoryRoot}; |
| 403 | path += sensorInfo.sensorPath; |
| 404 | |
| 405 | return ipmi::sensor::get::mapDbusToAssertion( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 406 | sensorInfo, path.string(), |
| 407 | sensorInfo.propertyInterfaces.begin()->first); |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 408 | } |
| 409 | |
Lei YU | ff8c9b4 | 2021-10-15 14:20:57 +0800 | [diff] [blame] | 410 | #else |
| 411 | |
| 412 | std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo, |
Lei YU | 8e8152c | 2021-12-06 20:11:08 +0800 | [diff] [blame] | 413 | const PropertyMap& /*properties*/) |
Lei YU | ff8c9b4 | 2021-10-15 14:20:57 +0800 | [diff] [blame] | 414 | { |
Lei YU | ff8c9b4 | 2021-10-15 14:20:57 +0800 | [diff] [blame] | 415 | // The assertion may contain multiple properties |
| 416 | // So we have to get the properties from DBus anyway |
| 417 | namespace fs = std::filesystem; |
| 418 | |
| 419 | fs::path path{ipmi::sensor::inventoryRoot}; |
| 420 | path += sensorInfo.sensorPath; |
| 421 | |
| 422 | auto response = ipmi::sensor::get::mapDbusToAssertion( |
| 423 | sensorInfo, path.string(), |
| 424 | sensorInfo.propertyInterfaces.begin()->first); |
| 425 | |
| 426 | if (!sensorCacheMap[id].has_value()) |
| 427 | { |
| 428 | sensorCacheMap[id] = SensorData{}; |
| 429 | } |
| 430 | sensorCacheMap[id]->response = response; |
| 431 | return response; |
| 432 | } |
| 433 | |
| 434 | #endif |
| 435 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 436 | } // namespace get |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 437 | |
| 438 | } // namespace inventory |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 439 | } // namespace sensor |
| 440 | } // namespace ipmi |