1 #pragma once
2 
3 #include "common/utils.hpp"
4 #include "libpldmresponder/platform.hpp"
5 
6 #include <string>
7 
8 using namespace pldm::utils;
9 namespace pldm
10 {
11 namespace responder
12 {
13 
14 static constexpr uint8_t pSideNum = 1;
15 static constexpr uint8_t tSideNum = 2;
16 static constexpr auto Pside = "P";
17 static constexpr auto Tside = "T";
18 
19 static 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  */
29 class 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 
78     virtual ~CodeUpdate()
79     {}
80 
81   private:
82     std::string currBootSide;      //!< current boot side
83     std::string nextBootSide;      //!< next boot side
84     std::string runningVersion;    //!< currently running image
85     std::string nonRunningVersion; //!< alternate image
86     std::string newImageId;        //!< new image id
87     bool codeUpdateInProgress =
88         false; //!< indicates whether codeupdate is going on
89     const pldm::utils::DBusHandler* dBusIntf; //!< D-Bus handler
90     std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
91         captureNextBootSideChange; //!< vector to catch the D-Bus property
92                                    //!< change for next boot side
93     std::unique_ptr<sdbusplus::bus::match::match>
94         fwUpdateMatcher; //!< pointer to capture the interface added signal for
95                          //!< new image
96     pldm::responder::oem_platform::Handler*
97         oemPlatformHandler; //!< oem platform handler
98 
99     /* @brief Method to take action when the subscribed D-Bus property is
100      *        changed
101      * @param[in] chProperties - list of properties which have changed
102      * @return - none
103      */
104 
105     void
106         processPriorityChangeNotification(const DbusChangedProps& chProperties);
107 };
108 
109 /* @brief Method to fetch current or next boot side
110  * @param[in] entityInstance - entity instance for the sensor
111  * @param[in] codeUpdate - pointer to the CodeUpdate object
112  *
113  * @return - boot side
114  */
115 uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate);
116 
117 /* @brief Method to set current or next  boot side
118  * @param[in] entityInstance - entity instance for the effecter
119  * @param[in] currState - state to be set
120  * @param[in] stateField - state field set as sent by Host
121  * @return - PLDM_SUCCESS codes
122  */
123 int setBootSide(uint16_t entityInstance, uint8_t currState,
124                 const std::vector<set_effecter_state_field>& stateField,
125                 CodeUpdate* codeUpdate);
126 
127 } // namespace responder
128 } // namespace pldm
129