blob: 9ad016f8479790e3591d3fa9a9c908361a3acbb4 [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>
Andrew Jeffery21f128d2024-01-15 15:34:26 +103010#include <libpldm/oem/ibm/state_set.h>
George Liuc453e162022-12-21 17:16:23 +080011#include <libpldm/platform.h>
George Liuc453e162022-12-21 17:16:23 +080012
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 Srinivas3687e2b2023-04-10 05:08:28 -050024constexpr uint32_t BMC_PDR_START_RANGE = 0x00000000;
25constexpr uint32_t BMC_PDR_END_RANGE = 0x00FFFFFF;
26constexpr uint32_t HOST_PDR_START_RANGE = 0x01000000;
27constexpr uint32_t HOST_PDR_END_RANGE = 0x01FFFFFF;
28
Sagar Srinivas7f760b32021-05-12 07:46:56 -050029enum SetEventReceiverCount
30{
31 SET_EVENT_RECEIVER_SENT = 0x2,
32};
33
Sampa Misraaea5dde2020-08-31 08:33:47 -050034class Handler : public oem_platform::Handler
35{
36 public:
37 Handler(const pldm::utils::DBusHandler* dBusIntf,
Varsha Kaverappabb585b22020-09-10 06:15:42 -050038 pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
Andrew Jefferya330b2f2023-05-04 14:55:37 +093039 uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb,
Brad Bishop5079ac42021-08-19 18:35:06 -040040 sdeventplus::Event& event,
Sampa Misrac0c79482021-06-02 08:01:54 -050041 pldm::requester::Handler<pldm::requester::Request>* handler) :
Sampa Misraaea5dde2020-08-31 08:33:47 -050042 oem_platform::Handler(dBusIntf),
Varsha Kaverappabb585b22020-09-10 06:15:42 -050043 codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
Andrew Jefferya330b2f2023-05-04 14:55:37 +093044 mctp_eid(mctp_eid), instanceIdDb(instanceIdDb), event(event),
45 handler(handler)
Sampa Misraaea5dde2020-08-31 08:33:47 -050046 {
47 codeUpdate->setVersions();
Sagar Srinivas7f760b32021-05-12 07:46:56 -050048 setEventReceiverCnt = 0;
49
50 using namespace sdbusplus::bus::match::rules;
Patrick Williams84b790c2022-07-22 19:26:56 -050051 hostOffMatch = std::make_unique<sdbusplus::bus::match_t>(
Sagar Srinivas7f760b32021-05-12 07:46:56 -050052 pldm::utils::DBusHandler::getBus(),
53 propertiesChanged("/xyz/openbmc_project/state/host0",
54 "xyz.openbmc_project.State.Host"),
Patrick Williams84b790c2022-07-22 19:26:56 -050055 [this](sdbusplus::message_t& msg) {
Patrick Williams6da4f912023-05-10 07:50:53 -050056 pldm::utils::DbusChangedProps props{};
57 std::string intf;
58 msg.read(intf, props);
59 const auto itr = props.find("CurrentHostState");
60 if (itr != props.end())
61 {
62 pldm::utils::PropertyValue value = itr->second;
63 auto propVal = std::get<std::string>(value);
64 if (propVal == "xyz.openbmc_project.State.Host.HostState.Off")
Sagar Srinivas7f760b32021-05-12 07:46:56 -050065 {
Patrick Williams6da4f912023-05-10 07:50:53 -050066 hostOff = true;
67 setEventReceiverCnt = 0;
68 disableWatchDogTimer();
Sagar Srinivas7f760b32021-05-12 07:46:56 -050069 }
Patrick Williams6da4f912023-05-10 07:50:53 -050070 else if (propVal ==
71 "xyz.openbmc_project.State.Host.HostState.Running")
72 {
73 hostOff = false;
74 }
75 }
Patrick Williamsa6756622023-10-20 11:19:15 -050076 });
Sampa Misraaea5dde2020-08-31 08:33:47 -050077 }
78
79 int getOemStateSensorReadingsHandler(
Brad Bishop5079ac42021-08-19 18:35:06 -040080 EntityType entityType, pldm::pdr::EntityInstance entityInstance,
81 pldm::pdr::StateSetId stateSetId,
82 pldm::pdr::CompositeCount compSensorCnt,
Sampa Misraaea5dde2020-08-31 08:33:47 -050083 std::vector<get_sensor_state_field>& stateField);
84
Sampa Misra3a0e3b92020-10-21 05:58:00 -050085 int oemSetStateEffecterStatesHandler(
Varsha Kaverappa3fbd39e2020-09-28 01:40:22 -050086 uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId,
87 uint8_t compEffecterCnt,
88 std::vector<set_effecter_state_field>& stateField, uint16_t effecterId);
Sampa Misraaea5dde2020-08-31 08:33:47 -050089
90 /** @brief Method to set the platform handler in the
91 * oem_ibm_handler class
92 * @param[in] handler - pointer to PLDM platform handler
93 */
94 void setPlatformHandler(pldm::responder::platform::Handler* handler);
95
Sagar Srinivas78a225a2020-08-27 00:52:20 -050096 /** @brief Method to fetch the effecter ID of the code update PDRs
97 *
98 * @return platformHandler->getNextEffecterId() - returns the
99 * effecter ID from the platform handler
100 */
Manojkiran Eda6b1d8832021-03-27 11:25:06 +0530101 virtual uint16_t getNextEffecterId()
Sagar Srinivas78a225a2020-08-27 00:52:20 -0500102 {
103 return platformHandler->getNextEffecterId();
104 }
105
106 /** @brief Method to fetch the sensor ID of the code update PDRs
107 *
108 * @return platformHandler->getNextSensorId() - returns the
109 * Sensor ID from the platform handler
110 */
Manojkiran Eda6b1d8832021-03-27 11:25:06 +0530111 virtual uint16_t getNextSensorId()
Sagar Srinivas78a225a2020-08-27 00:52:20 -0500112 {
113 return platformHandler->getNextSensorId();
114 }
115
116 /** @brief Method to Generate the OEM PDRs
117 *
118 * @param[in] repo - instance of concrete implementation of Repo
119 */
120 void buildOEMPDR(pdr_utils::Repo& repo);
121
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500122 /** @brief Method to send code update event to host
123 * @param[in] sensorId - sendor ID
124 * @param[in] sensorEventClass - event class of sensor
125 * @param[in] sensorOffset - sensor offset
126 * @param[in] eventState - new code update event state
127 * @param[in] prevEventState - previous code update event state
128 * @return none
129 */
130 void sendStateSensorEvent(uint16_t sensorId,
131 enum sensor_event_class_states sensorEventClass,
132 uint8_t sensorOffset, uint8_t eventState,
133 uint8_t prevEventState);
134
135 /** @brief Method to send encoded request msg of code update event to host
136 * @param[in] requestMsg - encoded request msg
Sampa Misrac0c79482021-06-02 08:01:54 -0500137 * @param[in] instanceId - instance id of the message
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500138 * @return PLDM status code
139 */
Sampa Misrac0c79482021-06-02 08:01:54 -0500140 int sendEventToHost(std::vector<uint8_t>& requestMsg, uint8_t instanceId);
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500141
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500142 /** @brief _processEndUpdate processes the actual work that needs
143 * to be carried out after EndUpdate effecter is set. This is done async
144 * after sending response for EndUpdate set effecter
145 * @param[in] source - sdeventplus event source
146 */
147 void _processEndUpdate(sdeventplus::source::EventBase& source);
148
149 /** @brief _processStartUpdate processes the actual work that needs
150 * to be carried out after StartUpdate effecter is set. This is done async
151 * after sending response for StartUpdate set effecter
152 * @param[in] source - sdeventplus event source
153 */
154 void _processStartUpdate(sdeventplus::source::EventBase& source);
155
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600156 /** @brief _processSystemReboot processes the actual work that needs to be
157 * carried out after the System Power State effecter is set to reboot
158 * the system
159 * @param[in] source - sdeventplus event source
160 */
161 void _processSystemReboot(sdeventplus::source::EventBase& source);
162
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500163 /*keeps track how many times setEventReceiver is sent */
164 void countSetEventReceiver()
165 {
166 setEventReceiverCnt++;
167 }
168
169 /* disables watchdog if running and Host is up */
170 void checkAndDisableWatchDog();
171
Sagar Srinivas79669c92021-04-28 15:43:30 -0500172 /** @brief To check if the watchdog app is running
173 *
174 * @return the running status of watchdog app
175 */
176 bool watchDogRunning();
177
178 /** @brief Method to reset the Watchdog timer on receiving platform Event
179 * Message for heartbeat elapsed time from Hostboot
180 */
181 void resetWatchDogTimer();
182
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500183 /** @brief To disable to the watchdog timer on host poweron completion*/
184 void disableWatchDogTimer();
185
Pavithra Barithaya99854a72021-09-29 06:58:11 -0500186 /** @brief to check the BMC state*/
187 int checkBMCState();
188
Kamalkumar Patel15ce5a12024-05-07 11:45:11 -0500189 /** @brief update the dbus object paths */
190 void updateOemDbusPaths(std::string& dbusPath);
191
Sagar Srinivas3687e2b2023-04-10 05:08:28 -0500192 /** @brief Method to fetch the last BMC record from the PDR repo
193 *
194 * @param[in] repo - pointer to BMC's primary PDR repo
195 *
196 * @return the last BMC record from the repo
197 */
198 const pldm_pdr_record* fetchLastBMCRecord(const pldm_pdr* repo);
199
200 /** @brief Method to check if the record handle passed is in remote PDR
201 * record handle range
202 *
203 * @param[in] record_handle - record handle of the PDR
204 *
205 * @return true if record handle passed is in host PDR record handle range
206 */
207 bool checkRecordHandleInRange(const uint32_t& record_handle);
208
Sagar Srinivas90314a32023-10-17 10:38:03 -0500209 /** *brief Method to call the setEventReceiver command*/
210 void processSetEventReceiver();
211
212 /** @brief Method to call the setEventReceiver through the platform
213 * handler
214 */
215 virtual void setEventReceiver()
216 {
217 platformHandler->setEventReceiver();
218 }
219
Sampa Misraaea5dde2020-08-31 08:33:47 -0500220 ~Handler() = default;
221
222 pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
223 pldm::responder::platform::Handler*
224 platformHandler; //!< pointer to PLDM platform handler
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500225
226 /** @brief fd of MCTP communications socket */
227 int mctp_fd;
228
229 /** @brief MCTP EID of host firmware */
230 uint8_t mctp_eid;
231
Andrew Jefferya330b2f2023-05-04 14:55:37 +0930232 /** @brief reference to an InstanceIdDb object, used to obtain a PLDM
233 * instance id. */
234 pldm::InstanceIdDb& instanceIdDb;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500235 /** @brief sdeventplus event source */
236 std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent;
237 std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600238 std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500239
240 /** @brief reference of main event loop of pldmd, primarily used to schedule
241 * work
242 */
243 sdeventplus::Event& event;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600244
245 private:
246 /** @brief D-Bus property changed signal match for CurrentPowerState*/
Patrick Williams84b790c2022-07-22 19:26:56 -0500247 std::unique_ptr<sdbusplus::bus::match_t> chassisOffMatch;
Sampa Misrac0c79482021-06-02 08:01:54 -0500248
249 /** @brief PLDM request handler */
250 pldm::requester::Handler<pldm::requester::Request>* handler;
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500251
252 /** @brief D-Bus property changed signal match */
Patrick Williams84b790c2022-07-22 19:26:56 -0500253 std::unique_ptr<sdbusplus::bus::match_t> hostOffMatch;
Sagar Srinivas7f760b32021-05-12 07:46:56 -0500254
255 bool hostOff = true;
256
257 int setEventReceiverCnt = 0;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500258};
259
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500260/** @brief Method to encode code update event msg
261 * @param[in] eventType - type of event
262 * @param[in] eventDataVec - vector of event data to be sent to host
263 * @param[in/out] requestMsg - request msg to be encoded
264 * @param[in] instanceId - instance ID
265 * @return PLDM status code
266 */
267int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec,
268 std::vector<uint8_t>& requestMsg, uint8_t instanceId);
269
Sampa Misraaea5dde2020-08-31 08:33:47 -0500270} // namespace oem_ibm_platform
271
272} // namespace responder
273
274} // namespace pldm