blob: ee1081eabf4513888b1c9134459aac07ae66f407 [file] [log] [blame]
#pragma once
#include "libpldm/entity.h"
#include "libpldm/platform.h"
#include "inband_code_update.hpp"
#include "libpldmresponder/oem_handler.hpp"
#include "libpldmresponder/pdr_utils.hpp"
#include "libpldmresponder/platform.hpp"
namespace pldm
{
namespace responder
{
namespace oem_ibm_platform
{
#define PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE 32768
#define PLDM_OEM_IBM_BOOT_STATE 32769
#define PLDM_OEM_IBM_SYSTEM_POWER_STATE 32771
static constexpr auto PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE = 24577;
static constexpr auto PLDM_OEM_IBM_VERIFICATION_STATE = 32770;
constexpr uint16_t ENTITY_INSTANCE_0 = 0;
constexpr uint16_t ENTITY_INSTANCE_1 = 1;
enum class CodeUpdateState : uint8_t
{
START = 0x1,
END = 0x2,
FAIL = 0x3,
ABORT = 0x4,
ACCEPT = 0x5,
REJECT = 0x6
};
enum VerificationStateValues
{
VALID = 0x0,
ENTITLEMENT_FAIL = 0x1,
BANNED_PLATFORM_FAIL = 0x2,
MIN_MIF_FAIL = 0x4,
};
enum SystemPowerStates
{
POWER_CYCLE_HARD = 0x1,
};
class Handler : public oem_platform::Handler
{
public:
Handler(const pldm::utils::DBusHandler* dBusIntf,
pldm::responder::CodeUpdate* codeUpdate, int mctp_fd,
uint8_t mctp_eid, Requester& requester, sdeventplus::Event& event) :
oem_platform::Handler(dBusIntf),
codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd),
mctp_eid(mctp_eid), requester(requester), event(event)
{
codeUpdate->setVersions();
}
int getOemStateSensorReadingsHandler(
EntityType entityType, EntityInstance entityInstance,
StateSetId stateSetId, CompositeCount compSensorCnt,
std::vector<get_sensor_state_field>& stateField);
int oemSetStateEffecterStatesHandler(
uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId,
uint8_t compEffecterCnt,
std::vector<set_effecter_state_field>& stateField, uint16_t effecterId);
/** @brief Method to set the platform handler in the
* oem_ibm_handler class
* @param[in] handler - pointer to PLDM platform handler
*/
void setPlatformHandler(pldm::responder::platform::Handler* handler);
/** @brief Method to fetch the effecter ID of the code update PDRs
*
* @return platformHandler->getNextEffecterId() - returns the
* effecter ID from the platform handler
*/
virtual uint16_t getNextEffecterId()
{
return platformHandler->getNextEffecterId();
}
/** @brief Method to fetch the sensor ID of the code update PDRs
*
* @return platformHandler->getNextSensorId() - returns the
* Sensor ID from the platform handler
*/
virtual uint16_t getNextSensorId()
{
return platformHandler->getNextSensorId();
}
/** @brief Method to Generate the OEM PDRs
*
* @param[in] repo - instance of concrete implementation of Repo
*/
void buildOEMPDR(pdr_utils::Repo& repo);
/** @brief Method to send code update event to host
* @param[in] sensorId - sendor ID
* @param[in] sensorEventClass - event class of sensor
* @param[in] sensorOffset - sensor offset
* @param[in] eventState - new code update event state
* @param[in] prevEventState - previous code update event state
* @return none
*/
void sendStateSensorEvent(uint16_t sensorId,
enum sensor_event_class_states sensorEventClass,
uint8_t sensorOffset, uint8_t eventState,
uint8_t prevEventState);
/** @brief Method to send encoded request msg of code update event to host
* @param[in] requestMsg - encoded request msg
* @return PLDM status code
*/
int sendEventToHost(std::vector<uint8_t>& requestMsg);
/** @brief _processEndUpdate processes the actual work that needs
* to be carried out after EndUpdate effecter is set. This is done async
* after sending response for EndUpdate set effecter
* @param[in] source - sdeventplus event source
*/
void _processEndUpdate(sdeventplus::source::EventBase& source);
/** @brief _processStartUpdate processes the actual work that needs
* to be carried out after StartUpdate effecter is set. This is done async
* after sending response for StartUpdate set effecter
* @param[in] source - sdeventplus event source
*/
void _processStartUpdate(sdeventplus::source::EventBase& source);
/** @brief _processSystemReboot processes the actual work that needs to be
* carried out after the System Power State effecter is set to reboot
* the system
* @param[in] source - sdeventplus event source
*/
void _processSystemReboot(sdeventplus::source::EventBase& source);
~Handler() = default;
pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object
pldm::responder::platform::Handler*
platformHandler; //!< pointer to PLDM platform handler
/** @brief fd of MCTP communications socket */
int mctp_fd;
/** @brief MCTP EID of host firmware */
uint8_t mctp_eid;
/** @brief reference to Requester object, primarily used to access API to
* obtain PLDM instance id.
*/
Requester& requester;
/** @brief sdeventplus event source */
std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent;
std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent;
std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent;
/** @brief reference of main event loop of pldmd, primarily used to schedule
* work
*/
sdeventplus::Event& event;
private:
/** @brief D-Bus property changed signal match for CurrentPowerState*/
std::unique_ptr<sdbusplus::bus::match::match> chassisOffMatch;
};
/** @brief Method to encode code update event msg
* @param[in] eventType - type of event
* @param[in] eventDataVec - vector of event data to be sent to host
* @param[in/out] requestMsg - request msg to be encoded
* @param[in] instanceId - instance ID
* @return PLDM status code
*/
int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec,
std::vector<uint8_t>& requestMsg, uint8_t instanceId);
} // namespace oem_ibm_platform
} // namespace responder
} // namespace pldm