1 #pragma once 2 #include "libpldm/platform.h" 3 4 #include "inband_code_update.hpp" 5 #include "libpldmresponder/oem_handler.hpp" 6 #include "libpldmresponder/pdr_utils.hpp" 7 #include "libpldmresponder/platform.hpp" 8 9 namespace pldm 10 { 11 namespace responder 12 { 13 namespace oem_ibm_platform 14 { 15 16 #define PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE 32768 17 #define PLDM_OEM_IBM_BOOT_STATE 32769 18 19 static constexpr auto PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE = 24577; 20 static constexpr auto PLDM_OEM_IBM_VERIFICATION_STATE = 32770; 21 constexpr uint16_t ENTITY_INSTANCE_0 = 0; 22 constexpr uint16_t ENTITY_INSTANCE_1 = 1; 23 24 enum 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 34 enum VerificationStateValues 35 { 36 VALID = 0x0, 37 ENTITLEMENT_FAIL = 0x1, 38 BANNED_PLATFORM_FAIL = 0x2, 39 MIN_MIF_FAIL = 0x4, 40 }; 41 42 class Handler : public oem_platform::Handler 43 { 44 public: 45 Handler(const pldm::utils::DBusHandler* dBusIntf, 46 pldm::responder::CodeUpdate* codeUpdate, int mctp_fd, 47 uint8_t mctp_eid, Requester& requester, sdeventplus::Event& event) : 48 oem_platform::Handler(dBusIntf), 49 codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd), 50 mctp_eid(mctp_eid), requester(requester), event(event) 51 { 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 60 int oemSetStateEffecterStatesHandler( 61 uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId, 62 uint8_t compEffecterCnt, 63 std::vector<set_effecter_state_field>& stateField, uint16_t effecterId); 64 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 71 /** @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 97 /** @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 116 /** @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 130 ~Handler() = default; 131 132 pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object 133 pldm::responder::platform::Handler* 134 platformHandler; //!< pointer to PLDM platform handler 135 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; 146 /** @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; 154 }; 155 156 /** @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 */ 163 int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec, 164 std::vector<uint8_t>& requestMsg, uint8_t instanceId); 165 166 } // namespace oem_ibm_platform 167 168 } // namespace responder 169 170 } // namespace pldm 171