Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
| 5 | #include "org/openbmc/Associations/server.hpp" |
| 6 | #include "xyz/openbmc_project/Software/ActivationProgress/server.hpp" |
| 7 | #include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp" |
| 8 | #include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp" |
| 9 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 10 | #include <sdbusplus/server.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 13 | |
| 14 | namespace openpower |
| 15 | { |
| 16 | namespace software |
| 17 | { |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 18 | namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 19 | { |
| 20 | |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 21 | using AssociationList = |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 22 | std::vector<std::tuple<std::string, std::string, std::string>>; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 23 | using ActivationInherit = sdbusplus::server::object::object< |
Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 24 | sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, |
Saqib Khan | c350c61 | 2017-08-13 13:36:44 -0500 | [diff] [blame] | 25 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
| 26 | sdbusplus::org::openbmc::server::Associations>; |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 27 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 28 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 29 | ActivationBlocksTransition>; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 30 | using RedundancyPriorityInherit = sdbusplus::server::object::object< |
| 31 | sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 32 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 33 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 34 | |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 35 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 36 | |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 37 | class ItemUpdater; |
| 38 | class Activation; |
| 39 | class RedundancyPriority; |
| 40 | |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 41 | /** @class RedundancyPriority |
| 42 | * @brief OpenBMC RedundancyPriority implementation |
| 43 | * @details A concrete implementation for |
| 44 | * xyz.openbmc_project.Software.RedundancyPriority DBus API. |
| 45 | */ |
| 46 | class RedundancyPriority : public RedundancyPriorityInherit |
| 47 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 48 | public: |
| 49 | /** @brief Constructs RedundancyPriority. |
| 50 | * |
| 51 | * @param[in] bus - The Dbus bus object |
| 52 | * @param[in] path - The Dbus object path |
| 53 | * @param[in] parent - Parent object. |
| 54 | * @param[in] value - The redundancyPriority value |
| 55 | */ |
| 56 | RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path, |
| 57 | Activation& parent, uint8_t value) : |
| 58 | RedundancyPriorityInherit(bus, path.c_str(), true), |
| 59 | parent(parent), bus(bus), path(path) |
| 60 | { |
| 61 | // Set Property |
| 62 | priority(value); |
| 63 | std::vector<std::string> interfaces({interface}); |
| 64 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 65 | } |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 66 | |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 67 | virtual ~RedundancyPriority() |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 68 | { |
| 69 | std::vector<std::string> interfaces({interface}); |
| 70 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 71 | } |
Saqib Khan | 2021b4c | 2017-06-07 14:37:36 -0500 | [diff] [blame] | 72 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 73 | /** @brief Overloaded Priority property set function |
| 74 | * |
| 75 | * @param[in] value - uint8_t |
| 76 | * |
| 77 | * @return Success or exception thrown |
| 78 | */ |
| 79 | uint8_t priority(uint8_t value) override; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 80 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 81 | /** @brief Priority property get function |
| 82 | * |
| 83 | * @returns uint8_t - The Priority value |
| 84 | */ |
| 85 | using RedundancyPriorityInherit::priority; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 86 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 87 | /** @brief Parent Object. */ |
| 88 | Activation& parent; |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 89 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 90 | private: |
| 91 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 92 | static constexpr auto interface = |
| 93 | "xyz.openbmc_project.Software.RedundancyPriority"; |
| 94 | sdbusplus::bus::bus& bus; |
| 95 | std::string path; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 96 | }; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 97 | |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 98 | /** @class ActivationBlocksTransition |
| 99 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 100 | * @details A concrete implementation for |
| 101 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 102 | */ |
| 103 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 104 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 105 | public: |
| 106 | /** @brief Constructs ActivationBlocksTransition. |
| 107 | * |
| 108 | * @param[in] bus - The Dbus bus object |
| 109 | * @param[in] path - The Dbus object path |
| 110 | */ |
| 111 | ActivationBlocksTransition(sdbusplus::bus::bus& bus, |
| 112 | const std::string& path) : |
| 113 | ActivationBlocksTransitionInherit(bus, path.c_str(), true), |
| 114 | bus(bus), path(path) |
| 115 | { |
| 116 | std::vector<std::string> interfaces({interface}); |
| 117 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 118 | } |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 119 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 120 | ~ActivationBlocksTransition() |
| 121 | { |
| 122 | std::vector<std::string> interfaces({interface}); |
| 123 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 124 | } |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 125 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 126 | private: |
| 127 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 128 | static constexpr auto interface = |
| 129 | "xyz.openbmc_project.Software.ActivationBlocksTransition"; |
| 130 | sdbusplus::bus::bus& bus; |
| 131 | std::string path; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 132 | }; |
| 133 | |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 134 | class ActivationProgress : public ActivationProgressInherit |
| 135 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 136 | public: |
| 137 | /** @brief Constructs ActivationProgress. |
| 138 | * |
| 139 | * @param[in] bus - The Dbus bus object |
| 140 | * @param[in] path - The Dbus object path |
| 141 | */ |
| 142 | ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) : |
| 143 | ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path) |
| 144 | { |
| 145 | progress(0); |
| 146 | std::vector<std::string> interfaces({interface}); |
| 147 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 148 | } |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 149 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 150 | ~ActivationProgress() |
| 151 | { |
| 152 | std::vector<std::string> interfaces({interface}); |
| 153 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 154 | } |
Adriana Kobylak | a8eda56 | 2017-07-17 15:24:29 -0500 | [diff] [blame] | 155 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 156 | private: |
| 157 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 158 | static constexpr auto interface = |
| 159 | "xyz.openbmc_project.Software.ActivationProgress"; |
| 160 | sdbusplus::bus::bus& bus; |
| 161 | std::string path; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 162 | }; |
| 163 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 164 | /** @class Activation |
| 165 | * @brief OpenBMC activation software management implementation. |
| 166 | * @details A concrete implementation for |
| 167 | * xyz.openbmc_project.Software.Activation DBus API. |
| 168 | */ |
| 169 | class Activation : public ActivationInherit |
| 170 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 171 | public: |
| 172 | /** @brief Constructs Activation Software Manager |
| 173 | * |
| 174 | * @param[in] bus - The Dbus bus object |
| 175 | * @param[in] path - The Dbus object path |
| 176 | * @param[in] parent - Parent object. |
| 177 | * @param[in] versionId - The software version id |
| 178 | * @param[in] extVersion - The extended version |
| 179 | * @param[in] activationStatus - The status of Activation |
| 180 | * @param[in] assocs - Association objects |
| 181 | */ |
| 182 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
| 183 | ItemUpdater& parent, std::string& versionId, |
| 184 | std::string& extVersion, |
| 185 | sdbusplus::xyz::openbmc_project::Software::server::Activation:: |
| 186 | Activations activationStatus, |
| 187 | AssociationList& assocs) : |
| 188 | ActivationInherit(bus, path.c_str(), true), |
| 189 | bus(bus), path(path), parent(parent), versionId(versionId), |
| 190 | systemdSignals( |
| 191 | bus, |
| 192 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 193 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 194 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
| 195 | std::bind(std::mem_fn(&Activation::unitStateChange), this, |
| 196 | std::placeholders::_1)) |
| 197 | { |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 198 | // Set Properties. |
| 199 | extendedVersion(extVersion); |
| 200 | activation(activationStatus); |
| 201 | associations(assocs); |
Gunnar Mills | 3edb84b | 2017-08-18 15:13:15 -0500 | [diff] [blame] | 202 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 203 | // Emit deferred signal. |
| 204 | emit_object_added(); |
| 205 | } |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 206 | virtual ~Activation() = default; |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 207 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 208 | /** @brief Activation property get function |
| 209 | * |
| 210 | * @returns One of Activation::Activations |
| 211 | */ |
| 212 | using ActivationInherit::activation; |
Saqib Khan | 2cbfa03 | 2017-08-17 14:52:37 -0500 | [diff] [blame] | 213 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 214 | /** @brief Overloaded requestedActivation property setter function |
| 215 | * |
| 216 | * @param[in] value - One of Activation::RequestedActivations |
| 217 | * |
| 218 | * @return Success or exception thrown |
| 219 | */ |
| 220 | RequestedActivations |
| 221 | requestedActivation(RequestedActivations value) override; |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 222 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 223 | /** |
| 224 | * @brief subscribe to the systemd signals |
| 225 | * |
| 226 | * This object needs to capture when it's systemd targets complete |
| 227 | * so it can keep it's state updated |
| 228 | * |
| 229 | **/ |
| 230 | void subscribeToSystemdSignals(); |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 231 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 232 | /** |
| 233 | * @brief unsubscribe from the systemd signals |
| 234 | * |
| 235 | * Once the activation process has completed successfully, we can |
| 236 | * safely unsubscribe from systemd signals. |
| 237 | * |
| 238 | **/ |
| 239 | void unsubscribeFromSystemdSignals(); |
Michael Tritz | 1cb127f | 2017-07-26 15:40:38 -0500 | [diff] [blame] | 240 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 241 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 242 | sdbusplus::bus::bus& bus; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 243 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 244 | /** @brief Persistent DBus object path */ |
| 245 | std::string path; |
Adriana Kobylak | 99c8c0e | 2017-04-17 13:39:11 -0500 | [diff] [blame] | 246 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 247 | /** @brief Parent Object. */ |
| 248 | ItemUpdater& parent; |
Saqib Khan | 81bac88 | 2017-06-08 12:17:01 -0500 | [diff] [blame] | 249 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 250 | /** @brief Version id */ |
| 251 | std::string versionId; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 252 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 253 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 254 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Saqib Khan | 942df8a | 2017-06-01 14:09:27 -0500 | [diff] [blame] | 255 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 256 | /** @brief Persistent ActivationProgress dbus object */ |
| 257 | std::unique_ptr<ActivationProgress> activationProgress; |
Michael Tritz | 1793b64 | 2017-06-28 18:35:58 -0500 | [diff] [blame] | 258 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 259 | /** @brief Persistent RedundancyPriority dbus object */ |
| 260 | std::unique_ptr<RedundancyPriority> redundancyPriority; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 261 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 262 | /** @brief Used to subscribe to dbus systemd signals **/ |
| 263 | sdbusplus::bus::match_t systemdSignals; |
Michael Tritz | 9d25b60 | 2017-06-14 14:41:43 -0500 | [diff] [blame] | 264 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 265 | /** @brief activation status property get function |
| 266 | * |
| 267 | * @returns Activations - The activation value |
| 268 | */ |
| 269 | using ActivationInherit::activation; |
Leonel Gonzalez | 9c8adfa | 2017-07-12 11:08:40 -0500 | [diff] [blame] | 270 | |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 271 | protected: |
| 272 | /** @brief Check if systemd state change is relevant to this object |
| 273 | * |
| 274 | * Instance specific interface to handle the detected systemd state |
| 275 | * change |
| 276 | * |
| 277 | * @param[in] msg - Data associated with subscribed signal |
| 278 | * |
| 279 | */ |
| 280 | virtual void unitStateChange(sdbusplus::message::message& msg) = 0; |
| 281 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 282 | /** |
| 283 | * @brief Deletes the version from Image Manager and the |
| 284 | * untar image from image upload dir. |
| 285 | */ |
| 286 | void deleteImageManagerObject(); |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 287 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 288 | /** @brief Member function for clarity & brevity at activation start */ |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 289 | virtual void startActivation() = 0; |
Saqib Khan | 7f80e0b | 2017-10-22 11:29:07 -0500 | [diff] [blame] | 290 | |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 291 | /** @brief Member function for clarity & brevity at activation end */ |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 292 | virtual void finishActivation() = 0; |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 293 | |
| 294 | #ifdef WANT_SIGNATURE_VERIFY |
| 295 | /** |
| 296 | * @brief Wrapper function for the signature verify function. |
| 297 | * Signature class verify function used for validating |
| 298 | * signed image. Also added additional logic to continue |
| 299 | * update process in lab environment by checking the |
| 300 | * fieldModeEnabled property. |
| 301 | * |
| 302 | * @return true if successful signature validation or field |
| 303 | * mode is disabled. |
| 304 | * false for unsuccessful signature validation or |
| 305 | * any internal failure during the mapper call. |
| 306 | */ |
Lei YU | 9b21efc | 2019-02-21 15:52:53 +0800 | [diff] [blame] | 307 | bool validateSignature(); |
Jayanth Othayoth | 11271fb | 2018-03-29 10:25:50 -0500 | [diff] [blame] | 308 | |
| 309 | /** |
| 310 | * @brief Gets the fieldModeEnabled property value. |
| 311 | * |
| 312 | * @return fieldModeEnabled property value |
| 313 | * @error InternalFailure exception thrown |
| 314 | */ |
| 315 | bool fieldModeEnabled(); |
| 316 | |
| 317 | /** |
| 318 | * @brief Gets the D-Bus Service name for the input D-Bus path |
| 319 | * |
| 320 | * @param[in] bus - Bus handler |
| 321 | * @param[in] path - Object Path |
| 322 | * @param[in] intf - Interface |
| 323 | * |
| 324 | * @return Service name |
| 325 | * @error InternalFailure exception thrown |
| 326 | */ |
| 327 | std::string getService(sdbusplus::bus::bus& bus, const std::string& path, |
| 328 | const std::string& intf); |
| 329 | #endif |
Adriana Kobylak | ea9626f | 2017-04-05 15:37:40 -0500 | [diff] [blame] | 330 | }; |
| 331 | |
Adriana Kobylak | befe5ce | 2017-04-05 15:57:44 -0500 | [diff] [blame] | 332 | } // namespace updater |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 333 | } // namespace software |
| 334 | } // namespace openpower |