blob: db89acf2236686ac3a3a4df1f25935d23c5245c4 [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"
4
Sampa Misraaea5dde2020-08-31 08:33:47 -05005#include "inband_code_update.hpp"
6#include "libpldmresponder/oem_handler.hpp"
Varsha Kaverappabb585b22020-09-10 06:15:42 -05007#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -05008#include "libpldmresponder/platform.hpp"
Sampa Misrac0c79482021-06-02 08:01:54 -05009#include "requester/handler.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -050010
11namespace pldm
12{
Sampa Misraaea5dde2020-08-31 08:33:47 -050013namespace responder
14{
Sampa Misraaea5dde2020-08-31 08:33:47 -050015namespace oem_ibm_platform
16{
17
18#define PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE 32768
19#define PLDM_OEM_IBM_BOOT_STATE 32769
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -060020#define PLDM_OEM_IBM_SYSTEM_POWER_STATE 32771
Sampa Misraaea5dde2020-08-31 08:33:47 -050021
Sagar Srinivas78a225a2020-08-27 00:52:20 -050022static constexpr auto PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE = 24577;
Sampa Misra3a0e3b92020-10-21 05:58:00 -050023static constexpr auto PLDM_OEM_IBM_VERIFICATION_STATE = 32770;
Sagar Srinivas78a225a2020-08-27 00:52:20 -050024constexpr uint16_t ENTITY_INSTANCE_0 = 0;
25constexpr uint16_t ENTITY_INSTANCE_1 = 1;
26
Varsha Kaverappabb585b22020-09-10 06:15:42 -050027enum class CodeUpdateState : uint8_t
28{
29 START = 0x1,
30 END = 0x2,
31 FAIL = 0x3,
32 ABORT = 0x4,
33 ACCEPT = 0x5,
34 REJECT = 0x6
35};
36
Sampa Misra3a0e3b92020-10-21 05:58:00 -050037enum VerificationStateValues
38{
39 VALID = 0x0,
40 ENTITLEMENT_FAIL = 0x1,
41 BANNED_PLATFORM_FAIL = 0x2,
42 MIN_MIF_FAIL = 0x4,
43};
44
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -060045enum SystemPowerStates
46{
47 POWER_CYCLE_HARD = 0x1,
48};
49
Sampa Misraaea5dde2020-08-31 08:33:47 -050050class Handler : public oem_platform::Handler
51{
52 public:
53 Handler(const pldm::utils::DBusHandler* dBusIntf,
Varsha Kaverappabb585b22020-09-10 06:15:42 -050054 pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
Brad Bishop5079ac42021-08-19 18:35:06 -040055 uint8_t mctp_eid, pldm::dbus_api::Requester& requester,
56 sdeventplus::Event& event,
Sampa Misrac0c79482021-06-02 08:01:54 -050057 pldm::requester::Handler<pldm::requester::Request>* handler) :
Sampa Misraaea5dde2020-08-31 08:33:47 -050058 oem_platform::Handler(dBusIntf),
Varsha Kaverappabb585b22020-09-10 06:15:42 -050059 codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
Sampa Misrac0c79482021-06-02 08:01:54 -050060 mctp_eid(mctp_eid), requester(requester), event(event), handler(handler)
Sampa Misraaea5dde2020-08-31 08:33:47 -050061 {
62 codeUpdate->setVersions();
63 }
64
65 int getOemStateSensorReadingsHandler(
Brad Bishop5079ac42021-08-19 18:35:06 -040066 EntityType entityType, pldm::pdr::EntityInstance entityInstance,
67 pldm::pdr::StateSetId stateSetId,
68 pldm::pdr::CompositeCount compSensorCnt,
Sampa Misraaea5dde2020-08-31 08:33:47 -050069 std::vector<get_sensor_state_field>& stateField);
70
Sampa Misra3a0e3b92020-10-21 05:58:00 -050071 int oemSetStateEffecterStatesHandler(
Varsha Kaverappa3fbd39e2020-09-28 01:40:22 -050072 uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId,
73 uint8_t compEffecterCnt,
74 std::vector<set_effecter_state_field>& stateField, uint16_t effecterId);
Sampa Misraaea5dde2020-08-31 08:33:47 -050075
76 /** @brief Method to set the platform handler in the
77 * oem_ibm_handler class
78 * @param[in] handler - pointer to PLDM platform handler
79 */
80 void setPlatformHandler(pldm::responder::platform::Handler* handler);
81
Sagar Srinivas78a225a2020-08-27 00:52:20 -050082 /** @brief Method to fetch the effecter ID of the code update PDRs
83 *
84 * @return platformHandler->getNextEffecterId() - returns the
85 * effecter ID from the platform handler
86 */
Manojkiran Eda6b1d8832021-03-27 11:25:06 +053087 virtual uint16_t getNextEffecterId()
Sagar Srinivas78a225a2020-08-27 00:52:20 -050088 {
89 return platformHandler->getNextEffecterId();
90 }
91
92 /** @brief Method to fetch the sensor ID of the code update PDRs
93 *
94 * @return platformHandler->getNextSensorId() - returns the
95 * Sensor ID from the platform handler
96 */
Manojkiran Eda6b1d8832021-03-27 11:25:06 +053097 virtual uint16_t getNextSensorId()
Sagar Srinivas78a225a2020-08-27 00:52:20 -050098 {
99 return platformHandler->getNextSensorId();
100 }
101
102 /** @brief Method to Generate the OEM PDRs
103 *
104 * @param[in] repo - instance of concrete implementation of Repo
105 */
106 void buildOEMPDR(pdr_utils::Repo& repo);
107
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500108 /** @brief Method to send code update event to host
109 * @param[in] sensorId - sendor ID
110 * @param[in] sensorEventClass - event class of sensor
111 * @param[in] sensorOffset - sensor offset
112 * @param[in] eventState - new code update event state
113 * @param[in] prevEventState - previous code update event state
114 * @return none
115 */
116 void sendStateSensorEvent(uint16_t sensorId,
117 enum sensor_event_class_states sensorEventClass,
118 uint8_t sensorOffset, uint8_t eventState,
119 uint8_t prevEventState);
120
121 /** @brief Method to send encoded request msg of code update event to host
122 * @param[in] requestMsg - encoded request msg
Sampa Misrac0c79482021-06-02 08:01:54 -0500123 * @param[in] instanceId - instance id of the message
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500124 * @return PLDM status code
125 */
Sampa Misrac0c79482021-06-02 08:01:54 -0500126 int sendEventToHost(std::vector<uint8_t>& requestMsg, uint8_t instanceId);
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500127
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500128 /** @brief _processEndUpdate processes the actual work that needs
129 * to be carried out after EndUpdate effecter is set. This is done async
130 * after sending response for EndUpdate set effecter
131 * @param[in] source - sdeventplus event source
132 */
133 void _processEndUpdate(sdeventplus::source::EventBase& source);
134
135 /** @brief _processStartUpdate processes the actual work that needs
136 * to be carried out after StartUpdate effecter is set. This is done async
137 * after sending response for StartUpdate set effecter
138 * @param[in] source - sdeventplus event source
139 */
140 void _processStartUpdate(sdeventplus::source::EventBase& source);
141
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600142 /** @brief _processSystemReboot processes the actual work that needs to be
143 * carried out after the System Power State effecter is set to reboot
144 * the system
145 * @param[in] source - sdeventplus event source
146 */
147 void _processSystemReboot(sdeventplus::source::EventBase& source);
148
Sagar Srinivas79669c92021-04-28 15:43:30 -0500149 /** @brief To check if the watchdog app is running
150 *
151 * @return the running status of watchdog app
152 */
153 bool watchDogRunning();
154
155 /** @brief Method to reset the Watchdog timer on receiving platform Event
156 * Message for heartbeat elapsed time from Hostboot
157 */
158 void resetWatchDogTimer();
159
Sampa Misraaea5dde2020-08-31 08:33:47 -0500160 ~Handler() = default;
161
162 pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
163 pldm::responder::platform::Handler*
164 platformHandler; //!< pointer to PLDM platform handler
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500165
166 /** @brief fd of MCTP communications socket */
167 int mctp_fd;
168
169 /** @brief MCTP EID of host firmware */
170 uint8_t mctp_eid;
171
172 /** @brief reference to Requester object, primarily used to access API to
173 * obtain PLDM instance id.
174 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400175 pldm::dbus_api::Requester& requester;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500176 /** @brief sdeventplus event source */
177 std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent;
178 std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600179 std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500180
181 /** @brief reference of main event loop of pldmd, primarily used to schedule
182 * work
183 */
184 sdeventplus::Event& event;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600185
186 private:
187 /** @brief D-Bus property changed signal match for CurrentPowerState*/
188 std::unique_ptr<sdbusplus::bus::match::match> chassisOffMatch;
Sampa Misrac0c79482021-06-02 08:01:54 -0500189
190 /** @brief PLDM request handler */
191 pldm::requester::Handler<pldm::requester::Request>* handler;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500192};
193
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500194/** @brief Method to encode code update event msg
195 * @param[in] eventType - type of event
196 * @param[in] eventDataVec - vector of event data to be sent to host
197 * @param[in/out] requestMsg - request msg to be encoded
198 * @param[in] instanceId - instance ID
199 * @return PLDM status code
200 */
201int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec,
202 std::vector<uint8_t>& requestMsg, uint8_t instanceId);
203
Sampa Misraaea5dde2020-08-31 08:33:47 -0500204} // namespace oem_ibm_platform
205
206} // namespace responder
207
208} // namespace pldm