Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 1 | #include "oem_ibm_handler.hpp" |
| 2 | |
| 3 | #include "libpldm/entity.h" |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 4 | #include "libpldm/requester/pldm.h" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 5 | |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 6 | #include "file_io_type_lid.hpp" |
| 7 | #include "libpldmresponder/file_io.hpp" |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 8 | #include "libpldmresponder/pdr_utils.hpp" |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 9 | |
| 10 | using namespace pldm::pdr; |
| 11 | using namespace pldm::utils; |
| 12 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 13 | namespace pldm |
| 14 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 15 | namespace responder |
| 16 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 17 | namespace oem_ibm_platform |
| 18 | { |
| 19 | |
| 20 | int pldm::responder::oem_ibm_platform::Handler:: |
| 21 | getOemStateSensorReadingsHandler( |
| 22 | EntityType entityType, EntityInstance entityInstance, |
| 23 | StateSetId stateSetId, CompositeCount compSensorCnt, |
| 24 | std::vector<get_sensor_state_field>& stateField) |
| 25 | { |
| 26 | int rc = PLDM_SUCCESS; |
| 27 | stateField.clear(); |
| 28 | |
| 29 | for (size_t i = 0; i < compSensorCnt; i++) |
| 30 | { |
| 31 | uint8_t sensorOpState{}; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 32 | if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 33 | stateSetId == PLDM_OEM_IBM_BOOT_STATE) |
| 34 | { |
| 35 | sensorOpState = fetchBootSide(entityInstance, codeUpdate); |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | rc = PLDM_PLATFORM_INVALID_STATE_VALUE; |
| 40 | break; |
| 41 | } |
| 42 | stateField.push_back({PLDM_SENSOR_ENABLED, PLDM_SENSOR_UNKNOWN, |
| 43 | PLDM_SENSOR_UNKNOWN, sensorOpState}); |
| 44 | } |
| 45 | return rc; |
| 46 | } |
| 47 | |
| 48 | int pldm::responder::oem_ibm_platform::Handler:: |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 49 | oemSetStateEffecterStatesHandler( |
Varsha Kaverappa | 3fbd39e | 2020-09-28 01:40:22 -0500 | [diff] [blame] | 50 | uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId, |
| 51 | uint8_t compEffecterCnt, |
| 52 | std::vector<set_effecter_state_field>& stateField, |
| 53 | uint16_t /*effecterId*/) |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 54 | { |
| 55 | int rc = PLDM_SUCCESS; |
| 56 | |
| 57 | for (uint8_t currState = 0; currState < compEffecterCnt; ++currState) |
| 58 | { |
| 59 | if (stateField[currState].set_request == PLDM_REQUEST_SET) |
| 60 | { |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 61 | if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 62 | stateSetId == PLDM_OEM_IBM_BOOT_STATE) |
| 63 | { |
| 64 | rc = setBootSide(entityInstance, currState, stateField, |
| 65 | codeUpdate); |
| 66 | } |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 67 | else if (entityType == PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE && |
| 68 | stateSetId == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) |
| 69 | { |
| 70 | if (stateField[currState].effecter_state == |
| 71 | uint8_t(CodeUpdateState::START)) |
| 72 | { |
| 73 | codeUpdate->setCodeUpdateProgress(true); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 74 | startUpdateEvent = |
| 75 | std::make_unique<sdeventplus::source::Defer>( |
| 76 | event, |
| 77 | std::bind(std::mem_fn(&oem_ibm_platform::Handler:: |
| 78 | _processStartUpdate), |
| 79 | this, std::placeholders::_1)); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 80 | } |
| 81 | else if (stateField[currState].effecter_state == |
| 82 | uint8_t(CodeUpdateState::END)) |
| 83 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 84 | rc = PLDM_SUCCESS; |
| 85 | assembleImageEvent = std::make_unique< |
| 86 | sdeventplus::source::Defer>( |
| 87 | event, |
| 88 | std::bind( |
| 89 | std::mem_fn( |
| 90 | &oem_ibm_platform::Handler::_processEndUpdate), |
| 91 | this, std::placeholders::_1)); |
| 92 | |
| 93 | // sendCodeUpdateEvent(effecterId, END, START); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 94 | } |
| 95 | else if (stateField[currState].effecter_state == |
| 96 | uint8_t(CodeUpdateState::ABORT)) |
| 97 | { |
| 98 | codeUpdate->setCodeUpdateProgress(false); |
| 99 | codeUpdate->clearDirPath(LID_STAGING_DIR); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 100 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 101 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, |
| 102 | uint8_t(CodeUpdateState::ABORT), |
| 103 | uint8_t(CodeUpdateState::START)); |
| 104 | // sendCodeUpdateEvent(effecterId, ABORT, END); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 105 | } |
| 106 | else if (stateField[currState].effecter_state == |
| 107 | uint8_t(CodeUpdateState::ACCEPT)) |
| 108 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 109 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 110 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, |
| 111 | uint8_t(CodeUpdateState::ACCEPT), |
| 112 | uint8_t(CodeUpdateState::END)); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 113 | // TODO Set new Dbus property provided by code update app |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 114 | // sendCodeUpdateEvent(effecterId, ACCEPT, END); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 115 | } |
| 116 | else if (stateField[currState].effecter_state == |
| 117 | uint8_t(CodeUpdateState::REJECT)) |
| 118 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 119 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 120 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, |
| 121 | uint8_t(CodeUpdateState::REJECT), |
| 122 | uint8_t(CodeUpdateState::END)); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 123 | // TODO Set new Dbus property provided by code update app |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 124 | // sendCodeUpdateEvent(effecterId, REJECT, END); |
Sagar Srinivas | cfdbca7 | 2020-09-22 10:03:35 -0500 | [diff] [blame] | 125 | } |
| 126 | } |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 127 | else if (entityType == PLDM_ENTITY_SYSTEM_CHASSIS && |
| 128 | stateSetId == PLDM_OEM_IBM_SYSTEM_POWER_STATE) |
| 129 | { |
| 130 | if (stateField[currState].effecter_state == POWER_CYCLE_HARD) |
| 131 | { |
| 132 | systemRebootEvent = |
| 133 | std::make_unique<sdeventplus::source::Defer>( |
| 134 | event, |
| 135 | std::bind(std::mem_fn(&oem_ibm_platform::Handler:: |
| 136 | _processSystemReboot), |
| 137 | this, std::placeholders::_1)); |
| 138 | } |
| 139 | } |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 140 | else |
| 141 | { |
| 142 | rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE; |
| 143 | } |
| 144 | } |
| 145 | if (rc != PLDM_SUCCESS) |
| 146 | { |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | return rc; |
| 151 | } |
| 152 | |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 153 | void buildAllCodeUpdateEffecterPDR(oem_ibm_platform::Handler* platformHandler, |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 154 | uint16_t entityType, uint16_t entityInstance, |
| 155 | uint16_t stateSetID, pdr_utils::Repo& repo) |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 156 | { |
| 157 | size_t pdrSize = 0; |
| 158 | pdrSize = sizeof(pldm_state_effecter_pdr) + |
| 159 | sizeof(state_effecter_possible_states); |
| 160 | std::vector<uint8_t> entry{}; |
| 161 | entry.resize(pdrSize); |
| 162 | pldm_state_effecter_pdr* pdr = |
| 163 | reinterpret_cast<pldm_state_effecter_pdr*>(entry.data()); |
| 164 | if (!pdr) |
| 165 | { |
| 166 | std::cerr << "Failed to get record by PDR type, ERROR:" |
| 167 | << PLDM_PLATFORM_INVALID_EFFECTER_ID << std::endl; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 168 | return; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 169 | } |
| 170 | pdr->hdr.record_handle = 0; |
| 171 | pdr->hdr.version = 1; |
| 172 | pdr->hdr.type = PLDM_STATE_EFFECTER_PDR; |
| 173 | pdr->hdr.record_change_num = 0; |
| 174 | pdr->hdr.length = sizeof(pldm_state_effecter_pdr) - sizeof(pldm_pdr_hdr); |
Manojkiran Eda | cc5f158 | 2021-09-29 17:03:06 +0530 | [diff] [blame] | 175 | pdr->terminus_handle = TERMINUS_HANDLE; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 176 | pdr->effecter_id = platformHandler->getNextEffecterId(); |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 177 | pdr->entity_type = entityType; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 178 | pdr->entity_instance = entityInstance; |
Sagar Srinivas | 97296e0 | 2021-08-26 09:40:41 -0500 | [diff] [blame] | 179 | pdr->container_id = 1; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 180 | pdr->effecter_semantic_id = 0; |
| 181 | pdr->effecter_init = PLDM_NO_INIT; |
| 182 | pdr->has_description_pdr = false; |
| 183 | pdr->composite_effecter_count = 1; |
| 184 | |
| 185 | auto* possibleStatesPtr = pdr->possible_states; |
| 186 | auto possibleStates = |
| 187 | reinterpret_cast<state_effecter_possible_states*>(possibleStatesPtr); |
| 188 | possibleStates->state_set_id = stateSetID; |
| 189 | possibleStates->possible_states_size = 2; |
| 190 | auto state = |
| 191 | reinterpret_cast<state_effecter_possible_states*>(possibleStates); |
| 192 | if (stateSetID == PLDM_OEM_IBM_BOOT_STATE) |
| 193 | state->states[0].byte = 6; |
| 194 | else if (stateSetID == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) |
| 195 | state->states[0].byte = 126; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 196 | else if (stateSetID == PLDM_OEM_IBM_SYSTEM_POWER_STATE) |
| 197 | state->states[0].byte = 2; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 198 | pldm::responder::pdr_utils::PdrEntry pdrEntry{}; |
| 199 | pdrEntry.data = entry.data(); |
| 200 | pdrEntry.size = pdrSize; |
| 201 | repo.addRecord(pdrEntry); |
| 202 | } |
| 203 | |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 204 | void buildAllCodeUpdateSensorPDR(oem_ibm_platform::Handler* platformHandler, |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 205 | uint16_t entityType, uint16_t entityInstance, |
| 206 | uint16_t stateSetID, pdr_utils::Repo& repo) |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 207 | { |
| 208 | size_t pdrSize = 0; |
| 209 | pdrSize = |
| 210 | sizeof(pldm_state_sensor_pdr) + sizeof(state_sensor_possible_states); |
| 211 | std::vector<uint8_t> entry{}; |
| 212 | entry.resize(pdrSize); |
| 213 | pldm_state_sensor_pdr* pdr = |
| 214 | reinterpret_cast<pldm_state_sensor_pdr*>(entry.data()); |
| 215 | if (!pdr) |
| 216 | { |
| 217 | std::cerr << "Failed to get record by PDR type, ERROR:" |
| 218 | << PLDM_PLATFORM_INVALID_SENSOR_ID << std::endl; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 219 | return; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 220 | } |
| 221 | pdr->hdr.record_handle = 0; |
| 222 | pdr->hdr.version = 1; |
| 223 | pdr->hdr.type = PLDM_STATE_SENSOR_PDR; |
| 224 | pdr->hdr.record_change_num = 0; |
| 225 | pdr->hdr.length = sizeof(pldm_state_sensor_pdr) - sizeof(pldm_pdr_hdr); |
Manojkiran Eda | cc5f158 | 2021-09-29 17:03:06 +0530 | [diff] [blame] | 226 | pdr->terminus_handle = TERMINUS_HANDLE; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 227 | pdr->sensor_id = platformHandler->getNextSensorId(); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 228 | pdr->entity_type = entityType; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 229 | pdr->entity_instance = entityInstance; |
Sagar Srinivas | 97296e0 | 2021-08-26 09:40:41 -0500 | [diff] [blame] | 230 | pdr->container_id = 1; |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 231 | pdr->sensor_init = PLDM_NO_INIT; |
| 232 | pdr->sensor_auxiliary_names_pdr = false; |
| 233 | pdr->composite_sensor_count = 1; |
| 234 | |
| 235 | auto* possibleStatesPtr = pdr->possible_states; |
| 236 | auto possibleStates = |
| 237 | reinterpret_cast<state_sensor_possible_states*>(possibleStatesPtr); |
| 238 | possibleStates->state_set_id = stateSetID; |
| 239 | possibleStates->possible_states_size = 2; |
| 240 | auto state = |
| 241 | reinterpret_cast<state_sensor_possible_states*>(possibleStates); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 242 | if ((stateSetID == PLDM_OEM_IBM_BOOT_STATE) || |
Christian Geddes | 7f9523c | 2021-08-03 13:44:38 -0500 | [diff] [blame] | 243 | (stateSetID == PLDM_OEM_IBM_VERIFICATION_STATE)) |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 244 | state->states[0].byte = 6; |
| 245 | else if (stateSetID == PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE) |
| 246 | state->states[0].byte = 126; |
| 247 | pldm::responder::pdr_utils::PdrEntry pdrEntry{}; |
| 248 | pdrEntry.data = entry.data(); |
| 249 | pdrEntry.size = pdrSize; |
| 250 | repo.addRecord(pdrEntry); |
| 251 | } |
| 252 | |
| 253 | void pldm::responder::oem_ibm_platform::Handler::buildOEMPDR( |
| 254 | pdr_utils::Repo& repo) |
| 255 | { |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 256 | buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 257 | ENTITY_INSTANCE_0, PLDM_OEM_IBM_BOOT_STATE, |
| 258 | repo); |
| 259 | buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 260 | ENTITY_INSTANCE_1, PLDM_OEM_IBM_BOOT_STATE, |
| 261 | repo); |
| 262 | buildAllCodeUpdateEffecterPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 263 | ENTITY_INSTANCE_0, |
| 264 | PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, repo); |
| 265 | buildAllCodeUpdateEffecterPDR(this, PLDM_ENTITY_SYSTEM_CHASSIS, |
Sagar Srinivas | 1b8d35f | 2021-11-10 10:54:40 -0600 | [diff] [blame^] | 266 | ENTITY_INSTANCE_1, |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 267 | PLDM_OEM_IBM_SYSTEM_POWER_STATE, repo); |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 268 | |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 269 | buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 270 | ENTITY_INSTANCE_0, PLDM_OEM_IBM_BOOT_STATE, |
| 271 | repo); |
| 272 | buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 273 | ENTITY_INSTANCE_1, PLDM_OEM_IBM_BOOT_STATE, |
| 274 | repo); |
| 275 | buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 276 | ENTITY_INSTANCE_0, |
| 277 | PLDM_OEM_IBM_FIRMWARE_UPDATE_STATE, repo); |
| 278 | buildAllCodeUpdateSensorPDR(this, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
| 279 | ENTITY_INSTANCE_0, |
| 280 | PLDM_OEM_IBM_VERIFICATION_STATE, repo); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 281 | auto sensorId = findStateSensorId( |
| 282 | repo.getPdr(), 0, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE, |
Sagar Srinivas | f4a7dd7 | 2021-10-20 04:45:37 -0500 | [diff] [blame] | 283 | ENTITY_INSTANCE_0, 1, PLDM_OEM_IBM_VERIFICATION_STATE); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 284 | codeUpdate->setMarkerLidSensor(sensorId); |
| 285 | 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_FIRMWARE_UPDATE_STATE); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 288 | codeUpdate->setFirmwareUpdateSensor(sensorId); |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 289 | } |
| 290 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 291 | void pldm::responder::oem_ibm_platform::Handler::setPlatformHandler( |
| 292 | pldm::responder::platform::Handler* handler) |
| 293 | { |
| 294 | platformHandler = handler; |
| 295 | } |
| 296 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 297 | int pldm::responder::oem_ibm_platform::Handler::sendEventToHost( |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 298 | std::vector<uint8_t>& requestMsg, uint8_t instanceId) |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 299 | { |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 300 | if (requestMsg.size()) |
| 301 | { |
| 302 | std::ostringstream tempStream; |
| 303 | for (int byte : requestMsg) |
| 304 | { |
| 305 | tempStream << std::setfill('0') << std::setw(2) << std::hex << byte |
| 306 | << " "; |
| 307 | } |
| 308 | std::cout << tempStream.str() << std::endl; |
| 309 | } |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 310 | auto oemPlatformEventMessageResponseHandler = |
| 311 | [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) { |
| 312 | uint8_t completionCode{}; |
| 313 | uint8_t status{}; |
| 314 | auto rc = decode_platform_event_message_resp( |
| 315 | response, respMsgLen, &completionCode, &status); |
| 316 | if (rc || completionCode) |
| 317 | { |
| 318 | std::cerr << "Failed to decode_platform_event_message_resp: " |
| 319 | << " for code update event rc=" << rc |
| 320 | << ", cc=" << static_cast<unsigned>(completionCode) |
| 321 | << std::endl; |
| 322 | } |
| 323 | }; |
| 324 | auto rc = handler->registerRequest( |
| 325 | mctp_eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE, |
| 326 | std::move(requestMsg), |
| 327 | std::move(oemPlatformEventMessageResponseHandler)); |
| 328 | if (rc) |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 329 | { |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 330 | std::cerr << "Failed to send BIOS attribute change event message \n"; |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 331 | } |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 332 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 333 | return rc; |
| 334 | } |
| 335 | |
| 336 | int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec, |
| 337 | std::vector<uint8_t>& requestMsg, uint8_t instanceId) |
| 338 | { |
| 339 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 340 | |
| 341 | auto rc = encode_platform_event_message_req( |
| 342 | instanceId, 1 /*formatVersion*/, 0 /*tId*/, eventType, |
| 343 | eventDataVec.data(), eventDataVec.size(), request, |
| 344 | eventDataVec.size() + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 345 | |
| 346 | return rc; |
| 347 | } |
| 348 | |
| 349 | void pldm::responder::oem_ibm_platform::Handler::sendStateSensorEvent( |
| 350 | uint16_t sensorId, enum sensor_event_class_states sensorEventClass, |
| 351 | uint8_t sensorOffset, uint8_t eventState, uint8_t prevEventState) |
| 352 | { |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 353 | std::vector<uint8_t> sensorEventDataVec{}; |
| 354 | size_t sensorEventSize = PLDM_SENSOR_EVENT_DATA_MIN_LENGTH + 1; |
| 355 | sensorEventDataVec.resize(sensorEventSize); |
| 356 | auto eventData = reinterpret_cast<struct pldm_sensor_event_data*>( |
| 357 | sensorEventDataVec.data()); |
| 358 | eventData->sensor_id = sensorId; |
| 359 | eventData->sensor_event_class_type = sensorEventClass; |
| 360 | auto eventClassStart = eventData->event_class; |
| 361 | auto eventClass = |
| 362 | reinterpret_cast<struct pldm_sensor_event_state_sensor_state*>( |
| 363 | eventClassStart); |
| 364 | eventClass->sensor_offset = sensorOffset; |
| 365 | eventClass->event_state = eventState; |
| 366 | eventClass->previous_event_state = prevEventState; |
| 367 | auto instanceId = requester.getInstanceId(mctp_eid); |
| 368 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 369 | PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + |
| 370 | sensorEventDataVec.size()); |
| 371 | auto rc = encodeEventMsg(PLDM_SENSOR_EVENT, sensorEventDataVec, requestMsg, |
| 372 | instanceId); |
| 373 | if (rc != PLDM_SUCCESS) |
| 374 | { |
| 375 | std::cerr << "Failed to encode state sensor event, rc = " << rc |
| 376 | << std::endl; |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 377 | requester.markFree(mctp_eid, instanceId); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 378 | return; |
| 379 | } |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 380 | rc = sendEventToHost(requestMsg, instanceId); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 381 | if (rc != PLDM_SUCCESS) |
| 382 | { |
| 383 | std::cerr << "Failed to send event to host: " |
| 384 | << "rc=" << rc << std::endl; |
| 385 | } |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 386 | return; |
| 387 | } |
| 388 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 389 | void pldm::responder::oem_ibm_platform::Handler::_processEndUpdate( |
| 390 | sdeventplus::source::EventBase& /*source */) |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 391 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 392 | assembleImageEvent.reset(); |
Adriana Kobylak | 9296f24 | 2021-09-22 15:52:00 +0000 | [diff] [blame] | 393 | int retc = codeUpdate->assembleCodeUpdateImage(); |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 394 | if (retc != PLDM_SUCCESS) |
| 395 | { |
| 396 | codeUpdate->setCodeUpdateProgress(false); |
| 397 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 398 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, |
| 399 | uint8_t(CodeUpdateState::FAIL), |
| 400 | uint8_t(CodeUpdateState::START)); |
| 401 | } |
| 402 | } |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 403 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 404 | void pldm::responder::oem_ibm_platform::Handler::_processStartUpdate( |
| 405 | sdeventplus::source::EventBase& /*source */) |
| 406 | { |
| 407 | codeUpdate->deleteImage(); |
| 408 | CodeUpdateState state = CodeUpdateState::START; |
| 409 | auto rc = codeUpdate->setRequestedApplyTime(); |
| 410 | if (rc != PLDM_SUCCESS) |
| 411 | { |
| 412 | std::cerr << "setRequestedApplyTime failed \n"; |
| 413 | state = CodeUpdateState::FAIL; |
| 414 | } |
| 415 | auto sensorId = codeUpdate->getFirmwareUpdateSensor(); |
| 416 | sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0, uint8_t(state), |
| 417 | uint8_t(CodeUpdateState::END)); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 418 | } |
| 419 | |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 420 | void pldm::responder::oem_ibm_platform::Handler::_processSystemReboot( |
| 421 | sdeventplus::source::EventBase& /*source */) |
| 422 | { |
| 423 | pldm::utils::PropertyValue value = |
| 424 | "xyz.openbmc_project.State.Chassis.Transition.Off"; |
| 425 | pldm::utils::DBusMapping dbusMapping{"/xyz/openbmc_project/state/chassis0", |
| 426 | "xyz.openbmc_project.State.Chassis", |
| 427 | "RequestedPowerTransition", "string"}; |
| 428 | try |
| 429 | { |
| 430 | dBusIntf->setDbusProperty(dbusMapping, value); |
| 431 | } |
| 432 | catch (const std::exception& e) |
| 433 | { |
| 434 | |
| 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; |
| 441 | chassisOffMatch = std::make_unique<sdbusplus::bus::match::match>( |
| 442 | pldm::utils::DBusHandler::getBus(), |
| 443 | propertiesChanged("/xyz/openbmc_project/state/chassis0", |
| 444 | "xyz.openbmc_project.State.Chassis"), |
| 445 | [this](sdbusplus::message::message& msg) { |
| 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 |