Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 3 | #include "types.hpp" |
| 4 | #include "host-ipmid/ipmid-api.h" |
| 5 | |
| 6 | namespace ipmi |
| 7 | { |
| 8 | namespace sensor |
| 9 | { |
| 10 | |
| 11 | using Assertion = uint16_t; |
| 12 | using Deassertion = uint16_t; |
| 13 | using AssertionSet = std::pair<Assertion, Deassertion>; |
| 14 | |
| 15 | using Service = std::string; |
| 16 | using Path = std::string; |
| 17 | using Interface = std::string; |
| 18 | |
| 19 | using ServicePath = std::pair<Path, Service>; |
| 20 | |
| 21 | using Interfaces = std::vector<Interface>; |
| 22 | |
| 23 | using MapperResponseType = std::map<Path, std::map<Service, Interfaces>>; |
| 24 | |
| 25 | /** @brief get the D-Bus service and service path |
| 26 | * @param[in] bus - The Dbus bus object |
| 27 | * @param[in] interface - interface to the service |
| 28 | * @param[in] path - interested path in the list of objects |
| 29 | * @return pair of service path and service |
| 30 | */ |
| 31 | ServicePath getServiceAndPath(sdbusplus::bus::bus& bus, |
| 32 | const std::string& interface, |
| 33 | const std::string& path = std::string()); |
| 34 | |
| 35 | /** @brief Make assertion set from input data |
| 36 | * @param[in] cmdData - Input sensor data |
| 37 | * @return pair of assertion and deassertion set |
| 38 | */ |
| 39 | AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData); |
| 40 | |
| 41 | /** @brief send the message to DBus |
| 42 | * @param[in] msg - message to send |
| 43 | * @return failure status in IPMI error code |
| 44 | */ |
Dhruvaraj Subhashchandran | 2a444d0 | 2017-08-07 01:45:14 -0500 | [diff] [blame] | 45 | ipmi_ret_t updateToDbus(IpmiUpdateData& msg); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 46 | |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame^] | 47 | namespace get |
| 48 | { |
| 49 | |
| 50 | /** |
| 51 | * @brief Helper function to map the dbus info to sensor's assertion status |
| 52 | * for the get sensor reading command. |
| 53 | * |
| 54 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 55 | * @param[in] path - Dbus object path. |
| 56 | * @param[in] interface - Dbus interface. |
| 57 | * |
| 58 | * @return Response for get sensor reading command. |
| 59 | */ |
| 60 | GetSensorResponse mapDbusToAssertion(const Info& sensorInfo, |
| 61 | const InstancePath& path, |
| 62 | const DbusInterface& interface); |
| 63 | |
| 64 | /** |
| 65 | * @brief Map the Dbus info to sensor's assertion status in the Get sensor |
| 66 | * reading command response. |
| 67 | * |
| 68 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 69 | * |
| 70 | * @return Response for get sensor reading command. |
| 71 | */ |
| 72 | GetSensorResponse assertion(const Info& sensorInfo); |
| 73 | |
| 74 | } //namespace get |
| 75 | |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 76 | namespace set |
| 77 | { |
| 78 | |
| 79 | /** @brief Make a DBus message for a Dbus call |
| 80 | * @param[in] updateInterface - Interface name |
| 81 | * @param[in] sensorPath - Path of the sensor |
| 82 | * @param[in] command - command to be executed |
| 83 | * @param[in] sensorInterface - DBus interface of sensor |
| 84 | * @return a dbus message |
| 85 | */ |
| 86 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
| 87 | const std::string& sensorPath, |
| 88 | const std::string& command, |
| 89 | const std::string& sensorInterface); |
| 90 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 91 | /** @brief Update d-bus based on assertion type sensor data |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 92 | * @param[in] cmdData - input sensor data |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 93 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 94 | * @return a IPMI error code |
| 95 | */ |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 96 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, |
| 97 | const Info& sensorInfo); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 98 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 99 | /** @brief Update d-bus based on a reading assertion |
| 100 | * @tparam T - type of d-bus property mapping this sensor |
| 101 | * @param[in] cmdData - input sensor data |
| 102 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 103 | * @return a IPMI error code |
| 104 | */ |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 105 | template<typename T> |
| 106 | ipmi_ret_t readingAssertion(const SetSensorReadingReq& cmdData, |
| 107 | const Info& sensorInfo) |
| 108 | { |
| 109 | auto msg = makeDbusMsg( |
| 110 | "org.freedesktop.DBus.Properties", |
| 111 | sensorInfo.sensorPath, |
| 112 | "Set", |
| 113 | sensorInfo.sensorInterface); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 114 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 115 | const auto& interface = sensorInfo.propertyInterfaces.begin(); |
| 116 | msg.append(interface->first); |
| 117 | for (const auto& property : interface->second) |
| 118 | { |
| 119 | msg.append(property.first); |
| 120 | sdbusplus::message::variant<T> value = |
| 121 | (cmdData.assertOffset8_14 << 8) | cmdData.assertOffset0_7; |
| 122 | msg.append(value); |
| 123 | } |
| 124 | return updateToDbus(msg); |
| 125 | } |
| 126 | |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 127 | /** @brief Update d-bus based on a discrete reading |
| 128 | * @param[in] cmdData - input sensor data |
| 129 | * @param[in] sensorInfo - sensor d-bus info |
| 130 | * @return an IPMI error code |
| 131 | */ |
| 132 | template<typename T> |
| 133 | ipmi_ret_t readingData(const SetSensorReadingReq& cmdData, |
| 134 | const Info& sensorInfo) |
| 135 | { |
| 136 | auto msg = makeDbusMsg( |
| 137 | "org.freedesktop.DBus.Properties", |
| 138 | sensorInfo.sensorPath, |
| 139 | "Set", |
| 140 | sensorInfo.sensorInterface); |
| 141 | |
| 142 | const auto& interface = sensorInfo.propertyInterfaces.begin(); |
| 143 | msg.append(interface->first); |
| 144 | |
| 145 | ipmi::sensor::Multiplier m = sensorInfo.coefficientM; |
| 146 | if (0 == m) |
| 147 | { |
| 148 | m = 1; // Avoid * 0 |
| 149 | } |
| 150 | |
| 151 | // TODO: Refactor this into a generated function depending on the type |
| 152 | // of conversion for the value between IPMI and dbus. |
| 153 | T raw_value = (m * cmdData.reading) + sensorInfo.scaledOffset; |
| 154 | |
| 155 | for (const auto& property : interface->second) |
| 156 | { |
| 157 | msg.append(property.first); |
| 158 | sdbusplus::message::variant<T> value = raw_value; |
| 159 | msg.append(value); |
| 160 | } |
| 161 | return updateToDbus(msg); |
| 162 | } |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 163 | |
| 164 | /** @brief Update d-bus based on eventdata type sensor data |
| 165 | * @param[in] cmdData - input sensor data |
| 166 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 167 | * @return a IPMI error code |
| 168 | */ |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 169 | ipmi_ret_t eventdata(const SetSensorReadingReq& cmdData, |
| 170 | const Info& sensorInfo, |
| 171 | uint8_t data); |
| 172 | |
| 173 | /** @brief Update d-bus based on eventdata1 type sensor data |
| 174 | * @param[in] cmdData - input sensor data |
| 175 | * @param[in] sensorInfo - sensor d-bus info |
| 176 | * @return a IPMI error code |
| 177 | */ |
| 178 | inline ipmi_ret_t eventdata1(const SetSensorReadingReq& cmdData, |
| 179 | const Info& sensorInfo) |
| 180 | { |
| 181 | return eventdata(cmdData, sensorInfo, cmdData.eventData1); |
| 182 | } |
| 183 | |
| 184 | /** @brief Update d-bus based on eventdata2 type sensor data |
| 185 | * @param[in] cmdData - input sensor data |
| 186 | * @param[in] sensorInfo - sensor d-bus info |
| 187 | * @return a IPMI error code |
| 188 | */ |
| 189 | inline ipmi_ret_t eventdata2(const SetSensorReadingReq& cmdData, |
| 190 | const Info& sensorInfo) |
| 191 | { |
| 192 | return eventdata(cmdData, sensorInfo, cmdData.eventData2); |
| 193 | } |
| 194 | |
| 195 | /** @brief Update d-bus based on eventdata3 type sensor data |
| 196 | * @param[in] cmdData - input sensor data |
| 197 | * @param[in] sensorInfo - sensor d-bus info |
| 198 | * @return a IPMI error code |
| 199 | */ |
| 200 | inline ipmi_ret_t eventdata3(const SetSensorReadingReq& cmdData, |
| 201 | const Info& sensorInfo) |
| 202 | { |
| 203 | return eventdata(cmdData, sensorInfo, cmdData.eventData3); |
| 204 | } |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 205 | |
| 206 | }//namespace set |
| 207 | |
| 208 | namespace notify |
| 209 | { |
| 210 | |
| 211 | /** @brief Make a DBus message for a Dbus call |
| 212 | * @param[in] updateInterface - Interface name |
| 213 | * @param[in] sensorPath - Path of the sensor |
| 214 | * @param[in] command - command to be executed |
| 215 | * @param[in] sensorInterface - DBus interface of sensor |
| 216 | * @return a dbus message |
| 217 | */ |
| 218 | IpmiUpdateData makeDbusMsg(const std::string& updateInterface, |
| 219 | const std::string& sensorPath, |
| 220 | const std::string& command, |
| 221 | const std::string& sensorInterface); |
| 222 | |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 223 | /** @brief Update d-bus based on assertion type sensor data |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 224 | * @param[in] interfaceMap - sensor interface |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 225 | * @param[in] cmdData - input sensor data |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 226 | * @param[in] sensorInfo - sensor d-bus info |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 227 | * @return a IPMI error code |
| 228 | */ |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 229 | ipmi_ret_t assertion(const SetSensorReadingReq& cmdData, |
| 230 | const Info& sensorInfo); |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 231 | |
| 232 | }//namespace notify |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame^] | 233 | |
| 234 | namespace inventory |
| 235 | { |
| 236 | |
| 237 | namespace get |
| 238 | { |
| 239 | |
| 240 | /** |
| 241 | * @brief Map the Dbus info to sensor's assertion status in the Get sensor |
| 242 | * reading command response. |
| 243 | * |
| 244 | * @param[in] sensorInfo - Dbus info related to sensor. |
| 245 | * |
| 246 | * @return Response for get sensor reading command. |
| 247 | */ |
| 248 | GetSensorResponse assertion(const Info& sensorInfo); |
| 249 | |
| 250 | } // namespace get |
| 251 | |
| 252 | } // namespace inventory |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 253 | }//namespace sensor |
| 254 | }//namespace ipmi |