blob: 8181149151855c9f3dea612858cea12b9c72e847 [file] [log] [blame]
Sampa Misraaea5dde2020-08-31 08:33:47 -05001#pragma once
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -06002#include "libpldm/entity.h"
Varsha Kaverappabb585b22020-09-10 06:15:42 -05003#include "libpldm/platform.h"
Christian Geddes7f9523c2021-08-03 13:44:38 -05004#include "oem/ibm/libpldm/state_set.h"
Varsha Kaverappabb585b22020-09-10 06:15:42 -05005
Sampa Misraaea5dde2020-08-31 08:33:47 -05006#include "inband_code_update.hpp"
7#include "libpldmresponder/oem_handler.hpp"
Varsha Kaverappabb585b22020-09-10 06:15:42 -05008#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -05009#include "libpldmresponder/platform.hpp"
Sampa Misrac0c79482021-06-02 08:01:54 -050010#include "requester/handler.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -050011
Christian Geddes7f9523c2021-08-03 13:44:38 -050012typedef ibm_oem_pldm_state_set_firmware_update_state_values CodeUpdateState;
13
Sampa Misraaea5dde2020-08-31 08:33:47 -050014namespace pldm
15{
Sampa Misraaea5dde2020-08-31 08:33:47 -050016namespace responder
17{
Sampa Misraaea5dde2020-08-31 08:33:47 -050018namespace oem_ibm_platform
19{
Sagar Srinivas78a225a2020-08-27 00:52:20 -050020static constexpr auto PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE = 24577;
21constexpr 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;
45 hostOffMatch = std::make_unique<sdbusplus::bus::match::match>(
46 pldm::utils::DBusHandler::getBus(),
47 propertiesChanged("/xyz/openbmc_project/state/host0",
48 "xyz.openbmc_project.State.Host"),
49 [this](sdbusplus::message::message& msg) {
50 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 ==
59 "xyz.openbmc_project.State.Host.HostState.Off")
60 {
61 hostOff = true;
62 setEventReceiverCnt = 0;
63 disableWatchDogTimer();
64 }
65 else if (propVal ==
66 "xyz.openbmc_project.State.Host.HostState.Running")
67 {
68 hostOff = false;
69 }
70 }
71 });
Sampa Misraaea5dde2020-08-31 08:33:47 -050072 }
73
74 int getOemStateSensorReadingsHandler(
Brad Bishop5079ac42021-08-19 18:35:06 -040075 EntityType entityType, pldm::pdr::EntityInstance entityInstance,
76 pldm::pdr::StateSetId stateSetId,
77 pldm::pdr::CompositeCount compSensorCnt,
Sampa Misraaea5dde2020-08-31 08:33:47 -050078 std::vector<get_sensor_state_field>& stateField);
79
Sampa Misra3a0e3b92020-10-21 05:58:00 -050080 int oemSetStateEffecterStatesHandler(
Varsha Kaverappa3fbd39e2020-09-28 01:40:22 -050081 uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId,
82 uint8_t compEffecterCnt,
83 std::vector<set_effecter_state_field>& stateField, uint16_t effecterId);
Sampa Misraaea5dde2020-08-31 08:33:47 -050084
85 /** @brief Method to set the platform handler in the
86 * oem_ibm_handler class
87 * @param[in] handler - pointer to PLDM platform handler
88 */
89 void setPlatformHandler(pldm::responder::platform::Handler* handler);
90
Sagar Srinivas78a225a2020-08-27 00:52:20 -050091 /** @brief Method to fetch the effecter ID of the code update PDRs
92 *
93 * @return platformHandler->getNextEffecterId() - returns the
94 * effecter ID from the platform handler
95 */
Manojkiran Eda6b1d8832021-03-27 11:25:06 +053096 virtual uint16_t getNextEffecterId()
Sagar Srinivas78a225a2020-08-27 00:52:20 -050097 {
98 return platformHandler->getNextEffecterId();
99 }
100
101 /** @brief Method to fetch the sensor ID of the code update PDRs
102 *
103 * @return platformHandler->getNextSensorId() - returns the
104 * Sensor ID from the platform handler
105 */
Manojkiran Eda6b1d8832021-03-27 11:25:06 +0530106 virtual uint16_t getNextSensorId()
Sagar Srinivas78a225a2020-08-27 00:52:20 -0500107 {
108 return platformHandler->getNextSensorId();
109 }
110
111 /** @brief Method to Generate the OEM PDRs
112 *
113 * @param[in] repo - instance of concrete implementation of Repo
114 */
115 void buildOEMPDR(pdr_utils::Repo& repo);
116
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500117 /** @brief Method to send code update event to host
118 * @param[in] sensorId - sendor ID
119 * @param[in] sensorEventClass - event class of sensor
120 * @param[in] sensorOffset - sensor offset
121 * @param[in] eventState - new code update event state
122 * @param[in] prevEventState - previous code update event state
123 * @return none
124 */
125 void sendStateSensorEvent(uint16_t sensorId,
126 enum sensor_event_class_states sensorEventClass,
127 uint8_t sensorOffset, uint8_t eventState,
128 uint8_t prevEventState);
129
130 /** @brief Method to send encoded request msg of code update event to host
131 * @param[in] requestMsg - encoded request msg
Sampa Misrac0c79482021-06-02 08:01:54 -0500132 * @param[in] instanceId - instance id of the message
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500133 * @return PLDM status code
134 */
Sampa Misrac0c79482021-06-02 08:01:54 -0500135 int sendEventToHost(std::vector<uint8_t>& requestMsg, uint8_t instanceId);
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500136
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500137 /** @brief _processEndUpdate processes the actual work that needs
138 * to be carried out after EndUpdate effecter is set. This is done async
139 * after sending response for EndUpdate set effecter
140 * @param[in] source - sdeventplus event source
141 */
142 void _processEndUpdate(sdeventplus::source::EventBase& source);
143
144 /** @brief _processStartUpdate processes the actual work that needs
145 * to be carried out after StartUpdate effecter is set. This is done async
146 * after sending response for StartUpdate set effecter
147 * @param[in] source - sdeventplus event source
148 */
149 void _processStartUpdate(sdeventplus::source::EventBase& source);
150
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600151 /** @brief _processSystemReboot processes the actual work that needs to be
152 * carried out after the System Power State effecter is set to reboot
153 * the system
154 * @param[in] source - sdeventplus event source
155 */
156 void _processSystemReboot(sdeventplus::source::EventBase& source);
157
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500158 /*keeps track how many times setEventReceiver is sent */
159 void countSetEventReceiver()
160 {
161 setEventReceiverCnt++;
162 }
163
164 /* disables watchdog if running and Host is up */
165 void checkAndDisableWatchDog();
166
Sagar Srinivas79669c92021-04-28 15:43:30 -0500167 /** @brief To check if the watchdog app is running
168 *
169 * @return the running status of watchdog app
170 */
171 bool watchDogRunning();
172
173 /** @brief Method to reset the Watchdog timer on receiving platform Event
174 * Message for heartbeat elapsed time from Hostboot
175 */
176 void resetWatchDogTimer();
177
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500178 /** @brief To disable to the watchdog timer on host poweron completion*/
179 void disableWatchDogTimer();
180
Sampa Misraaea5dde2020-08-31 08:33:47 -0500181 ~Handler() = default;
182
183 pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
184 pldm::responder::platform::Handler*
185 platformHandler; //!< pointer to PLDM platform handler
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500186
187 /** @brief fd of MCTP communications socket */
188 int mctp_fd;
189
190 /** @brief MCTP EID of host firmware */
191 uint8_t mctp_eid;
192
193 /** @brief reference to Requester object, primarily used to access API to
194 * obtain PLDM instance id.
195 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400196 pldm::dbus_api::Requester& requester;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500197 /** @brief sdeventplus event source */
198 std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent;
199 std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600200 std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500201
202 /** @brief reference of main event loop of pldmd, primarily used to schedule
203 * work
204 */
205 sdeventplus::Event& event;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600206
207 private:
208 /** @brief D-Bus property changed signal match for CurrentPowerState*/
209 std::unique_ptr<sdbusplus::bus::match::match> chassisOffMatch;
Sampa Misrac0c79482021-06-02 08:01:54 -0500210
211 /** @brief PLDM request handler */
212 pldm::requester::Handler<pldm::requester::Request>* handler;
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500213
214 /** @brief D-Bus property changed signal match */
215 std::unique_ptr<sdbusplus::bus::match::match> hostOffMatch;
216
217 bool hostOff = true;
218
219 int setEventReceiverCnt = 0;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500220};
221
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500222/** @brief Method to encode code update event msg
223 * @param[in] eventType - type of event
224 * @param[in] eventDataVec - vector of event data to be sent to host
225 * @param[in/out] requestMsg - request msg to be encoded
226 * @param[in] instanceId - instance ID
227 * @return PLDM status code
228 */
229int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec,
230 std::vector<uint8_t>& requestMsg, uint8_t instanceId);
231
Sampa Misraaea5dde2020-08-31 08:33:47 -0500232} // namespace oem_ibm_platform
233
234} // namespace responder
235
236} // namespace pldm