blob: 854c96bcec546a2a65687fe4775666908a9d309d [file] [log] [blame]
Sampa Misraaea5dde2020-08-31 08:33:47 -05001#pragma once
Varsha Kaverappabb585b22020-09-10 06:15:42 -05002#include "libpldm/platform.h"
3
Sampa Misraaea5dde2020-08-31 08:33:47 -05004#include "inband_code_update.hpp"
5#include "libpldmresponder/oem_handler.hpp"
Varsha Kaverappabb585b22020-09-10 06:15:42 -05006#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -05007#include "libpldmresponder/platform.hpp"
8
9namespace pldm
10{
Sampa Misraaea5dde2020-08-31 08:33:47 -050011namespace responder
12{
Sampa Misraaea5dde2020-08-31 08:33:47 -050013namespace oem_ibm_platform
14{
15
16#define PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE 32768
17#define PLDM_OEM_IBM_BOOT_STATE 32769
18
Sagar Srinivas78a225a2020-08-27 00:52:20 -050019static constexpr auto PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE = 24577;
Sampa Misra3a0e3b92020-10-21 05:58:00 -050020static constexpr auto PLDM_OEM_IBM_VERIFICATION_STATE = 32770;
Sagar Srinivas78a225a2020-08-27 00:52:20 -050021constexpr uint16_t ENTITY_INSTANCE_0 = 0;
22constexpr uint16_t ENTITY_INSTANCE_1 = 1;
23
Varsha Kaverappabb585b22020-09-10 06:15:42 -050024enum class CodeUpdateState : uint8_t
25{
26 START = 0x1,
27 END = 0x2,
28 FAIL = 0x3,
29 ABORT = 0x4,
30 ACCEPT = 0x5,
31 REJECT = 0x6
32};
33
Sampa Misra3a0e3b92020-10-21 05:58:00 -050034enum VerificationStateValues
35{
36 VALID = 0x0,
37 ENTITLEMENT_FAIL = 0x1,
38 BANNED_PLATFORM_FAIL = 0x2,
39 MIN_MIF_FAIL = 0x4,
40};
41
Sampa Misraaea5dde2020-08-31 08:33:47 -050042class Handler : public oem_platform::Handler
43{
44 public:
45 Handler(const pldm::utils::DBusHandler* dBusIntf,
Varsha Kaverappabb585b22020-09-10 06:15:42 -050046 pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
Sampa Misra3a0e3b92020-10-21 05:58:00 -050047 uint8_t mctp_eid, Requester& requester, sdeventplus::Event& event) :
Sampa Misraaea5dde2020-08-31 08:33:47 -050048 oem_platform::Handler(dBusIntf),
Varsha Kaverappabb585b22020-09-10 06:15:42 -050049 codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
Sampa Misra3a0e3b92020-10-21 05:58:00 -050050 mctp_eid(mctp_eid), requester(requester), event(event)
Sampa Misraaea5dde2020-08-31 08:33:47 -050051 {
52 codeUpdate->setVersions();
53 }
54
55 int getOemStateSensorReadingsHandler(
56 EntityType entityType, EntityInstance entityInstance,
57 StateSetId stateSetId, CompositeCount compSensorCnt,
58 std::vector<get_sensor_state_field>& stateField);
59
Sampa Misra3a0e3b92020-10-21 05:58:00 -050060 int oemSetStateEffecterStatesHandler(
Varsha Kaverappa3fbd39e2020-09-28 01:40:22 -050061 uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId,
62 uint8_t compEffecterCnt,
63 std::vector<set_effecter_state_field>& stateField, uint16_t effecterId);
Sampa Misraaea5dde2020-08-31 08:33:47 -050064
65 /** @brief Method to set the platform handler in the
66 * oem_ibm_handler class
67 * @param[in] handler - pointer to PLDM platform handler
68 */
69 void setPlatformHandler(pldm::responder::platform::Handler* handler);
70
Sagar Srinivas78a225a2020-08-27 00:52:20 -050071 /** @brief Method to fetch the effecter ID of the code update PDRs
72 *
73 * @return platformHandler->getNextEffecterId() - returns the
74 * effecter ID from the platform handler
75 */
76 uint16_t getNextEffecterId()
77 {
78 return platformHandler->getNextEffecterId();
79 }
80
81 /** @brief Method to fetch the sensor ID of the code update PDRs
82 *
83 * @return platformHandler->getNextSensorId() - returns the
84 * Sensor ID from the platform handler
85 */
86 uint16_t getNextSensorId()
87 {
88 return platformHandler->getNextSensorId();
89 }
90
91 /** @brief Method to Generate the OEM PDRs
92 *
93 * @param[in] repo - instance of concrete implementation of Repo
94 */
95 void buildOEMPDR(pdr_utils::Repo& repo);
96
Varsha Kaverappabb585b22020-09-10 06:15:42 -050097 /** @brief Method to send code update event to host
98 * @param[in] sensorId - sendor ID
99 * @param[in] sensorEventClass - event class of sensor
100 * @param[in] sensorOffset - sensor offset
101 * @param[in] eventState - new code update event state
102 * @param[in] prevEventState - previous code update event state
103 * @return none
104 */
105 void sendStateSensorEvent(uint16_t sensorId,
106 enum sensor_event_class_states sensorEventClass,
107 uint8_t sensorOffset, uint8_t eventState,
108 uint8_t prevEventState);
109
110 /** @brief Method to send encoded request msg of code update event to host
111 * @param[in] requestMsg - encoded request msg
112 * @return PLDM status code
113 */
114 int sendEventToHost(std::vector<uint8_t>& requestMsg);
115
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500116 /** @brief _processEndUpdate processes the actual work that needs
117 * to be carried out after EndUpdate effecter is set. This is done async
118 * after sending response for EndUpdate set effecter
119 * @param[in] source - sdeventplus event source
120 */
121 void _processEndUpdate(sdeventplus::source::EventBase& source);
122
123 /** @brief _processStartUpdate processes the actual work that needs
124 * to be carried out after StartUpdate effecter is set. This is done async
125 * after sending response for StartUpdate set effecter
126 * @param[in] source - sdeventplus event source
127 */
128 void _processStartUpdate(sdeventplus::source::EventBase& source);
129
Sampa Misraaea5dde2020-08-31 08:33:47 -0500130 ~Handler() = default;
131
132 pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
133 pldm::responder::platform::Handler*
134 platformHandler; //!< pointer to PLDM platform handler
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500135
136 /** @brief fd of MCTP communications socket */
137 int mctp_fd;
138
139 /** @brief MCTP EID of host firmware */
140 uint8_t mctp_eid;
141
142 /** @brief reference to Requester object, primarily used to access API to
143 * obtain PLDM instance id.
144 */
145 Requester& requester;
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500146 /** @brief sdeventplus event source */
147 std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent;
148 std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent;
149
150 /** @brief reference of main event loop of pldmd, primarily used to schedule
151 * work
152 */
153 sdeventplus::Event& event;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500154};
155
Varsha Kaverappabb585b22020-09-10 06:15:42 -0500156/** @brief Method to encode code update event msg
157 * @param[in] eventType - type of event
158 * @param[in] eventDataVec - vector of event data to be sent to host
159 * @param[in/out] requestMsg - request msg to be encoded
160 * @param[in] instanceId - instance ID
161 * @return PLDM status code
162 */
163int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec,
164 std::vector<uint8_t>& requestMsg, uint8_t instanceId);
165
Sampa Misraaea5dde2020-08-31 08:33:47 -0500166} // namespace oem_ibm_platform
167
168} // namespace responder
169
170} // namespace pldm