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 | |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 50 | enum SetEventReceiverCount |
| 51 | { |
| 52 | SET_EVENT_RECEIVER_SENT = 0x2, |
| 53 | }; |
| 54 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 55 | class Handler : public oem_platform::Handler |
| 56 | { |
| 57 | public: |
| 58 | Handler(const pldm::utils::DBusHandler* dBusIntf, |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 59 | pldm::responder::CodeUpdate* codeUpdate, int mctp_fd, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 60 | uint8_t mctp_eid, pldm::dbus_api::Requester& requester, |
| 61 | sdeventplus::Event& event, |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 62 | pldm::requester::Handler<pldm::requester::Request>* handler) : |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 63 | oem_platform::Handler(dBusIntf), |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 64 | codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd), |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 65 | mctp_eid(mctp_eid), requester(requester), event(event), handler(handler) |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 66 | { |
| 67 | codeUpdate->setVersions(); |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 68 | setEventReceiverCnt = 0; |
| 69 | |
| 70 | using namespace sdbusplus::bus::match::rules; |
| 71 | hostOffMatch = std::make_unique<sdbusplus::bus::match::match>( |
| 72 | pldm::utils::DBusHandler::getBus(), |
| 73 | propertiesChanged("/xyz/openbmc_project/state/host0", |
| 74 | "xyz.openbmc_project.State.Host"), |
| 75 | [this](sdbusplus::message::message& msg) { |
| 76 | pldm::utils::DbusChangedProps props{}; |
| 77 | std::string intf; |
| 78 | msg.read(intf, props); |
| 79 | const auto itr = props.find("CurrentHostState"); |
| 80 | if (itr != props.end()) |
| 81 | { |
| 82 | pldm::utils::PropertyValue value = itr->second; |
| 83 | auto propVal = std::get<std::string>(value); |
| 84 | if (propVal == |
| 85 | "xyz.openbmc_project.State.Host.HostState.Off") |
| 86 | { |
| 87 | hostOff = true; |
| 88 | setEventReceiverCnt = 0; |
| 89 | disableWatchDogTimer(); |
| 90 | } |
| 91 | else if (propVal == |
| 92 | "xyz.openbmc_project.State.Host.HostState.Running") |
| 93 | { |
| 94 | hostOff = false; |
| 95 | } |
| 96 | } |
| 97 | }); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | int getOemStateSensorReadingsHandler( |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 101 | EntityType entityType, pldm::pdr::EntityInstance entityInstance, |
| 102 | pldm::pdr::StateSetId stateSetId, |
| 103 | pldm::pdr::CompositeCount compSensorCnt, |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 104 | std::vector<get_sensor_state_field>& stateField); |
| 105 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 106 | int oemSetStateEffecterStatesHandler( |
Varsha Kaverappa | 3fbd39e | 2020-09-28 01:40:22 -0500 | [diff] [blame] | 107 | uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId, |
| 108 | uint8_t compEffecterCnt, |
| 109 | std::vector<set_effecter_state_field>& stateField, uint16_t effecterId); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 110 | |
| 111 | /** @brief Method to set the platform handler in the |
| 112 | * oem_ibm_handler class |
| 113 | * @param[in] handler - pointer to PLDM platform handler |
| 114 | */ |
| 115 | void setPlatformHandler(pldm::responder::platform::Handler* handler); |
| 116 | |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 117 | /** @brief Method to fetch the effecter ID of the code update PDRs |
| 118 | * |
| 119 | * @return platformHandler->getNextEffecterId() - returns the |
| 120 | * effecter ID from the platform handler |
| 121 | */ |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 122 | virtual uint16_t getNextEffecterId() |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 123 | { |
| 124 | return platformHandler->getNextEffecterId(); |
| 125 | } |
| 126 | |
| 127 | /** @brief Method to fetch the sensor ID of the code update PDRs |
| 128 | * |
| 129 | * @return platformHandler->getNextSensorId() - returns the |
| 130 | * Sensor ID from the platform handler |
| 131 | */ |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 132 | virtual uint16_t getNextSensorId() |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 133 | { |
| 134 | return platformHandler->getNextSensorId(); |
| 135 | } |
| 136 | |
| 137 | /** @brief Method to Generate the OEM PDRs |
| 138 | * |
| 139 | * @param[in] repo - instance of concrete implementation of Repo |
| 140 | */ |
| 141 | void buildOEMPDR(pdr_utils::Repo& repo); |
| 142 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 143 | /** @brief Method to send code update event to host |
| 144 | * @param[in] sensorId - sendor ID |
| 145 | * @param[in] sensorEventClass - event class of sensor |
| 146 | * @param[in] sensorOffset - sensor offset |
| 147 | * @param[in] eventState - new code update event state |
| 148 | * @param[in] prevEventState - previous code update event state |
| 149 | * @return none |
| 150 | */ |
| 151 | void sendStateSensorEvent(uint16_t sensorId, |
| 152 | enum sensor_event_class_states sensorEventClass, |
| 153 | uint8_t sensorOffset, uint8_t eventState, |
| 154 | uint8_t prevEventState); |
| 155 | |
| 156 | /** @brief Method to send encoded request msg of code update event to host |
| 157 | * @param[in] requestMsg - encoded request msg |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 158 | * @param[in] instanceId - instance id of the message |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 159 | * @return PLDM status code |
| 160 | */ |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 161 | int sendEventToHost(std::vector<uint8_t>& requestMsg, uint8_t instanceId); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 162 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 163 | /** @brief _processEndUpdate processes the actual work that needs |
| 164 | * to be carried out after EndUpdate effecter is set. This is done async |
| 165 | * after sending response for EndUpdate set effecter |
| 166 | * @param[in] source - sdeventplus event source |
| 167 | */ |
| 168 | void _processEndUpdate(sdeventplus::source::EventBase& source); |
| 169 | |
| 170 | /** @brief _processStartUpdate processes the actual work that needs |
| 171 | * to be carried out after StartUpdate effecter is set. This is done async |
| 172 | * after sending response for StartUpdate set effecter |
| 173 | * @param[in] source - sdeventplus event source |
| 174 | */ |
| 175 | void _processStartUpdate(sdeventplus::source::EventBase& source); |
| 176 | |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 177 | /** @brief _processSystemReboot processes the actual work that needs to be |
| 178 | * carried out after the System Power State effecter is set to reboot |
| 179 | * the system |
| 180 | * @param[in] source - sdeventplus event source |
| 181 | */ |
| 182 | void _processSystemReboot(sdeventplus::source::EventBase& source); |
| 183 | |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 184 | /*keeps track how many times setEventReceiver is sent */ |
| 185 | void countSetEventReceiver() |
| 186 | { |
| 187 | setEventReceiverCnt++; |
| 188 | } |
| 189 | |
| 190 | /* disables watchdog if running and Host is up */ |
| 191 | void checkAndDisableWatchDog(); |
| 192 | |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 193 | /** @brief To check if the watchdog app is running |
| 194 | * |
| 195 | * @return the running status of watchdog app |
| 196 | */ |
| 197 | bool watchDogRunning(); |
| 198 | |
| 199 | /** @brief Method to reset the Watchdog timer on receiving platform Event |
| 200 | * Message for heartbeat elapsed time from Hostboot |
| 201 | */ |
| 202 | void resetWatchDogTimer(); |
| 203 | |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 204 | /** @brief To disable to the watchdog timer on host poweron completion*/ |
| 205 | void disableWatchDogTimer(); |
| 206 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 207 | ~Handler() = default; |
| 208 | |
| 209 | pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object |
| 210 | pldm::responder::platform::Handler* |
| 211 | platformHandler; //!< pointer to PLDM platform handler |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 212 | |
| 213 | /** @brief fd of MCTP communications socket */ |
| 214 | int mctp_fd; |
| 215 | |
| 216 | /** @brief MCTP EID of host firmware */ |
| 217 | uint8_t mctp_eid; |
| 218 | |
| 219 | /** @brief reference to Requester object, primarily used to access API to |
| 220 | * obtain PLDM instance id. |
| 221 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 222 | pldm::dbus_api::Requester& requester; |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 223 | /** @brief sdeventplus event source */ |
| 224 | std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent; |
| 225 | std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 226 | std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent; |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 227 | |
| 228 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 229 | * work |
| 230 | */ |
| 231 | sdeventplus::Event& event; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 232 | |
| 233 | private: |
| 234 | /** @brief D-Bus property changed signal match for CurrentPowerState*/ |
| 235 | std::unique_ptr<sdbusplus::bus::match::match> chassisOffMatch; |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 236 | |
| 237 | /** @brief PLDM request handler */ |
| 238 | pldm::requester::Handler<pldm::requester::Request>* handler; |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 239 | |
| 240 | /** @brief D-Bus property changed signal match */ |
| 241 | std::unique_ptr<sdbusplus::bus::match::match> hostOffMatch; |
| 242 | |
| 243 | bool hostOff = true; |
| 244 | |
| 245 | int setEventReceiverCnt = 0; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 246 | }; |
| 247 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 248 | /** @brief Method to encode code update event msg |
| 249 | * @param[in] eventType - type of event |
| 250 | * @param[in] eventDataVec - vector of event data to be sent to host |
| 251 | * @param[in/out] requestMsg - request msg to be encoded |
| 252 | * @param[in] instanceId - instance ID |
| 253 | * @return PLDM status code |
| 254 | */ |
| 255 | int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec, |
| 256 | std::vector<uint8_t>& requestMsg, uint8_t instanceId); |
| 257 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 258 | } // namespace oem_ibm_platform |
| 259 | |
| 260 | } // namespace responder |
| 261 | |
| 262 | } // namespace pldm |