blob: 4de683525796a156e6bfbf3daa9b93f5b25b31e5 [file] [log] [blame]
Sampa Misraaea5dde2020-08-31 08:33:47 -05001#pragma once
Varsha Kaverappabb585b22020-09-10 06:15:42 -05002
Sampa Misraaea5dde2020-08-31 08:33:47 -05003#include "inband_code_update.hpp"
4#include "libpldmresponder/oem_handler.hpp"
Varsha Kaverappabb585b22020-09-10 06:15:42 -05005#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -05006#include "libpldmresponder/platform.hpp"
Sampa Misrac0c79482021-06-02 08:01:54 -05007#include "requester/handler.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -05008
George Liuc453e162022-12-21 17:16:23 +08009#include <libpldm/entity.h>
10#include <libpldm/platform.h>
11#include <libpldm/state_set_oem_ibm.h>
12
Christian Geddes7f9523c2021-08-03 13:44:38 -050013typedef ibm_oem_pldm_state_set_firmware_update_state_values CodeUpdateState;
14
Sampa Misraaea5dde2020-08-31 08:33:47 -050015namespace pldm
16{
Sampa Misraaea5dde2020-08-31 08:33:47 -050017namespace responder
18{
Sampa Misraaea5dde2020-08-31 08:33:47 -050019namespace oem_ibm_platform
20{
Sagar Srinivas78a225a2020-08-27 00:52:20 -050021constexpr uint16_t ENTITY_INSTANCE_0 = 0;
22constexpr uint16_t ENTITY_INSTANCE_1 = 1;
23
Sagar Srinivas7f760b32021-05-12 07:46:56 -050024enum SetEventReceiverCount
25{
26 SET_EVENT_RECEIVER_SENT = 0x2,
27};
28
Sampa Misraaea5dde2020-08-31 08:33:47 -050029class Handler : public oem_platform::Handler
30{
31 public:
32 Handler(const pldm::utils::DBusHandler* dBusIntf,
Varsha Kaverappabb585b22020-09-10 06:15:42 -050033 pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
Brad Bishop5079ac42021-08-19 18:35:06 -040034 uint8_t mctp_eid, pldm::dbus_api::Requester& requester,
35 sdeventplus::Event& event,
Sampa Misrac0c79482021-06-02 08:01:54 -050036 pldm::requester::Handler<pldm::requester::Request>* handler) :
Sampa Misraaea5dde2020-08-31 08:33:47 -050037 oem_platform::Handler(dBusIntf),
Varsha Kaverappabb585b22020-09-10 06:15:42 -050038 codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
Sampa Misrac0c79482021-06-02 08:01:54 -050039 mctp_eid(mctp_eid), requester(requester), event(event), handler(handler)
Sampa Misraaea5dde2020-08-31 08:33:47 -050040 {
41 codeUpdate->setVersions();
Sagar Srinivas7f760b32021-05-12 07:46:56 -050042 setEventReceiverCnt = 0;
43
44 using namespace sdbusplus::bus::match::rules;
Patrick Williams84b790c2022-07-22 19:26:56 -050045 hostOffMatch = std::make_unique<sdbusplus::bus::match_t>(
Sagar Srinivas7f760b32021-05-12 07:46:56 -050046 pldm::utils::DBusHandler::getBus(),
47 propertiesChanged("/xyz/openbmc_project/state/host0",
48 "xyz.openbmc_project.State.Host"),
Patrick Williams84b790c2022-07-22 19:26:56 -050049 [this](sdbusplus::message_t& msg) {
Patrick Williams6da4f912023-05-10 07:50:53 -050050 pldm::utils::DbusChangedProps props{};
51 std::string intf;
52 msg.read(intf, props);
53 const auto itr = props.find("CurrentHostState");
54 if (itr != props.end())
55 {
56 pldm::utils::PropertyValue value = itr->second;
57 auto propVal = std::get<std::string>(value);
58 if (propVal == "xyz.openbmc_project.State.Host.HostState.Off")
Sagar Srinivas7f760b32021-05-12 07:46:56 -050059 {
Patrick Williams6da4f912023-05-10 07:50:53 -050060 hostOff = true;
61 setEventReceiverCnt = 0;
62 disableWatchDogTimer();
Sagar Srinivas7f760b32021-05-12 07:46:56 -050063 }
Patrick Williams6da4f912023-05-10 07:50:53 -050064 else if (propVal ==
65 "xyz.openbmc_project.State.Host.HostState.Running")
66 {
67 hostOff = false;
68 }
69 }
Sagar Srinivas7f760b32021-05-12 07:46:56 -050070 });
Sampa Misraaea5dde2020-08-31 08:33:47 -050071 }
72
73 int getOemStateSensorReadingsHandler(
Brad Bishop5079ac42021-08-19 18:35:06 -040074 EntityType entityType, pldm::pdr::EntityInstance entityInstance,
75 pldm::pdr::StateSetId stateSetId,
76 pldm::pdr::CompositeCount compSensorCnt,
Sampa Misraaea5dde2020-08-31 08:33:47 -050077 std::vector<get_sensor_state_field>& stateField);
78
Sampa Misra3a0e3b92020-10-21 05:58:00 -050079 int oemSetStateEffecterStatesHandler(
Varsha Kaverappa3fbd39e2020-09-28 01:40:22 -050080 uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId,
81 uint8_t compEffecterCnt,
82 std::vector<set_effecter_state_field>& stateField, uint16_t effecterId);
Sampa Misraaea5dde2020-08-31 08:33:47 -050083
84 /** @brief Method to set the platform handler in the
85 * oem_ibm_handler class
86 * @param[in] handler - pointer to PLDM platform handler
87 */
88 void setPlatformHandler(pldm::responder::platform::Handler* handler);
89
Sagar Srinivas78a225a2020-08-27 00:52:20 -050090 /** @brief Method to fetch the effecter ID of the code update PDRs
91 *
92 * @return platformHandler->getNextEffecterId() - returns the
93 * effecter ID from the platform handler
94 */
Manojkiran Eda6b1d8832021-03-27 11:25:06 +053095 virtual uint16_t getNextEffecterId()
Sagar Srinivas78a225a2020-08-27 00:52:20 -050096 {
97 return platformHandler->getNextEffecterId();
98 }
99
100 /** @brief Method to fetch the sensor ID of the code update PDRs
101 *
102 * @return platformHandler->getNextSensorId() - returns the
103 * Sensor ID from the platform handler
104 */
Manojkiran Eda6b1d8832021-03-27 11:25:06 +0530105 virtual uint16_t getNextSensorId()
Sagar Srinivas78a225a2020-08-27 00:52:20 -0500106 {
107 return platformHandler->getNextSensorId();
108 }
109
110 /** @brief Method to Generate the OEM PDRs
111 *
112 * @param[in] repo - instance of concrete implementation of Repo
113 */
114 void buildOEMPDR(pdr_utils::Repo& repo);
115
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500116 /** @brief Method to send code update event to host
117 * @param[in] sensorId - sendor ID
118 * @param[in] sensorEventClass - event class of sensor
119 * @param[in] sensorOffset - sensor offset
120 * @param[in] eventState - new code update event state
121 * @param[in] prevEventState - previous code update event state
122 * @return none
123 */
124 void sendStateSensorEvent(uint16_t sensorId,
125 enum sensor_event_class_states sensorEventClass,
126 uint8_t sensorOffset, uint8_t eventState,
127 uint8_t prevEventState);
128
129 /** @brief Method to send encoded request msg of code update event to host
130 * @param[in] requestMsg - encoded request msg
Sampa Misrac0c79482021-06-02 08:01:54 -0500131 * @param[in] instanceId - instance id of the message
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500132 * @return PLDM status code
133 */
Sampa Misrac0c79482021-06-02 08:01:54 -0500134 int sendEventToHost(std::vector<uint8_t>& requestMsg, uint8_t instanceId);
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500135
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500136 /** @brief _processEndUpdate processes the actual work that needs
137 * to be carried out after EndUpdate effecter is set. This is done async
138 * after sending response for EndUpdate set effecter
139 * @param[in] source - sdeventplus event source
140 */
141 void _processEndUpdate(sdeventplus::source::EventBase& source);
142
143 /** @brief _processStartUpdate processes the actual work that needs
144 * to be carried out after StartUpdate effecter is set. This is done async
145 * after sending response for StartUpdate set effecter
146 * @param[in] source - sdeventplus event source
147 */
148 void _processStartUpdate(sdeventplus::source::EventBase& source);
149
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600150 /** @brief _processSystemReboot processes the actual work that needs to be
151 * carried out after the System Power State effecter is set to reboot
152 * the system
153 * @param[in] source - sdeventplus event source
154 */
155 void _processSystemReboot(sdeventplus::source::EventBase& source);
156
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500157 /*keeps track how many times setEventReceiver is sent */
158 void countSetEventReceiver()
159 {
160 setEventReceiverCnt++;
161 }
162
163 /* disables watchdog if running and Host is up */
164 void checkAndDisableWatchDog();
165
Sagar Srinivas79669c92021-04-28 15:43:30 -0500166 /** @brief To check if the watchdog app is running
167 *
168 * @return the running status of watchdog app
169 */
170 bool watchDogRunning();
171
172 /** @brief Method to reset the Watchdog timer on receiving platform Event
173 * Message for heartbeat elapsed time from Hostboot
174 */
175 void resetWatchDogTimer();
176
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500177 /** @brief To disable to the watchdog timer on host poweron completion*/
178 void disableWatchDogTimer();
179
Pavithra Barithaya99854a72021-09-29 06:58:11 -0500180 /** @brief to check the BMC state*/
181 int checkBMCState();
182
Sampa Misraaea5dde2020-08-31 08:33:47 -0500183 ~Handler() = default;
184
185 pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
186 pldm::responder::platform::Handler*
187 platformHandler; //!< pointer to PLDM platform handler
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500188
189 /** @brief fd of MCTP communications socket */
190 int mctp_fd;
191
192 /** @brief MCTP EID of host firmware */
193 uint8_t mctp_eid;
194
195 /** @brief reference to Requester object, primarily used to access API to
196 * obtain PLDM instance id.
197 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400198 pldm::dbus_api::Requester& requester;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500199 /** @brief sdeventplus event source */
200 std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent;
201 std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600202 std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500203
204 /** @brief reference of main event loop of pldmd, primarily used to schedule
205 * work
206 */
207 sdeventplus::Event& event;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600208
209 private:
210 /** @brief D-Bus property changed signal match for CurrentPowerState*/
Patrick Williams84b790c2022-07-22 19:26:56 -0500211 std::unique_ptr<sdbusplus::bus::match_t> chassisOffMatch;
Sampa Misrac0c79482021-06-02 08:01:54 -0500212
213 /** @brief PLDM request handler */
214 pldm::requester::Handler<pldm::requester::Request>* handler;
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500215
216 /** @brief D-Bus property changed signal match */
Patrick Williams84b790c2022-07-22 19:26:56 -0500217 std::unique_ptr<sdbusplus::bus::match_t> hostOffMatch;
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500218
219 bool hostOff = true;
220
221 int setEventReceiverCnt = 0;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500222};
223
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500224/** @brief Method to encode code update event msg
225 * @param[in] eventType - type of event
226 * @param[in] eventDataVec - vector of event data to be sent to host
227 * @param[in/out] requestMsg - request msg to be encoded
228 * @param[in] instanceId - instance ID
229 * @return PLDM status code
230 */
231int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec,
232 std::vector<uint8_t>& requestMsg, uint8_t instanceId);
233
Sampa Misraaea5dde2020-08-31 08:33:47 -0500234} // namespace oem_ibm_platform
235
236} // namespace responder
237
238} // namespace pldm