blob: ce69cf1a6dc325ef19866522d273000500199c52 [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"
Eddie Jamesbbbbae12021-10-14 09:24:23 -05004#include "oem/ibm/libpldm/state_set_oem_ibm.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 -050020constexpr uint16_t ENTITY_INSTANCE_0 = 0;
21constexpr uint16_t ENTITY_INSTANCE_1 = 1;
22
Sagar Srinivas7f760b32021-05-12 07:46:56 -050023enum SetEventReceiverCount
24{
25 SET_EVENT_RECEIVER_SENT = 0x2,
26};
27
Sampa Misraaea5dde2020-08-31 08:33:47 -050028class Handler : public oem_platform::Handler
29{
30 public:
31 Handler(const pldm::utils::DBusHandler* dBusIntf,
Varsha Kaverappabb585b22020-09-10 06:15:42 -050032 pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
Brad Bishop5079ac42021-08-19 18:35:06 -040033 uint8_t mctp_eid, pldm::dbus_api::Requester& requester,
34 sdeventplus::Event& event,
Sampa Misrac0c79482021-06-02 08:01:54 -050035 pldm::requester::Handler<pldm::requester::Request>* handler) :
Sampa Misraaea5dde2020-08-31 08:33:47 -050036 oem_platform::Handler(dBusIntf),
Varsha Kaverappabb585b22020-09-10 06:15:42 -050037 codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
Sampa Misrac0c79482021-06-02 08:01:54 -050038 mctp_eid(mctp_eid), requester(requester), event(event), handler(handler)
Sampa Misraaea5dde2020-08-31 08:33:47 -050039 {
40 codeUpdate->setVersions();
Sagar Srinivas7f760b32021-05-12 07:46:56 -050041 setEventReceiverCnt = 0;
42
43 using namespace sdbusplus::bus::match::rules;
44 hostOffMatch = std::make_unique<sdbusplus::bus::match::match>(
45 pldm::utils::DBusHandler::getBus(),
46 propertiesChanged("/xyz/openbmc_project/state/host0",
47 "xyz.openbmc_project.State.Host"),
48 [this](sdbusplus::message::message& msg) {
49 pldm::utils::DbusChangedProps props{};
50 std::string intf;
51 msg.read(intf, props);
52 const auto itr = props.find("CurrentHostState");
53 if (itr != props.end())
54 {
55 pldm::utils::PropertyValue value = itr->second;
56 auto propVal = std::get<std::string>(value);
57 if (propVal ==
58 "xyz.openbmc_project.State.Host.HostState.Off")
59 {
60 hostOff = true;
61 setEventReceiverCnt = 0;
62 disableWatchDogTimer();
63 }
64 else if (propVal ==
65 "xyz.openbmc_project.State.Host.HostState.Running")
66 {
67 hostOff = false;
68 }
69 }
70 });
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*/
211 std::unique_ptr<sdbusplus::bus::match::match> 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 */
217 std::unique_ptr<sdbusplus::bus::match::match> hostOffMatch;
218
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