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