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