Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 1 | #pragma once |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 2 | #include "libpldm/entity.h" |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 3 | #include "libpldm/platform.h" |
| 4 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 5 | #include "inband_code_update.hpp" |
| 6 | #include "libpldmresponder/oem_handler.hpp" |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 7 | #include "libpldmresponder/pdr_utils.hpp" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 8 | #include "libpldmresponder/platform.hpp" |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 9 | #include "requester/handler.hpp" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 10 | |
| 11 | namespace pldm |
| 12 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 13 | namespace responder |
| 14 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 15 | namespace oem_ibm_platform |
| 16 | { |
| 17 | |
| 18 | #define PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE 32768 |
| 19 | #define PLDM_OEM_IBM_BOOT_STATE 32769 |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 20 | #define PLDM_OEM_IBM_SYSTEM_POWER_STATE 32771 |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 21 | |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 22 | static constexpr auto PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE = 24577; |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 23 | static constexpr auto PLDM_OEM_IBM_VERIFICATION_STATE = 32770; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 24 | constexpr uint16_t ENTITY_INSTANCE_0 = 0; |
| 25 | constexpr uint16_t ENTITY_INSTANCE_1 = 1; |
| 26 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 27 | enum 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 Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 37 | enum VerificationStateValues |
| 38 | { |
| 39 | VALID = 0x0, |
| 40 | ENTITLEMENT_FAIL = 0x1, |
| 41 | BANNED_PLATFORM_FAIL = 0x2, |
| 42 | MIN_MIF_FAIL = 0x4, |
| 43 | }; |
| 44 | |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 45 | enum SystemPowerStates |
| 46 | { |
| 47 | POWER_CYCLE_HARD = 0x1, |
| 48 | }; |
| 49 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 50 | class Handler : public oem_platform::Handler |
| 51 | { |
| 52 | public: |
| 53 | Handler(const pldm::utils::DBusHandler* dBusIntf, |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 54 | pldm::responder::CodeUpdate* codeUpdate, int mctp_fd, |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 55 | uint8_t mctp_eid, Requester& requester, sdeventplus::Event& event, |
| 56 | pldm::requester::Handler<pldm::requester::Request>* handler) : |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 57 | oem_platform::Handler(dBusIntf), |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 58 | codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd), |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 59 | mctp_eid(mctp_eid), requester(requester), event(event), handler(handler) |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 60 | { |
| 61 | codeUpdate->setVersions(); |
| 62 | } |
| 63 | |
| 64 | int getOemStateSensorReadingsHandler( |
| 65 | EntityType entityType, EntityInstance entityInstance, |
| 66 | StateSetId stateSetId, CompositeCount compSensorCnt, |
| 67 | std::vector<get_sensor_state_field>& stateField); |
| 68 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 69 | int oemSetStateEffecterStatesHandler( |
Varsha Kaverappa | 3fbd39e | 2020-09-28 01:40:22 -0500 | [diff] [blame] | 70 | uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId, |
| 71 | uint8_t compEffecterCnt, |
| 72 | std::vector<set_effecter_state_field>& stateField, uint16_t effecterId); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 73 | |
| 74 | /** @brief Method to set the platform handler in the |
| 75 | * oem_ibm_handler class |
| 76 | * @param[in] handler - pointer to PLDM platform handler |
| 77 | */ |
| 78 | void setPlatformHandler(pldm::responder::platform::Handler* handler); |
| 79 | |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 80 | /** @brief Method to fetch the effecter ID of the code update PDRs |
| 81 | * |
| 82 | * @return platformHandler->getNextEffecterId() - returns the |
| 83 | * effecter ID from the platform handler |
| 84 | */ |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 85 | virtual uint16_t getNextEffecterId() |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 86 | { |
| 87 | return platformHandler->getNextEffecterId(); |
| 88 | } |
| 89 | |
| 90 | /** @brief Method to fetch the sensor ID of the code update PDRs |
| 91 | * |
| 92 | * @return platformHandler->getNextSensorId() - returns the |
| 93 | * Sensor ID from the platform handler |
| 94 | */ |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 95 | virtual uint16_t getNextSensorId() |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 96 | { |
| 97 | return platformHandler->getNextSensorId(); |
| 98 | } |
| 99 | |
| 100 | /** @brief Method to Generate the OEM PDRs |
| 101 | * |
| 102 | * @param[in] repo - instance of concrete implementation of Repo |
| 103 | */ |
| 104 | void buildOEMPDR(pdr_utils::Repo& repo); |
| 105 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 106 | /** @brief Method to send code update event to host |
| 107 | * @param[in] sensorId - sendor ID |
| 108 | * @param[in] sensorEventClass - event class of sensor |
| 109 | * @param[in] sensorOffset - sensor offset |
| 110 | * @param[in] eventState - new code update event state |
| 111 | * @param[in] prevEventState - previous code update event state |
| 112 | * @return none |
| 113 | */ |
| 114 | void sendStateSensorEvent(uint16_t sensorId, |
| 115 | enum sensor_event_class_states sensorEventClass, |
| 116 | uint8_t sensorOffset, uint8_t eventState, |
| 117 | uint8_t prevEventState); |
| 118 | |
| 119 | /** @brief Method to send encoded request msg of code update event to host |
| 120 | * @param[in] requestMsg - encoded request msg |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 121 | * @param[in] instanceId - instance id of the message |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 122 | * @return PLDM status code |
| 123 | */ |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 124 | int sendEventToHost(std::vector<uint8_t>& requestMsg, uint8_t instanceId); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 125 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 126 | /** @brief _processEndUpdate processes the actual work that needs |
| 127 | * to be carried out after EndUpdate effecter is set. This is done async |
| 128 | * after sending response for EndUpdate set effecter |
| 129 | * @param[in] source - sdeventplus event source |
| 130 | */ |
| 131 | void _processEndUpdate(sdeventplus::source::EventBase& source); |
| 132 | |
| 133 | /** @brief _processStartUpdate processes the actual work that needs |
| 134 | * to be carried out after StartUpdate effecter is set. This is done async |
| 135 | * after sending response for StartUpdate set effecter |
| 136 | * @param[in] source - sdeventplus event source |
| 137 | */ |
| 138 | void _processStartUpdate(sdeventplus::source::EventBase& source); |
| 139 | |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 140 | /** @brief _processSystemReboot processes the actual work that needs to be |
| 141 | * carried out after the System Power State effecter is set to reboot |
| 142 | * the system |
| 143 | * @param[in] source - sdeventplus event source |
| 144 | */ |
| 145 | void _processSystemReboot(sdeventplus::source::EventBase& source); |
| 146 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 147 | ~Handler() = default; |
| 148 | |
| 149 | pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object |
| 150 | pldm::responder::platform::Handler* |
| 151 | platformHandler; //!< pointer to PLDM platform handler |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 152 | |
| 153 | /** @brief fd of MCTP communications socket */ |
| 154 | int mctp_fd; |
| 155 | |
| 156 | /** @brief MCTP EID of host firmware */ |
| 157 | uint8_t mctp_eid; |
| 158 | |
| 159 | /** @brief reference to Requester object, primarily used to access API to |
| 160 | * obtain PLDM instance id. |
| 161 | */ |
| 162 | Requester& requester; |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 163 | /** @brief sdeventplus event source */ |
| 164 | std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent; |
| 165 | std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 166 | std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent; |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 167 | |
| 168 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 169 | * work |
| 170 | */ |
| 171 | sdeventplus::Event& event; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 172 | |
| 173 | private: |
| 174 | /** @brief D-Bus property changed signal match for CurrentPowerState*/ |
| 175 | std::unique_ptr<sdbusplus::bus::match::match> chassisOffMatch; |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 176 | |
| 177 | /** @brief PLDM request handler */ |
| 178 | pldm::requester::Handler<pldm::requester::Request>* handler; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 179 | }; |
| 180 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 181 | /** @brief Method to encode code update event msg |
| 182 | * @param[in] eventType - type of event |
| 183 | * @param[in] eventDataVec - vector of event data to be sent to host |
| 184 | * @param[in/out] requestMsg - request msg to be encoded |
| 185 | * @param[in] instanceId - instance ID |
| 186 | * @return PLDM status code |
| 187 | */ |
| 188 | int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec, |
| 189 | std::vector<uint8_t>& requestMsg, uint8_t instanceId); |
| 190 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 191 | } // namespace oem_ibm_platform |
| 192 | |
| 193 | } // namespace responder |
| 194 | |
| 195 | } // namespace pldm |