Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Brandon Kim | 9cf8562 | 2019-06-19 12:05:08 -0700 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 5 | #include "sensorhandler.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 6 | |
Patrick Venture | 586d35b | 2018-09-07 19:56:18 -0700 | [diff] [blame] | 7 | #include <cmath> |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 8 | #include <ipmid/api.hpp> |
Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 9 | #include <ipmid/types.hpp> |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 10 | #include <ipmid/utils.hpp> |
Tony Lee | c532425 | 2019-10-31 17:24:16 +0800 | [diff] [blame] | 11 | #include <phosphor-logging/elog-errors.hpp> |
| 12 | #include <phosphor-logging/log.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 13 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 14 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 15 | namespace ipmi |
| 16 | { |
| 17 | namespace sensor |
| 18 | { |
| 19 | |
| 20 | using Assertion = uint16_t; |
| 21 | using Deassertion = uint16_t; |
| 22 | using AssertionSet = std::pair<Assertion, Deassertion>; |
| 23 | |
| 24 | using Service = std::string; |
| 25 | using Path = std::string; |
| 26 | using Interface = std::string; |
| 27 | |
| 28 | using ServicePath = std::pair<Path, Service>; |
| 29 | |
| 30 | using Interfaces = std::vector<Interface>; |
| 31 | |
| 32 | using MapperResponseType = std::map<Path, std::map<Service, Interfaces>>; |
Tony Lee | c532425 | 2019-10-31 17:24:16 +0800 | [diff] [blame] | 33 | using namespace phosphor::logging; |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 34 | |
| 35 | /** @brief get the D-Bus service and service path |
| 36 | * @param[in] bus - The Dbus bus object |
| 37 | * @param[in] interface - interface to the service |
| 38 | * @param[in] path - interested path in the list of objects |
| 39 | * @return pair of service path and service |
| 40 | */ |
| 41 | ServicePath getServiceAndPath(sdbusplus::bus::bus& bus, |
| 42 | const std::string& interface, |
| 43 | const std::string& path = std::string()); |
| 44 | |
| 45 | /** @brief Make assertion set from input data |
| 46 | * @param[in] cmdData - Input sensor data |
| 47 | * @return pair of assertion and deassertion set |
| 48 | */ |
| 49 | AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData); |
| 50 | |
| 51 | /** @brief send the message to DBus |
| 52 | * @param[in] msg - message to send |
| 53 | * @return failure status in IPMI error code |
| 54 | */ |
Dhruvaraj Subhashchandran | 2a444d0 | 2017-08-07 01:45:14 -0500 | [diff] [blame] | 55 | ipmi_ret_t updateToDbus(IpmiUpdateData& msg); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 56 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 57 | namespace get |
| 58 | { |
| 59 | |
Tom Joseph | b0adbcd | 2018-01-24 11:51:29 +0530 | [diff] [blame] | 60 | /** @brief Populate sensor name from the D-Bus property associated with the |
| 61 | * sensor. In the example entry from the yaml, the name of the D-bus |
| 62 | * property "AttemptsLeft" is the sensor name. |
| 63 | * |
| 64 | * 0x07: |
| 65 | * sensorType: 195 |
| 66 | * path: /xyz/openbmc_project/state/host0 |
| 67 | * sensorReadingType: 0x6F |
| 68 | * serviceInterface: org.freedesktop.DBus.Properties |
| 69 | * readingType: readingAssertion |
| 70 | * sensorNamePattern: nameProperty |
| 71 | * interfaces: |
| 72 | * xyz.openbmc_project.Control.Boot.RebootAttempts: |
| 73 | * AttemptsLeft: |
| 74 | * Offsets: |
| 75 | * 0xFF: |
| 76 | * type: uint32_t |
| 77 | * |
| 78 | * |
| 79 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 80 | * |
| 81 | * @return On success return the sensor name for the sensor. |
| 82 | */ |
| 83 | inline SensorName nameProperty(const Info& sensorInfo) |
| 84 | { |
| 85 | return sensorInfo.propertyInterfaces.begin()->second.begin()->first; |
| 86 | } |
| 87 | |
| 88 | /** @brief Populate sensor name from the D-Bus object associated with the |
| 89 | * sensor. If the object path is /system/chassis/motherboard/dimm0 then |
| 90 | * the leaf dimm0 is considered as the sensor name. |
| 91 | * |
| 92 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 93 | * |
| 94 | * @return On success return the sensor name for the sensor. |
| 95 | */ |
| 96 | inline SensorName nameLeaf(const Info& sensorInfo) |
| 97 | { |
| 98 | return sensorInfo.sensorPath.substr( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 99 | sensorInfo.sensorPath.find_last_of('/') + 1, |
| 100 | sensorInfo.sensorPath.length()); |
Tom Joseph | b0adbcd | 2018-01-24 11:51:29 +0530 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** @brief Populate sensor name from the D-Bus object associated with the |
Lotus Xu | 2101a44 | 2020-12-24 16:01:56 +0800 | [diff] [blame] | 104 | * sensor and the property. |
| 105 | * If the object path is /xyz/openbmc_project/inventory/Fan0 and |
| 106 | * the property is Present, the leaf Fan0 and the Property is |
| 107 | * joined to Fan0_Present as the sensor name. |
| 108 | * |
| 109 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 110 | * |
| 111 | * @return On success return the sensor name for the sensor. |
| 112 | */ |
| 113 | inline SensorName nameLeafProperty(const Info& sensorInfo) |
| 114 | { |
| 115 | return nameLeaf(sensorInfo) + "_" + nameProperty(sensorInfo); |
| 116 | } |
| 117 | |
| 118 | /** @brief Populate sensor name from the D-Bus object associated with the |
Tom Joseph | b0adbcd | 2018-01-24 11:51:29 +0530 | [diff] [blame] | 119 | * sensor. If the object path is /system/chassis/motherboard/cpu0/core0 |
| 120 | * then the sensor name is cpu0_core0. The leaf and the parent is put |
| 121 | * together to get the sensor name. |
| 122 | * |
| 123 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 124 | * |
| 125 | * @return On success return the sensor name for the sensor. |
| 126 | */ |
| 127 | SensorName nameParentLeaf(const Info& sensorInfo); |
| 128 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 129 | /** |
| 130 | * @brief Helper function to map the dbus info to sensor's assertion status |
| 131 | * for the get sensor reading command. |
| 132 | * |
| 133 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 134 | * @param[in] path - Dbus object path. |
| 135 | * @param[in] interface - Dbus interface. |
| 136 | * |
| 137 | * @return Response for get sensor reading command. |
| 138 | */ |
| 139 | GetSensorResponse mapDbusToAssertion(const Info& sensorInfo, |
| 140 | const InstancePath& path, |
| 141 | const DbusInterface& interface); |
| 142 | |
| 143 | /** |
| 144 | * @brief Map the Dbus info to sensor's assertion status in the Get sensor |
| 145 | * reading command response. |
| 146 | * |
| 147 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 148 | * |
| 149 | * @return Response for get sensor reading command. |
| 150 | */ |
| 151 | GetSensorResponse assertion(const Info& sensorInfo); |
| 152 | |
Tom Joseph | e4014fc | 2017-09-06 23:57:36 +0530 | [diff] [blame] | 153 | /** |
| 154 | * @brief Maps the Dbus info to the reading field in the Get sensor reading |
| 155 | * command response. |
| 156 | * |
| 157 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 158 | * |
| 159 | * @return Response for get sensor reading command. |
| 160 | */ |
| 161 | GetSensorResponse eventdata2(const Info& sensorInfo); |
| 162 | |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 163 | /** |
| 164 | * @brief readingAssertion is a case where the entire assertion state field |
| 165 | * serves as the sensor value. |
| 166 | * |
| 167 | * @tparam T - type of the dbus property related to sensor. |
| 168 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 169 | * |
| 170 | * @return Response for get sensor reading command. |
| 171 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 172 | template <typename T> |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 173 | GetSensorResponse readingAssertion(const Info& sensorInfo) |
| 174 | { |
| 175 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 176 | GetSensorResponse response{}; |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 177 | |
Jeremy Kerr | 3dc3558 | 2020-05-17 15:47:07 +0800 | [diff] [blame] | 178 | enableScanning(&response); |
| 179 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 180 | auto service = ipmi::getService(bus, sensorInfo.sensorInterface, |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 181 | sensorInfo.sensorPath); |
| 182 | |
| 183 | auto propValue = ipmi::getDbusProperty( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 184 | bus, service, sensorInfo.sensorPath, |
| 185 | sensorInfo.propertyInterfaces.begin()->first, |
| 186 | sensorInfo.propertyInterfaces.begin()->second.begin()->first); |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 187 | |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 188 | setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)), &response); |
Tom Joseph | 295f17e | 2017-09-07 00:09:46 +0530 | [diff] [blame] | 189 | |
| 190 | return response; |
| 191 | } |
| 192 | |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 193 | /** @brief Map the Dbus info to the reading field in the Get sensor reading |
| 194 | * command response |
| 195 | * |
| 196 | * @tparam T - type of the dbus property related to sensor. |
| 197 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 198 | * |
| 199 | * @return Response for get sensor reading command. |
| 200 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 201 | template <typename T> |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 202 | GetSensorResponse readingData(const Info& sensorInfo) |
| 203 | { |
| 204 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 205 | |
Sui Chen | 4cc4255 | 2019-09-11 10:28:35 -0700 | [diff] [blame] | 206 | GetSensorResponse response{}; |
| 207 | |
| 208 | enableScanning(&response); |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 209 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 210 | auto service = ipmi::getService(bus, sensorInfo.sensorInterface, |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 211 | sensorInfo.sensorPath); |
| 212 | |
Brandon Kim | 9cf8562 | 2019-06-19 12:05:08 -0700 | [diff] [blame] | 213 | #ifdef UPDATE_FUNCTIONAL_ON_FAIL |
| 214 | // Check the OperationalStatus interface for functional property |
| 215 | if (sensorInfo.propertyInterfaces.begin()->first == |
| 216 | "xyz.openbmc_project.Sensor.Value") |
| 217 | { |
| 218 | bool functional = true; |
| 219 | try |
| 220 | { |
| 221 | auto funcValue = ipmi::getDbusProperty( |
| 222 | bus, service, sensorInfo.sensorPath, |
| 223 | "xyz.openbmc_project.State.Decorator.OperationalStatus", |
| 224 | "Functional"); |
| 225 | functional = std::get<bool>(funcValue); |
| 226 | } |
| 227 | catch (...) |
| 228 | { |
| 229 | // No-op if Functional property could not be found since this |
| 230 | // check is only valid for Sensor.Value read for hwmonio |
| 231 | } |
| 232 | if (!functional) |
| 233 | { |
| 234 | throw SensorFunctionalError(); |
| 235 | } |
| 236 | } |
| 237 | #endif |
| 238 | |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 239 | auto propValue = ipmi::getDbusProperty( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 240 | bus, service, sensorInfo.sensorPath, |
| 241 | sensorInfo.propertyInterfaces.begin()->first, |
| 242 | sensorInfo.propertyInterfaces.begin()->second.begin()->first); |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 243 | |
Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 244 | double value = std::get<T>(propValue) * |
Patrick Venture | 586d35b | 2018-09-07 19:56:18 -0700 | [diff] [blame] | 245 | std::pow(10, sensorInfo.scale - sensorInfo.exponentR); |
Tony Lee | c532425 | 2019-10-31 17:24:16 +0800 | [diff] [blame] | 246 | int32_t rawData = |
| 247 | (value - sensorInfo.scaledOffset) / sensorInfo.coefficientM; |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 248 | |
Tony Lee | c532425 | 2019-10-31 17:24:16 +0800 | [diff] [blame] | 249 | constexpr uint8_t sensorUnitsSignedBits = 2 << 6; |
| 250 | constexpr uint8_t signedDataFormat = 0x80; |
| 251 | // if sensorUnits1 [7:6] = 10b, sensor is signed |
| 252 | if ((sensorInfo.sensorUnits1 & sensorUnitsSignedBits) == signedDataFormat) |
| 253 | { |
| 254 | if (rawData > std::numeric_limits<int8_t>::max() || |
| 255 | rawData < std::numeric_limits<int8_t>::lowest()) |
| 256 | { |
| 257 | log<level::ERR>("Value out of range"); |
| 258 | throw std::out_of_range("Value out of range"); |
| 259 | } |
| 260 | setReading(static_cast<int8_t>(rawData), &response); |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | if (rawData > std::numeric_limits<uint8_t>::max() || |
| 265 | rawData < std::numeric_limits<uint8_t>::lowest()) |
| 266 | { |
| 267 | log<level::ERR>("Value out of range"); |
| 268 | throw std::out_of_range("Value out of range"); |
| 269 | } |
| 270 | setReading(static_cast<uint8_t>(rawData), &response); |
| 271 | } |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 272 | |
Konstantin Aladyshev | f93b29c | 2021-05-05 14:49:14 +0300 | [diff] [blame] | 273 | if (!std::isfinite(value)) |
| 274 | { |
| 275 | response.readingOrStateUnavailable = 1; |
| 276 | } |
| 277 | |
Tom Joseph | e05b292 | 2017-09-07 00:43:16 +0530 | [diff] [blame] | 278 | return response; |
| 279 | } |
| 280 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 281 | } // namespace get |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 282 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 283 | namespace set |
| 284 | { |
| 285 | |
| 286 | /** @brief Make a DBus message for a Dbus call |
| 287 | * @param[in] updateInterface - Interface name |
| 288 | * @param[in] sensorPath - Path of the sensor |
| 289 | * @param[in] command - command to be executed |
| 290 | * @param[in] sensorInterface - DBus interface of sensor |
| 291 | * @return a dbus message |
| 292 | */ |
| 293 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
| 294 | const std::string& sensorPath, |
| 295 | const std::string& command, |
| 296 | const std::string& sensorInterface); |
| 297 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 298 | /** @brief Update d-bus based on assertion type sensor data |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 299 | * @param[in] cmdData - input sensor data |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 300 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 301 | * @return a IPMI error code |
| 302 | */ |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 303 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, |
| 304 | const Info& sensorInfo); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 305 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 306 | /** @brief Update d-bus based on a reading assertion |
| 307 | * @tparam T - type of d-bus property mapping this sensor |
| 308 | * @param[in] cmdData - input sensor data |
| 309 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 310 | * @return a IPMI error code |
| 311 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 312 | template <typename T> |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 313 | ipmi_ret_t readingAssertion(const SetSensorReadingReq& cmdData, |
| 314 | const Info& sensorInfo) |
| 315 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 316 | auto msg = |
| 317 | makeDbusMsg("org.freedesktop.DBus.Properties", sensorInfo.sensorPath, |
| 318 | "Set", sensorInfo.sensorInterface); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 319 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 320 | const auto& interface = sensorInfo.propertyInterfaces.begin(); |
| 321 | msg.append(interface->first); |
| 322 | for (const auto& property : interface->second) |
| 323 | { |
| 324 | msg.append(property.first); |
Andrew Geissler | 6467ed2 | 2020-05-16 16:03:53 -0500 | [diff] [blame] | 325 | std::variant<T> value = static_cast<T>((cmdData.assertOffset8_14 << 8) | |
| 326 | cmdData.assertOffset0_7); |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 327 | msg.append(value); |
| 328 | } |
| 329 | return updateToDbus(msg); |
| 330 | } |
| 331 | |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 332 | /** @brief Update d-bus based on a discrete reading |
| 333 | * @param[in] cmdData - input sensor data |
| 334 | * @param[in] sensorInfo - sensor d-bus info |
| 335 | * @return an IPMI error code |
| 336 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 337 | template <typename T> |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 338 | ipmi_ret_t readingData(const SetSensorReadingReq& cmdData, |
| 339 | const Info& sensorInfo) |
| 340 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 341 | T raw_value = |
| 342 | (sensorInfo.coefficientM * cmdData.reading) + sensorInfo.scaledOffset; |
Tom Joseph | 2210215 | 2018-03-02 18:46:39 +0530 | [diff] [blame] | 343 | |
Patrick Venture | 586d35b | 2018-09-07 19:56:18 -0700 | [diff] [blame] | 344 | raw_value *= std::pow(10, sensorInfo.exponentR - sensorInfo.scale); |
Tom Joseph | 2210215 | 2018-03-02 18:46:39 +0530 | [diff] [blame] | 345 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 346 | auto msg = |
| 347 | makeDbusMsg("org.freedesktop.DBus.Properties", sensorInfo.sensorPath, |
| 348 | "Set", sensorInfo.sensorInterface); |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 349 | |
| 350 | const auto& interface = sensorInfo.propertyInterfaces.begin(); |
| 351 | msg.append(interface->first); |
| 352 | |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 353 | for (const auto& property : interface->second) |
| 354 | { |
| 355 | msg.append(property.first); |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 356 | std::variant<T> value = raw_value; |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 357 | msg.append(value); |
| 358 | } |
| 359 | return updateToDbus(msg); |
| 360 | } |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 361 | |
| 362 | /** @brief Update d-bus based on eventdata type sensor data |
| 363 | * @param[in] cmdData - input sensor data |
| 364 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 365 | * @return a IPMI error code |
| 366 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 367 | ipmi_ret_t eventdata(const SetSensorReadingReq& cmdData, const Info& sensorInfo, |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 368 | uint8_t data); |
| 369 | |
| 370 | /** @brief Update d-bus based on eventdata1 type sensor data |
| 371 | * @param[in] cmdData - input sensor data |
| 372 | * @param[in] sensorInfo - sensor d-bus info |
| 373 | * @return a IPMI error code |
| 374 | */ |
| 375 | inline ipmi_ret_t eventdata1(const SetSensorReadingReq& cmdData, |
| 376 | const Info& sensorInfo) |
| 377 | { |
| 378 | return eventdata(cmdData, sensorInfo, cmdData.eventData1); |
| 379 | } |
| 380 | |
| 381 | /** @brief Update d-bus based on eventdata2 type sensor data |
| 382 | * @param[in] cmdData - input sensor data |
| 383 | * @param[in] sensorInfo - sensor d-bus info |
| 384 | * @return a IPMI error code |
| 385 | */ |
| 386 | inline ipmi_ret_t eventdata2(const SetSensorReadingReq& cmdData, |
| 387 | const Info& sensorInfo) |
| 388 | { |
| 389 | return eventdata(cmdData, sensorInfo, cmdData.eventData2); |
| 390 | } |
| 391 | |
| 392 | /** @brief Update d-bus based on eventdata3 type sensor data |
| 393 | * @param[in] cmdData - input sensor data |
| 394 | * @param[in] sensorInfo - sensor d-bus info |
| 395 | * @return a IPMI error code |
| 396 | */ |
| 397 | inline ipmi_ret_t eventdata3(const SetSensorReadingReq& cmdData, |
| 398 | const Info& sensorInfo) |
| 399 | { |
| 400 | return eventdata(cmdData, sensorInfo, cmdData.eventData3); |
| 401 | } |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 402 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 403 | } // namespace set |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 404 | |
| 405 | namespace notify |
| 406 | { |
| 407 | |
| 408 | /** @brief Make a DBus message for a Dbus call |
| 409 | * @param[in] updateInterface - Interface name |
| 410 | * @param[in] sensorPath - Path of the sensor |
| 411 | * @param[in] command - command to be executed |
| 412 | * @param[in] sensorInterface - DBus interface of sensor |
| 413 | * @return a dbus message |
| 414 | */ |
| 415 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
| 416 | const std::string& sensorPath, |
| 417 | const std::string& command, |
| 418 | const std::string& sensorInterface); |
| 419 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 420 | /** @brief Update d-bus based on assertion type sensor data |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 421 | * @param[in] interfaceMap - sensor interface |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 422 | * @param[in] cmdData - input sensor data |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 423 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 424 | * @return a IPMI error code |
| 425 | */ |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 426 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, |
| 427 | const Info& sensorInfo); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 428 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 429 | } // namespace notify |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 430 | |
| 431 | namespace inventory |
| 432 | { |
| 433 | |
| 434 | namespace get |
| 435 | { |
| 436 | |
| 437 | /** |
| 438 | * @brief Map the Dbus info to sensor's assertion status in the Get sensor |
| 439 | * reading command response. |
| 440 | * |
| 441 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 442 | * |
| 443 | * @return Response for get sensor reading command. |
| 444 | */ |
| 445 | GetSensorResponse assertion(const Info& sensorInfo); |
| 446 | |
| 447 | } // namespace get |
| 448 | |
| 449 | } // namespace inventory |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 450 | } // namespace sensor |
| 451 | } // namespace ipmi |