Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 1 | #include "oem_ibm_handler.hpp" |
| 2 | |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 3 | #include "file_io_type_lid.hpp" |
| 4 | #include "libpldmresponder/file_io.hpp" |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 5 | #include "libpldmresponder/pdr_utils.hpp" |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 6 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 7 | #include <libpldm/entity.h> |
Brad Bishop | 27403f4 | 2021-12-01 21:37:44 -0500 | [diff] [blame] | 8 | #include <libpldm/entity_oem_ibm.h> |
| 9 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 10 | #include <phosphor-logging/lg2.hpp> |
| 11 | |
| 12 | PHOSPHOR_LOG2_USING; |
| 13 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 14 | using namespace pldm::pdr; |
| 15 | using namespace pldm::utils; |
| 16 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 17 | namespace pldm |
| 18 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 19 | namespace responder |
| 20 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 21 | namespace oem_ibm_platform |
| 22 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 23 | int pldm::responder::oem_ibm_platform::Handler:: |
| 24 | getOemStateSensorReadingsHandler( |
| 25 | EntityType entityType, EntityInstance entityInstance, |
| 26 | StateSetId stateSetId, CompositeCount compSensorCnt, |
| 27 | std::vector<get_sensor_state_field>& stateField) |
| 28 | { |
| 29 | int rc = PLDM_SUCCESS; |
| 30 | stateField.clear(); |
| 31 | |
| 32 | for (size_t i = 0; i < compSensorCnt; i++) |
| 33 | { |
| 34 | uint8_t sensorOpState{}; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 35 | if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 36 | stateSetId == PLDM_OEM_IBM_BOOT_STATE) |
| 37 | { |
| 38 | sensorOpState = fetchBootSide(entityInstance, codeUpdate); |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | rc = PLDM_PLATFORM_INVALID_STATE_VALUE; |
| 43 | break; |
| 44 | } |
| 45 | stateField.push_back({PLDM_SENSOR_ENABLED, PLDM_SENSOR_UNKNOWN, |
| 46 | PLDM_SENSOR_UNKNOWN, sensorOpState}); |
| 47 | } |
| 48 | return rc; |
| 49 | } |
| 50 | |
| 51 | int pldm::responder::oem_ibm_platform::Handler:: |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 52 | oemSetStateEffecterStatesHandler( |
Varsha Kaverappa | 3fbd39e | 2020-09-28 01:40:22 -0500 | [diff] [blame] | 53 | uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId, |
| 54 | uint8_t compEffecterCnt, |
| 55 | std::vector<set_effecter_state_field>& stateField, |
| 56 | uint16_t /*effecterId*/) |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 57 | { |
| 58 | int rc = PLDM_SUCCESS; |
| 59 | |
| 60 | for (uint8_t currState = 0; currState < compEffecterCnt; ++currState) |
| 61 | { |
| 62 | if (stateField[currState].set_request == PLDM_REQUEST_SET) |
| 63 | { |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 64 | if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 65 | stateSetId == PLDM_OEM_IBM_BOOT_STATE) |
| 66 | { |
| 67 | rc = setBootSide(entityInstance, currState, stateField, |
| 68 | codeUpdate); |
| 69 | } |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 70 | else if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && |
| 71 | stateSetId == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) |
| 72 | { |
| 73 | if (stateField[currState].effecter_state == |
| 74 | uint8_t(CodeUpdateState::START)) |
| 75 | { |
| 76 | codeUpdate->setCodeUpdateProgress(true); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 77 | startUpdateEvent = |
| 78 | std::make_unique<sdeventplus::source::Defer>( |
| 79 | event, |
| 80 | std::bind(std::mem_fn(&oem_ibm_platform::Handler:: |
| 81 | _processStartUpdate), |
| 82 | this, std::placeholders::_1)); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 83 | } |
| 84 | else if (stateField[currState].effecter_state == |
| 85 | uint8_t(CodeUpdateState::END)) |
| 86 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 87 | rc = PLDM_SUCCESS; |
| 88 | assembleImageEvent = std::make_unique< |
| 89 | sdeventplus::source::Defer>( |
| 90 | event, |
| 91 | std::bind( |
| 92 | std::mem_fn( |
| 93 | &oem_ibm_platform::Handler::_processEndUpdate), |
| 94 | this, std::placeholders::_1)); |
| 95 | |
| 96 | // sendCodeUpdateEvent(effecterId, END, START); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 97 | } |
| 98 | else if (stateField[currState].effecter_state == |
| 99 | uint8_t(CodeUpdateState::ABORT)) |
| 100 | { |
| 101 | codeUpdate->setCodeUpdateProgress(false); |
| 102 | codeUpdate->clearDirPath(LID_STAGING_DIR); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 103 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 104 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, |
| 105 | uint8_t(CodeUpdateState::ABORT), |
| 106 | uint8_t(CodeUpdateState::START)); |
| 107 | // sendCodeUpdateEvent(effecterId, ABORT, END); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 108 | } |
| 109 | else if (stateField[currState].effecter_state == |
| 110 | uint8_t(CodeUpdateState::ACCEPT)) |
| 111 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 112 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 113 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, |
| 114 | uint8_t(CodeUpdateState::ACCEPT), |
| 115 | uint8_t(CodeUpdateState::END)); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 116 | // TODO Set new Dbus property provided by code update app |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 117 | // sendCodeUpdateEvent(effecterId, ACCEPT, END); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 118 | } |
| 119 | else if (stateField[currState].effecter_state == |
| 120 | uint8_t(CodeUpdateState::REJECT)) |
| 121 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 122 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 123 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, |
| 124 | uint8_t(CodeUpdateState::REJECT), |
| 125 | uint8_t(CodeUpdateState::END)); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 126 | // TODO Set new Dbus property provided by code update app |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 127 | // sendCodeUpdateEvent(effecterId, REJECT, END); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 128 | } |
| 129 | } |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 130 | else if (entityType == PLDM_ENTITY_SYSTEM_CHASSIS && |
| 131 | stateSetId == PLDM_OEM_IBM_SYSTEM_POWER_STATE) |
| 132 | { |
| 133 | if (stateField[currState].effecter_state == POWER_CYCLE_HARD) |
| 134 | { |
| 135 | systemRebootEvent = |
| 136 | std::make_unique<sdeventplus::source::Defer>( |
| 137 | event, |
| 138 | std::bind(std::mem_fn(&oem_ibm_platform::Handler:: |
| 139 | _processSystemReboot), |
| 140 | this, std::placeholders::_1)); |
| 141 | } |
| 142 | } |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 143 | else |
| 144 | { |
| 145 | rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE; |
| 146 | } |
| 147 | } |
| 148 | if (rc != PLDM_SUCCESS) |
| 149 | { |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | return rc; |
| 154 | } |
| 155 | |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 156 | void buildAllCodeUpdateEffecterPDR(oem_ibm_platform::Handler* platformHandler, |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 157 | uint16_t entityType, uint16_t entityInstance, |
| 158 | uint16_t stateSetID, pdr_utils::Repo& repo) |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 159 | { |
| 160 | size_t pdrSize = 0; |
| 161 | pdrSize = sizeof(pldm_state_effecter_pdr) + |
| 162 | sizeof(state_effecter_possible_states); |
| 163 | std::vector<uint8_t> entry{}; |
| 164 | entry.resize(pdrSize); |
| 165 | pldm_state_effecter_pdr* pdr = |
| 166 | reinterpret_cast<pldm_state_effecter_pdr*>(entry.data()); |
| 167 | if (!pdr) |
| 168 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 169 | error("Failed to get record by PDR type, ERROR:{ERR_CODE}", "ERR_CODE", |
| 170 | lg2::hex, |
| 171 | static_cast<unsigned>(PLDM_PLATFORM_INVALID_EFFECTER_ID)); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 172 | return; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 173 | } |
| 174 | pdr->hdr.record_handle = 0; |
| 175 | pdr->hdr.version = 1; |
| 176 | pdr->hdr.type = PLDM_STATE_EFFECTER_PDR; |
| 177 | pdr->hdr.record_change_num = 0; |
| 178 | pdr->hdr.length = sizeof(pldm_state_effecter_pdr) - sizeof(pldm_pdr_hdr); |
Manojkiran Eda | cc5f158 | 2021-09-29 17:03:06 +0530 | [diff] [blame] | 179 | pdr->terminus_handle = TERMINUS_HANDLE; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 180 | pdr->effecter_id = platformHandler->getNextEffecterId(); |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 181 | pdr->entity_type = entityType; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 182 | pdr->entity_instance = entityInstance; |
Sagar Srinivas | 97296e0 | 2021-08-26 09:40:41 -0500 | [diff] [blame] | 183 | pdr->container_id = 1; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 184 | pdr->effecter_semantic_id = 0; |
| 185 | pdr->effecter_init = PLDM_NO_INIT; |
| 186 | pdr->has_description_pdr = false; |
| 187 | pdr->composite_effecter_count = 1; |
| 188 | |
| 189 | auto* possibleStatesPtr = pdr->possible_states; |
| 190 | auto possibleStates = |
| 191 | reinterpret_cast<state_effecter_possible_states*>(possibleStatesPtr); |
| 192 | possibleStates->state_set_id = stateSetID; |
| 193 | possibleStates->possible_states_size = 2; |
| 194 | auto state = |
| 195 | reinterpret_cast<state_effecter_possible_states*>(possibleStates); |
| 196 | if (stateSetID == PLDM_OEM_IBM_BOOT_STATE) |
| 197 | state->states[0].byte = 6; |
| 198 | else if (stateSetID == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) |
| 199 | state->states[0].byte = 126; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 200 | else if (stateSetID == PLDM_OEM_IBM_SYSTEM_POWER_STATE) |
| 201 | state->states[0].byte = 2; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 202 | pldm::responder::pdr_utils::PdrEntry pdrEntry{}; |
| 203 | pdrEntry.data = entry.data(); |
| 204 | pdrEntry.size = pdrSize; |
| 205 | repo.addRecord(pdrEntry); |
| 206 | } |
| 207 | |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 208 | void buildAllCodeUpdateSensorPDR(oem_ibm_platform::Handler* platformHandler, |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 209 | uint16_t entityType, uint16_t entityInstance, |
| 210 | uint16_t stateSetID, pdr_utils::Repo& repo) |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 211 | { |
| 212 | size_t pdrSize = 0; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 213 | pdrSize = sizeof(pldm_state_sensor_pdr) + |
| 214 | sizeof(state_sensor_possible_states); |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 215 | std::vector<uint8_t> entry{}; |
| 216 | entry.resize(pdrSize); |
| 217 | pldm_state_sensor_pdr* pdr = |
| 218 | reinterpret_cast<pldm_state_sensor_pdr*>(entry.data()); |
| 219 | if (!pdr) |
| 220 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 221 | error("Failed to get record by PDR type, ERROR:{ERR_CODE}", "ERR_CODE", |
| 222 | lg2::hex, static_cast<unsigned>(PLDM_PLATFORM_INVALID_SENSOR_ID)); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 223 | return; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 224 | } |
| 225 | pdr->hdr.record_handle = 0; |
| 226 | pdr->hdr.version = 1; |
| 227 | pdr->hdr.type = PLDM_STATE_SENSOR_PDR; |
| 228 | pdr->hdr.record_change_num = 0; |
| 229 | pdr->hdr.length = sizeof(pldm_state_sensor_pdr) - sizeof(pldm_pdr_hdr); |
Manojkiran Eda | cc5f158 | 2021-09-29 17:03:06 +0530 | [diff] [blame] | 230 | pdr->terminus_handle = TERMINUS_HANDLE; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 231 | pdr->sensor_id = platformHandler->getNextSensorId(); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 232 | pdr->entity_type = entityType; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 233 | pdr->entity_instance = entityInstance; |
Sagar Srinivas | 97296e0 | 2021-08-26 09:40:41 -0500 | [diff] [blame] | 234 | pdr->container_id = 1; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 235 | pdr->sensor_init = PLDM_NO_INIT; |
| 236 | pdr->sensor_auxiliary_names_pdr = false; |
| 237 | pdr->composite_sensor_count = 1; |
| 238 | |
| 239 | auto* possibleStatesPtr = pdr->possible_states; |
| 240 | auto possibleStates = |
| 241 | reinterpret_cast<state_sensor_possible_states*>(possibleStatesPtr); |
| 242 | possibleStates->state_set_id = stateSetID; |
| 243 | possibleStates->possible_states_size = 2; |
| 244 | auto state = |
| 245 | reinterpret_cast<state_sensor_possible_states*>(possibleStates); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 246 | if ((stateSetID == PLDM_OEM_IBM_BOOT_STATE) || |
Christian Geddes | 7f9523c | 2021-08-03 13:44:38 -0500 | [diff] [blame] | 247 | (stateSetID == PLDM_OEM_IBM_VERIFICATION_STATE)) |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 248 | state->states[0].byte = 6; |
| 249 | else if (stateSetID == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) |
| 250 | state->states[0].byte = 126; |
| 251 | pldm::responder::pdr_utils::PdrEntry pdrEntry{}; |
| 252 | pdrEntry.data = entry.data(); |
| 253 | pdrEntry.size = pdrSize; |
| 254 | repo.addRecord(pdrEntry); |
| 255 | } |
| 256 | |
| 257 | void pldm::responder::oem_ibm_platform::Handler::buildOEMPDR( |
| 258 | pdr_utils::Repo& repo) |
| 259 | { |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 260 | buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 261 | ENTITY_INSTANCE_0, PLDM_OEM_IBM_BOOT_STATE, |
| 262 | repo); |
| 263 | buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 264 | ENTITY_INSTANCE_1, PLDM_OEM_IBM_BOOT_STATE, |
| 265 | repo); |
| 266 | buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 267 | ENTITY_INSTANCE_0, |
| 268 | PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, repo); |
| 269 | buildAllCodeUpdateEffecterPDR(this, PLDM_ENTITY_SYSTEM_CHASSIS, |
Sagar Srinivas | 1b8d35f | 2021-11-10 10:54:40 -0600 | [diff] [blame] | 270 | ENTITY_INSTANCE_1, |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 271 | PLDM_OEM_IBM_SYSTEM_POWER_STATE, repo); |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 272 | |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 273 | buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 274 | ENTITY_INSTANCE_0, PLDM_OEM_IBM_BOOT_STATE, |
| 275 | repo); |
| 276 | buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 277 | ENTITY_INSTANCE_1, PLDM_OEM_IBM_BOOT_STATE, |
| 278 | repo); |
| 279 | buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 280 | ENTITY_INSTANCE_0, |
| 281 | PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, repo); |
| 282 | buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 283 | ENTITY_INSTANCE_0, |
| 284 | PLDM_OEM_IBM_VERIFICATION_STATE, repo); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 285 | auto sensorId = findStateSensorId( |
| 286 | repo.getPdr(), 0, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
Sagar Srinivas | f4a7dd7 | 2021-10-20 04:45:37 -0500 | [diff] [blame] | 287 | ENTITY_INSTANCE_0, 1, PLDM_OEM_IBM_VERIFICATION_STATE); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 288 | codeUpdate->setMarkerLidSensor(sensorId); |
| 289 | sensorId = findStateSensorId( |
| 290 | repo.getPdr(), 0, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
Sagar Srinivas | f4a7dd7 | 2021-10-20 04:45:37 -0500 | [diff] [blame] | 291 | ENTITY_INSTANCE_0, 1, PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 292 | codeUpdate->setFirmwareUpdateSensor(sensorId); |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 293 | } |
| 294 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 295 | void pldm::responder::oem_ibm_platform::Handler::setPlatformHandler( |
| 296 | pldm::responder::platform::Handler* handler) |
| 297 | { |
| 298 | platformHandler = handler; |
| 299 | } |
| 300 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 301 | int pldm::responder::oem_ibm_platform::Handler::sendEventToHost( |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 302 | std::vector<uint8_t>& requestMsg, uint8_t instanceId) |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 303 | { |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 304 | if (requestMsg.size()) |
| 305 | { |
| 306 | std::ostringstream tempStream; |
| 307 | for (int byte : requestMsg) |
| 308 | { |
| 309 | tempStream << std::setfill('0') << std::setw(2) << std::hex << byte |
| 310 | << " "; |
| 311 | } |
| 312 | std::cout << tempStream.str() << std::endl; |
| 313 | } |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 314 | auto oemPlatformEventMessageResponseHandler = |
| 315 | [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 316 | uint8_t completionCode{}; |
| 317 | uint8_t status{}; |
| 318 | auto rc = decode_platform_event_message_resp(response, respMsgLen, |
| 319 | &completionCode, &status); |
| 320 | if (rc || completionCode) |
| 321 | { |
| 322 | error( |
| 323 | "Failed to decode_platform_event_message_resp: for code update event rc={RC}, cc={CC}", |
| 324 | "RC", rc, "CC", static_cast<unsigned>(completionCode)); |
| 325 | } |
| 326 | }; |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 327 | auto rc = handler->registerRequest( |
| 328 | mctp_eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE, |
| 329 | std::move(requestMsg), |
| 330 | std::move(oemPlatformEventMessageResponseHandler)); |
| 331 | if (rc) |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 332 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 333 | error("Failed to send BIOS attribute change event message "); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 334 | } |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 335 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 336 | return rc; |
| 337 | } |
| 338 | |
| 339 | int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec, |
| 340 | std::vector<uint8_t>& requestMsg, uint8_t instanceId) |
| 341 | { |
| 342 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 343 | |
| 344 | auto rc = encode_platform_event_message_req( |
ArchanaKakani | 6c39c7a | 2022-12-05 04:36:35 -0600 | [diff] [blame] | 345 | instanceId, 1 /*formatVersion*/, TERMINUS_ID /*tId*/, eventType, |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 346 | eventDataVec.data(), eventDataVec.size(), request, |
| 347 | eventDataVec.size() + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 348 | |
| 349 | return rc; |
| 350 | } |
| 351 | |
| 352 | void pldm::responder::oem_ibm_platform::Handler::sendStateSensorEvent( |
| 353 | uint16_t sensorId, enum sensor_event_class_states sensorEventClass, |
| 354 | uint8_t sensorOffset, uint8_t eventState, uint8_t prevEventState) |
| 355 | { |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 356 | std::vector<uint8_t> sensorEventDataVec{}; |
| 357 | size_t sensorEventSize = PLDM_SENSOR_EVENT_DATA_MIN_LENGTH + 1; |
| 358 | sensorEventDataVec.resize(sensorEventSize); |
| 359 | auto eventData = reinterpret_cast<struct pldm_sensor_event_data*>( |
| 360 | sensorEventDataVec.data()); |
| 361 | eventData->sensor_id = sensorId; |
| 362 | eventData->sensor_event_class_type = sensorEventClass; |
| 363 | auto eventClassStart = eventData->event_class; |
| 364 | auto eventClass = |
| 365 | reinterpret_cast<struct pldm_sensor_event_state_sensor_state*>( |
| 366 | eventClassStart); |
| 367 | eventClass->sensor_offset = sensorOffset; |
| 368 | eventClass->event_state = eventState; |
| 369 | eventClass->previous_event_state = prevEventState; |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 370 | auto instanceId = instanceIdDb.next(mctp_eid); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 371 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 372 | PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + |
| 373 | sensorEventDataVec.size()); |
| 374 | auto rc = encodeEventMsg(PLDM_SENSOR_EVENT, sensorEventDataVec, requestMsg, |
| 375 | instanceId); |
| 376 | if (rc != PLDM_SUCCESS) |
| 377 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 378 | error("Failed to encode state sensor event, rc = {RC}", "RC", rc); |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 379 | instanceIdDb.free(mctp_eid, instanceId); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 380 | return; |
| 381 | } |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 382 | rc = sendEventToHost(requestMsg, instanceId); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 383 | if (rc != PLDM_SUCCESS) |
| 384 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 385 | error("Failed to send event to host: rc={RC}", "RC", rc); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 386 | } |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 387 | return; |
| 388 | } |
| 389 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 390 | void pldm::responder::oem_ibm_platform::Handler::_processEndUpdate( |
| 391 | sdeventplus::source::EventBase& /*source */) |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 392 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 393 | assembleImageEvent.reset(); |
Adriana Kobylak | 9296f24 | 2021-09-22 15:52:00 +0000 | [diff] [blame] | 394 | int retc = codeUpdate->assembleCodeUpdateImage(); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 395 | if (retc != PLDM_SUCCESS) |
| 396 | { |
| 397 | codeUpdate->setCodeUpdateProgress(false); |
| 398 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 399 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, |
| 400 | uint8_t(CodeUpdateState::FAIL), |
| 401 | uint8_t(CodeUpdateState::START)); |
| 402 | } |
| 403 | } |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 404 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 405 | void pldm::responder::oem_ibm_platform::Handler::_processStartUpdate( |
| 406 | sdeventplus::source::EventBase& /*source */) |
| 407 | { |
| 408 | codeUpdate->deleteImage(); |
| 409 | CodeUpdateState state = CodeUpdateState::START; |
| 410 | auto rc = codeUpdate->setRequestedApplyTime(); |
| 411 | if (rc != PLDM_SUCCESS) |
| 412 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 413 | error("setRequestedApplyTime failed"); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 414 | state = CodeUpdateState::FAIL; |
| 415 | } |
| 416 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 417 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, uint8_t(state), |
| 418 | uint8_t(CodeUpdateState::END)); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 419 | } |
| 420 | |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 421 | void pldm::responder::oem_ibm_platform::Handler::_processSystemReboot( |
| 422 | sdeventplus::source::EventBase& /*source */) |
| 423 | { |
| 424 | pldm::utils::PropertyValue value = |
| 425 | "xyz.openbmc_project.State.Chassis.Transition.Off"; |
| 426 | pldm::utils::DBusMapping dbusMapping{"/xyz/openbmc_project/state/chassis0", |
| 427 | "xyz.openbmc_project.State.Chassis", |
| 428 | "RequestedPowerTransition", "string"}; |
| 429 | try |
| 430 | { |
| 431 | dBusIntf->setDbusProperty(dbusMapping, value); |
| 432 | } |
| 433 | catch (const std::exception& e) |
| 434 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 435 | error( |
| 436 | "Chassis State transition to Off failed, unable to set property RequestedPowerTransition ERROR={ERR_EXCEP}", |
| 437 | "ERR_EXCEP", e.what()); |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | using namespace sdbusplus::bus::match::rules; |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 441 | chassisOffMatch = std::make_unique<sdbusplus::bus::match_t>( |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 442 | pldm::utils::DBusHandler::getBus(), |
| 443 | propertiesChanged("/xyz/openbmc_project/state/chassis0", |
| 444 | "xyz.openbmc_project.State.Chassis"), |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 445 | [this](sdbusplus::message_t& msg) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 446 | DbusChangedProps props{}; |
| 447 | std::string intf; |
| 448 | msg.read(intf, props); |
| 449 | const auto itr = props.find("CurrentPowerState"); |
| 450 | if (itr != props.end()) |
| 451 | { |
| 452 | PropertyValue value = itr->second; |
| 453 | auto propVal = std::get<std::string>(value); |
| 454 | if (propVal == "xyz.openbmc_project.State.Chassis.PowerState.Off") |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 455 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 456 | pldm::utils::DBusMapping dbusMapping{ |
| 457 | "/xyz/openbmc_project/control/host0/" |
| 458 | "power_restore_policy/one_time", |
| 459 | "xyz.openbmc_project.Control.Power.RestorePolicy", |
| 460 | "PowerRestorePolicy", "string"}; |
| 461 | value = "xyz.openbmc_project.Control.Power.RestorePolicy." |
| 462 | "Policy.AlwaysOn"; |
| 463 | try |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 464 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 465 | dBusIntf->setDbusProperty(dbusMapping, value); |
| 466 | } |
| 467 | catch (const std::exception& e) |
| 468 | { |
| 469 | error( |
| 470 | "Setting one-time restore policy failed, unable to set property PowerRestorePolicy ERROR={ERR_EXCEP}", |
| 471 | "ERR_EXCEP", e.what()); |
| 472 | } |
| 473 | dbusMapping = pldm::utils::DBusMapping{ |
| 474 | "/xyz/openbmc_project/state/bmc0", |
| 475 | "xyz.openbmc_project.State.BMC", "RequestedBMCTransition", |
| 476 | "string"}; |
| 477 | value = "xyz.openbmc_project.State.BMC.Transition.Reboot"; |
| 478 | try |
| 479 | { |
| 480 | dBusIntf->setDbusProperty(dbusMapping, value); |
| 481 | } |
| 482 | catch (const std::exception& e) |
| 483 | { |
| 484 | error( |
| 485 | "BMC state transition to reboot failed, unable to set property RequestedBMCTransition ERROR={ERR_EXCEP}", |
| 486 | "ERR_EXCEP", e.what()); |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 487 | } |
| 488 | } |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 489 | } |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 490 | }); |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 491 | } |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 492 | |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 493 | void pldm::responder::oem_ibm_platform::Handler::checkAndDisableWatchDog() |
| 494 | { |
| 495 | if (!hostOff && setEventReceiverCnt == SET_EVENT_RECEIVER_SENT) |
| 496 | { |
| 497 | disableWatchDogTimer(); |
| 498 | } |
| 499 | |
| 500 | return; |
| 501 | } |
| 502 | |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 503 | bool pldm::responder::oem_ibm_platform::Handler::watchDogRunning() |
| 504 | { |
| 505 | static constexpr auto watchDogObjectPath = |
| 506 | "/xyz/openbmc_project/watchdog/host0"; |
| 507 | static constexpr auto watchDogEnablePropName = "Enabled"; |
| 508 | static constexpr auto watchDogInterface = |
| 509 | "xyz.openbmc_project.State.Watchdog"; |
| 510 | bool isWatchDogRunning = false; |
| 511 | try |
| 512 | { |
| 513 | isWatchDogRunning = pldm::utils::DBusHandler().getDbusProperty<bool>( |
| 514 | watchDogObjectPath, watchDogEnablePropName, watchDogInterface); |
| 515 | } |
| 516 | catch (const std::exception& e) |
| 517 | { |
| 518 | return false; |
| 519 | } |
| 520 | return isWatchDogRunning; |
| 521 | } |
| 522 | |
| 523 | void pldm::responder::oem_ibm_platform::Handler::resetWatchDogTimer() |
| 524 | { |
| 525 | static constexpr auto watchDogService = "xyz.openbmc_project.Watchdog"; |
| 526 | static constexpr auto watchDogObjectPath = |
| 527 | "/xyz/openbmc_project/watchdog/host0"; |
| 528 | static constexpr auto watchDogInterface = |
| 529 | "xyz.openbmc_project.State.Watchdog"; |
| 530 | static constexpr auto watchDogResetPropName = "ResetTimeRemaining"; |
| 531 | |
| 532 | bool wdStatus = watchDogRunning(); |
| 533 | if (wdStatus == false) |
| 534 | { |
| 535 | return; |
| 536 | } |
| 537 | try |
| 538 | { |
| 539 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 540 | auto resetMethod = |
| 541 | bus.new_method_call(watchDogService, watchDogObjectPath, |
| 542 | watchDogInterface, watchDogResetPropName); |
| 543 | resetMethod.append(true); |
vkaverap@in.ibm.com | 5b71b86 | 2023-08-21 05:19:04 +0000 | [diff] [blame] | 544 | bus.call_noreply(resetMethod, dbusTimeout); |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 545 | } |
| 546 | catch (const std::exception& e) |
| 547 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 548 | error("Failed To reset watchdog timer ERROR={ERR_EXCEP}", "ERR_EXCEP", |
| 549 | e.what()); |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 550 | return; |
| 551 | } |
| 552 | } |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 553 | |
| 554 | void pldm::responder::oem_ibm_platform::Handler::disableWatchDogTimer() |
| 555 | { |
| 556 | setEventReceiverCnt = 0; |
| 557 | pldm::utils::DBusMapping dbusMapping{"/xyz/openbmc_project/watchdog/host0", |
| 558 | "xyz.openbmc_project.State.Watchdog", |
| 559 | "Enabled", "bool"}; |
| 560 | bool wdStatus = watchDogRunning(); |
| 561 | |
| 562 | if (!wdStatus) |
| 563 | { |
| 564 | return; |
| 565 | } |
| 566 | try |
| 567 | { |
| 568 | pldm::utils::DBusHandler().setDbusProperty(dbusMapping, false); |
| 569 | } |
| 570 | catch (const std::exception& e) |
| 571 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 572 | error("Failed To disable watchdog timer ERROR={ERR_EXCEP}", "ERR_EXCEP", |
| 573 | e.what()); |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 574 | } |
| 575 | } |
Pavithra Barithaya | 99854a7 | 2021-09-29 06:58:11 -0500 | [diff] [blame] | 576 | int pldm::responder::oem_ibm_platform::Handler::checkBMCState() |
| 577 | { |
| 578 | try |
| 579 | { |
| 580 | pldm::utils::PropertyValue propertyValue = |
| 581 | pldm::utils::DBusHandler().getDbusPropertyVariant( |
| 582 | "/xyz/openbmc_project/state/bmc0", "CurrentBMCState", |
| 583 | "xyz.openbmc_project.State.BMC"); |
| 584 | |
| 585 | if (std::get<std::string>(propertyValue) == |
| 586 | "xyz.openbmc_project.State.BMC.BMCState.NotReady") |
| 587 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 588 | error("GetPDR : PLDM stack is not ready for PDR exchange"); |
Pavithra Barithaya | 99854a7 | 2021-09-29 06:58:11 -0500 | [diff] [blame] | 589 | return PLDM_ERROR_NOT_READY; |
| 590 | } |
| 591 | } |
| 592 | catch (const std::exception& e) |
| 593 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 594 | error("Error getting the current BMC state"); |
Pavithra Barithaya | 99854a7 | 2021-09-29 06:58:11 -0500 | [diff] [blame] | 595 | return PLDM_ERROR; |
| 596 | } |
| 597 | return PLDM_SUCCESS; |
| 598 | } |
| 599 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 600 | const pldm_pdr_record* |
| 601 | pldm::responder::oem_ibm_platform::Handler::fetchLastBMCRecord( |
| 602 | const pldm_pdr* repo) |
| 603 | { |
| 604 | return pldm_pdr_find_last_in_range(repo, BMC_PDR_START_RANGE, |
| 605 | BMC_PDR_END_RANGE); |
| 606 | } |
| 607 | |
| 608 | bool pldm::responder::oem_ibm_platform::Handler::checkRecordHandleInRange( |
| 609 | const uint32_t& record_handle) |
| 610 | { |
| 611 | return record_handle >= HOST_PDR_START_RANGE && |
| 612 | record_handle <= HOST_PDR_END_RANGE; |
| 613 | } |
| 614 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 615 | } // namespace oem_ibm_platform |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 616 | } // namespace responder |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 617 | } // namespace pldm |