blob: 237a662491efbcc8302451f510d2f229ac0f9ae7 [file] [log] [blame]
Sampa Misraaea5dde2020-08-31 08:33:47 -05001#pragma once
2
3#include "common/utils.hpp"
4#include "libpldmresponder/platform.hpp"
5
6#include <string>
7
8using namespace pldm::utils;
9namespace pldm
10{
11namespace responder
12{
13
14static constexpr uint8_t pSideNum = 1;
15static constexpr uint8_t tSideNum = 2;
16static constexpr auto Pside = "P";
17static constexpr auto Tside = "T";
18
19static constexpr auto redundancyIntf =
20 "xyz.openbmc_project.Software.RedundancyPriority";
21
22/** @class CodeUpdate
23 *
24 * @brief This class performs the necessary operation in pldm for
25 * inband code update. That includes taking actions on the
26 * setStateEffecterStates calls from Host and also sending
27 * notification to phosphor-software-manager app
28 */
29class CodeUpdate
30{
31 public:
32 /** @brief Constructor to create an inband codeupdate object
33 * @param[in] dBusIntf - D-Bus handler pointer
34 */
35 CodeUpdate(const pldm::utils::DBusHandler* dBusIntf) : dBusIntf(dBusIntf)
36 {
37 currBootSide = Tside;
38 nextBootSide = Tside;
39 }
40
41 /* @brief Method to return the current boot side
42 */
43 std::string fetchCurrentBootSide();
44
45 /* @brief Method to return the next boot side
46 */
47 std::string fetchNextBootSide();
48
49 /* @brief Method to set the current boot side or
50 * perform a rename operation on current boot side
51 * @param[in] currSide - current side to be set to
52 * @return PLDM_SUCCESS codes
53 */
54 int setCurrentBootSide(const std::string& currSide);
55
56 /* @brief Method to set the next boot side
57 * @param[in] nextSide - next boot side to be set to
58 * @return PLDM_SUCCESS codes
59 */
60 int setNextBootSide(const std::string& nextSide);
61
62 /* @brief Method to set the running and non-running
63 * images
64 */
65 virtual void setVersions();
66
67 /* @brief Method to return the newly upoaded image id in
68 * /tmp
69 */
70 std::string fetchnewImageId()
71 {
72 return newImageId;
73 }
74
75 /* @brief Method to set the oem platform handler in CodeUpdate class */
76 void setOemPlatformHandler(pldm::responder::oem_platform::Handler* handler);
77
Sampa Misra69508502020-09-08 00:08:21 -050078 /* @brief Method to check whether code update is
79 * going on
80 * @return - bool
81 */
82 bool isCodeUpdateInProgress()
83 {
84 return codeUpdateInProgress;
85 }
86
87 /* @brief Method to indicate whether code update
88 * is going on
89 * @param[in] progress - yes/no
90 */
91 void setCodeUpdateProgress(bool progress)
92 {
93 codeUpdateInProgress = progress;
94 }
95
Sampa Misraaea5dde2020-08-31 08:33:47 -050096 virtual ~CodeUpdate()
97 {}
98
99 private:
100 std::string currBootSide; //!< current boot side
101 std::string nextBootSide; //!< next boot side
102 std::string runningVersion; //!< currently running image
103 std::string nonRunningVersion; //!< alternate image
104 std::string newImageId; //!< new image id
105 bool codeUpdateInProgress =
106 false; //!< indicates whether codeupdate is going on
107 const pldm::utils::DBusHandler* dBusIntf; //!< D-Bus handler
108 std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
109 captureNextBootSideChange; //!< vector to catch the D-Bus property
110 //!< change for next boot side
111 std::unique_ptr<sdbusplus::bus::match::match>
112 fwUpdateMatcher; //!< pointer to capture the interface added signal for
113 //!< new image
114 pldm::responder::oem_platform::Handler*
115 oemPlatformHandler; //!< oem platform handler
116
117 /* @brief Method to take action when the subscribed D-Bus property is
118 * changed
119 * @param[in] chProperties - list of properties which have changed
120 * @return - none
121 */
122
123 void
124 processPriorityChangeNotification(const DbusChangedProps& chProperties);
125};
126
127/* @brief Method to fetch current or next boot side
128 * @param[in] entityInstance - entity instance for the sensor
129 * @param[in] codeUpdate - pointer to the CodeUpdate object
130 *
131 * @return - boot side
132 */
133uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate);
134
135/* @brief Method to set current or next boot side
136 * @param[in] entityInstance - entity instance for the effecter
137 * @param[in] currState - state to be set
138 * @param[in] stateField - state field set as sent by Host
139 * @return - PLDM_SUCCESS codes
140 */
141int setBootSide(uint16_t entityInstance, uint8_t currState,
142 const std::vector<set_effecter_state_field>& stateField,
143 CodeUpdate* codeUpdate);
144
145} // namespace responder
146} // namespace pldm