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