George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1 | #include "pldm_cmd_helper.hpp" |
| 2 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 3 | namespace pldmtool |
| 4 | { |
| 5 | |
| 6 | namespace platform |
| 7 | { |
| 8 | |
| 9 | namespace |
| 10 | { |
| 11 | |
| 12 | using namespace pldmtool::helper; |
| 13 | std::vector<std::unique_ptr<CommandInterface>> commands; |
| 14 | |
| 15 | } // namespace |
| 16 | |
| 17 | class GetPDR : public CommandInterface |
| 18 | { |
| 19 | public: |
| 20 | ~GetPDR() = default; |
| 21 | GetPDR() = delete; |
| 22 | GetPDR(const GetPDR&) = delete; |
| 23 | GetPDR(GetPDR&&) = default; |
| 24 | GetPDR& operator=(const GetPDR&) = delete; |
| 25 | GetPDR& operator=(GetPDR&&) = default; |
| 26 | |
| 27 | using CommandInterface::CommandInterface; |
| 28 | |
| 29 | // The maximum number of record bytes requested to be returned in the |
| 30 | // response to this instance of the GetPDR command. |
| 31 | static constexpr uint16_t requestCount = 128; |
| 32 | |
| 33 | explicit GetPDR(const char* type, const char* name, CLI::App* app) : |
| 34 | CommandInterface(type, name, app) |
| 35 | { |
| 36 | app->add_option( |
| 37 | "-d,--data", recordHandle, |
| 38 | "retrieve individual PDRs from a PDR Repository\n" |
| 39 | "eg: The recordHandle value for the PDR to be retrieved and 0 " |
| 40 | "means get first PDR in the repository.") |
| 41 | ->required(); |
| 42 | } |
| 43 | |
| 44 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 45 | { |
| 46 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 47 | PLDM_GET_PDR_REQ_BYTES); |
| 48 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 49 | |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 50 | auto rc = encode_get_pdr_req(instanceId, recordHandle, 0, |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 51 | PLDM_GET_FIRSTPART, requestCount, 0, |
| 52 | request, PLDM_GET_PDR_REQ_BYTES); |
| 53 | return {rc, requestMsg}; |
| 54 | } |
| 55 | |
| 56 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 57 | { |
| 58 | uint8_t completionCode = 0; |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 59 | uint8_t recordData[65535] = {0}; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 60 | uint32_t nextRecordHndl = 0; |
| 61 | uint32_t nextDataTransferHndl = 0; |
| 62 | uint8_t transferFlag = 0; |
| 63 | uint16_t respCnt = 0; |
| 64 | uint8_t transferCRC = 0; |
| 65 | |
| 66 | auto rc = decode_get_pdr_resp( |
| 67 | responsePtr, payloadLength, &completionCode, &nextRecordHndl, |
| 68 | &nextDataTransferHndl, &transferFlag, &respCnt, recordData, |
| 69 | sizeof(recordData), &transferCRC); |
| 70 | |
| 71 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 72 | { |
| 73 | std::cerr << "Response Message Error: " |
| 74 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 75 | << std::endl; |
| 76 | return; |
| 77 | } |
| 78 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 79 | printPDRMsg(nextRecordHndl, respCnt, recordData); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | private: |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 83 | const std::map<uint16_t, std::string> entityType = { |
| 84 | {64, "System Board"}, |
Pavithra Barithaya | e8beb89 | 2020-04-14 23:24:25 -0500 | [diff] [blame] | 85 | {66, "Memory Module"}, |
| 86 | {67, "Processor Module"}, |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 87 | {137, "Management Controller"}, |
| 88 | {69, "Chassis front panel board (control panel)"}, |
| 89 | {123, "Power converter"}, |
| 90 | {45, "System chassis (main enclosure)"}, |
| 91 | {11521, "System (logical)"}, |
| 92 | }; |
| 93 | |
Deepak Kodihalli | a556eb2 | 2020-04-14 02:29:11 -0500 | [diff] [blame] | 94 | std::string getEntityName(uint16_t type) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 95 | { |
| 96 | try |
| 97 | { |
| 98 | return entityType.at(type); |
| 99 | } |
| 100 | catch (const std::out_of_range& e) |
| 101 | { |
| 102 | return std::to_string(static_cast<unsigned>(type)) + "(OEM)"; |
| 103 | } |
| 104 | } |
| 105 | |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 106 | void printCommonPDRHeader(const pldm_pdr_hdr* hdr) |
| 107 | { |
| 108 | std::cout << "recordHandle: " << hdr->record_handle << std::endl; |
| 109 | std::cout << "PDRHeaderVersion: " << unsigned(hdr->version) |
| 110 | << std::endl; |
| 111 | std::cout << "PDRType: " << unsigned(hdr->type) << std::endl; |
| 112 | std::cout << "recordChangeNumber: " << hdr->record_change_num |
| 113 | << std::endl; |
| 114 | std::cout << "dataLength: " << hdr->length << std::endl << std::endl; |
| 115 | } |
| 116 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 117 | void printPDRFruRecordSet(uint8_t* data) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 118 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 119 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 120 | { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | data += sizeof(pldm_pdr_hdr); |
| 125 | pldm_pdr_fru_record_set* pdr = |
| 126 | reinterpret_cast<pldm_pdr_fru_record_set*>(data); |
| 127 | |
| 128 | std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle |
| 129 | << std::endl; |
| 130 | std::cout << "FRURecordSetIdentifier: " << pdr->fru_rsi << std::endl; |
| 131 | std::cout << "entityType: " << getEntityName(pdr->entity_type) |
| 132 | << std::endl; |
| 133 | std::cout << "entityInstanceNumber: " << pdr->entity_instance_num |
| 134 | << std::endl; |
| 135 | std::cout << "containerID: " << pdr->container_id << std::endl; |
| 136 | } |
| 137 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 138 | void printPDREntityAssociation(uint8_t* data) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 139 | { |
| 140 | const std::map<uint8_t, const char*> assocationType = { |
| 141 | {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"}, |
| 142 | {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"}, |
| 143 | }; |
| 144 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 145 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 146 | { |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | data += sizeof(pldm_pdr_hdr); |
| 151 | pldm_pdr_entity_association* pdr = |
| 152 | reinterpret_cast<pldm_pdr_entity_association*>(data); |
| 153 | |
| 154 | std::cout << "containerID: " << pdr->container_id << std::endl; |
| 155 | std::cout << "associationType: " |
| 156 | << assocationType.at(pdr->association_type) << std::endl |
| 157 | << std::endl; |
| 158 | |
| 159 | std::cout << "containerEntityType: " |
| 160 | << getEntityName(pdr->container.entity_type) << std::endl; |
| 161 | std::cout << "containerEntityInstanceNumber: " |
| 162 | << pdr->container.entity_instance_num << std::endl; |
| 163 | std::cout << "containerEntityContainerID: " |
| 164 | << pdr->container.entity_container_id << std::endl; |
| 165 | |
| 166 | std::cout << "containedEntityCount: " |
| 167 | << static_cast<unsigned>(pdr->num_children) << std::endl |
| 168 | << std::endl; |
| 169 | |
| 170 | auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]); |
| 171 | for (int i = 0; i < pdr->num_children; ++i) |
| 172 | { |
| 173 | std::cout << "containedEntityType[" << i + 1 |
| 174 | << "]: " << getEntityName(child->entity_type) |
| 175 | << std::endl; |
| 176 | std::cout << "containedEntityInstanceNumber[" << i + 1 |
| 177 | << "]: " << child->entity_instance_num << std::endl; |
| 178 | std::cout << "containedEntityContainerID[" << i + 1 |
| 179 | << "]: " << child->entity_container_id << std::endl |
| 180 | << std::endl; |
| 181 | ++child; |
| 182 | } |
| 183 | } |
| 184 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 185 | void printNumericEffecterPDR(uint8_t* data) |
| 186 | { |
| 187 | struct pldm_numeric_effecter_value_pdr* pdr = |
| 188 | (struct pldm_numeric_effecter_value_pdr*)data; |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 189 | std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle |
| 190 | << std::endl; |
| 191 | std::cout << "effecterID: " << pdr->effecter_id << std::endl; |
| 192 | std::cout << "entityType: " << pdr->entity_type << std::endl; |
| 193 | std::cout << "entityInstanceNumber: " << pdr->entity_instance |
| 194 | << std::endl; |
| 195 | std::cout << "containerID: " << pdr->container_id << std::endl; |
| 196 | std::cout << "effecterSemanticID: " << pdr->effecter_semantic_id |
| 197 | << std::endl; |
| 198 | std::cout << "effecterInit: " << unsigned(pdr->effecter_init) |
| 199 | << std::endl; |
| 200 | std::cout << "effecterAuxiliaryNames: " |
| 201 | << (unsigned(pdr->effecter_auxiliary_names) ? "true" |
| 202 | : "false") |
| 203 | << std::endl; |
| 204 | std::cout << "baseUnit: " << unsigned(pdr->base_unit) << std::endl; |
| 205 | std::cout << "unitModifier: " << unsigned(pdr->unit_modifier) |
| 206 | << std::endl; |
| 207 | std::cout << "rateUnit: " << unsigned(pdr->rate_unit) << std::endl; |
| 208 | std::cout << "baseOEMUnitHandle: " |
| 209 | << unsigned(pdr->base_oem_unit_handle) << std::endl; |
| 210 | std::cout << "auxUnit: " << unsigned(pdr->aux_unit) << std::endl; |
| 211 | std::cout << "auxUnitModifier: " << unsigned(pdr->aux_unit_modifier) |
| 212 | << std::endl; |
| 213 | std::cout << "auxrateUnit: " << unsigned(pdr->aux_rate_unit) |
| 214 | << std::endl; |
| 215 | std::cout << "auxOEMUnitHandle: " << unsigned(pdr->aux_oem_unit_handle) |
| 216 | << std::endl; |
| 217 | std::cout << "isLinear: " |
| 218 | << (unsigned(pdr->is_linear) ? "true" : "false") << std::endl; |
| 219 | std::cout << "effecterDataSize: " << unsigned(pdr->effecter_data_size) |
| 220 | << std::endl; |
| 221 | std::cout << "resolution: " << pdr->resolution << std::endl; |
| 222 | std::cout << "offset: " << pdr->offset << std::endl; |
| 223 | std::cout << "accuracy: " << pdr->accuracy << std::endl; |
| 224 | std::cout << "plusTolerance: " << unsigned(pdr->plus_tolerance) |
| 225 | << std::endl; |
| 226 | std::cout << "minusTolerance: " << unsigned(pdr->minus_tolerance) |
| 227 | << std::endl; |
| 228 | std::cout << "stateTransitionInterval: " |
| 229 | << pdr->state_transition_interval << std::endl; |
| 230 | std::cout << "TransitionInterval: " << pdr->transition_interval |
| 231 | << std::endl; |
| 232 | switch (pdr->effecter_data_size) |
| 233 | { |
| 234 | case PLDM_EFFECTER_DATA_SIZE_UINT8: |
| 235 | std::cout << "maxSettable: " |
| 236 | << unsigned(pdr->max_set_table.value_u8) << std::endl; |
| 237 | std::cout << "minSettable: " |
| 238 | << unsigned(pdr->min_set_table.value_u8) << std::endl; |
| 239 | break; |
| 240 | case PLDM_EFFECTER_DATA_SIZE_SINT8: |
| 241 | std::cout << "maxSettable: " |
| 242 | << unsigned(pdr->max_set_table.value_s8) << std::endl; |
| 243 | std::cout << "minSettable: " |
| 244 | << unsigned(pdr->min_set_table.value_s8) << std::endl; |
| 245 | break; |
| 246 | case PLDM_EFFECTER_DATA_SIZE_UINT16: |
| 247 | std::cout << "maxSettable: " << pdr->max_set_table.value_u16 |
| 248 | << std::endl; |
| 249 | std::cout << "minSettable: " << pdr->min_set_table.value_u16 |
| 250 | << std::endl; |
| 251 | break; |
| 252 | case PLDM_EFFECTER_DATA_SIZE_SINT16: |
| 253 | std::cout << "maxSettable: " << pdr->max_set_table.value_s16 |
| 254 | << std::endl; |
| 255 | std::cout << "minSettable: " << pdr->min_set_table.value_s16 |
| 256 | << std::endl; |
| 257 | break; |
| 258 | case PLDM_EFFECTER_DATA_SIZE_UINT32: |
| 259 | std::cout << "maxSettable: " << pdr->max_set_table.value_u32 |
| 260 | << std::endl; |
| 261 | std::cout << "minSettable: " << pdr->min_set_table.value_u32 |
| 262 | << std::endl; |
| 263 | break; |
| 264 | case PLDM_EFFECTER_DATA_SIZE_SINT32: |
| 265 | std::cout << "maxSettable: " << pdr->max_set_table.value_s32 |
| 266 | << std::endl; |
| 267 | std::cout << "minSettable: " << pdr->min_set_table.value_s32 |
| 268 | << std::endl; |
| 269 | break; |
| 270 | default: |
| 271 | break; |
| 272 | } |
| 273 | std::cout << "rangeFieldFormat: " << unsigned(pdr->range_field_format) |
| 274 | << std::endl; |
| 275 | std::cout << "rangeFieldSupport: " |
| 276 | << unsigned(pdr->range_field_support.byte) << std::endl; |
| 277 | switch (pdr->range_field_format) |
| 278 | { |
| 279 | case PLDM_RANGE_FIELD_FORMAT_UINT8: |
| 280 | std::cout << "nominalValue: " |
| 281 | << unsigned(pdr->nominal_value.value_u8) << std::endl; |
| 282 | std::cout << "normalMax: " << unsigned(pdr->normal_max.value_u8) |
| 283 | << std::endl; |
| 284 | std::cout << "normalMin: " << unsigned(pdr->normal_min.value_u8) |
| 285 | << std::endl; |
| 286 | std::cout << "ratedMax: " << unsigned(pdr->rated_max.value_u8) |
| 287 | << std::endl; |
| 288 | std::cout << "ratedMin: " << unsigned(pdr->rated_min.value_u8) |
| 289 | << std::endl; |
| 290 | break; |
| 291 | case PLDM_RANGE_FIELD_FORMAT_SINT8: |
| 292 | std::cout << "nominalValue: " |
| 293 | << unsigned(pdr->nominal_value.value_s8) << std::endl; |
| 294 | std::cout << "normalMax: " << unsigned(pdr->normal_max.value_s8) |
| 295 | << std::endl; |
| 296 | std::cout << "normalMin: " << unsigned(pdr->normal_min.value_s8) |
| 297 | << std::endl; |
| 298 | std::cout << "ratedMax: " << unsigned(pdr->rated_max.value_s8) |
| 299 | << std::endl; |
| 300 | std::cout << "ratedMin: " << unsigned(pdr->rated_min.value_s8) |
| 301 | << std::endl; |
| 302 | break; |
| 303 | case PLDM_RANGE_FIELD_FORMAT_UINT16: |
| 304 | std::cout << "nominalValue: " << pdr->nominal_value.value_u16 |
| 305 | << std::endl; |
| 306 | std::cout << "normalMax: " << pdr->normal_max.value_u16 |
| 307 | << std::endl; |
| 308 | std::cout << "normalMin: " << pdr->normal_min.value_u16 |
| 309 | << std::endl; |
| 310 | std::cout << "ratedMax: " << pdr->rated_max.value_u16 |
| 311 | << std::endl; |
| 312 | std::cout << "ratedMin: " << pdr->rated_min.value_u16 |
| 313 | << std::endl; |
| 314 | break; |
| 315 | case PLDM_RANGE_FIELD_FORMAT_SINT16: |
| 316 | std::cout << "nominalValue: " << pdr->nominal_value.value_s16 |
| 317 | << std::endl; |
| 318 | std::cout << "normalMax: " << pdr->normal_max.value_s16 |
| 319 | << std::endl; |
| 320 | std::cout << "normalMin: " << pdr->normal_min.value_s16 |
| 321 | << std::endl; |
| 322 | std::cout << "ratedMax: " << pdr->rated_max.value_s16 |
| 323 | << std::endl; |
| 324 | std::cout << "ratedMin: " << pdr->rated_min.value_s16 |
| 325 | << std::endl; |
| 326 | break; |
| 327 | case PLDM_RANGE_FIELD_FORMAT_UINT32: |
| 328 | std::cout << "nominalValue: " << pdr->nominal_value.value_u32 |
| 329 | << std::endl; |
| 330 | std::cout << "normalMax: " << pdr->normal_max.value_u32 |
| 331 | << std::endl; |
| 332 | std::cout << "normalMin: " << pdr->normal_min.value_u32 |
| 333 | << std::endl; |
| 334 | std::cout << "ratedMax: " << pdr->rated_max.value_u32 |
| 335 | << std::endl; |
| 336 | std::cout << "ratedMin: " << pdr->rated_min.value_u32 |
| 337 | << std::endl; |
| 338 | break; |
| 339 | case PLDM_RANGE_FIELD_FORMAT_SINT32: |
| 340 | std::cout << "nominalValue: " << pdr->nominal_value.value_s32 |
| 341 | << std::endl; |
| 342 | std::cout << "normalMax: " << pdr->normal_max.value_s32 |
| 343 | << std::endl; |
| 344 | std::cout << "normalMin: " << pdr->normal_min.value_s32 |
| 345 | << std::endl; |
| 346 | std::cout << "ratedMax: " << pdr->rated_max.value_s32 |
| 347 | << std::endl; |
| 348 | std::cout << "ratedMin: " << pdr->rated_min.value_s32 |
| 349 | << std::endl; |
| 350 | break; |
| 351 | case PLDM_RANGE_FIELD_FORMAT_REAL32: |
| 352 | std::cout << "nominalValue: " << pdr->nominal_value.value_f32 |
| 353 | << std::endl; |
| 354 | std::cout << "normalMax: " << pdr->normal_max.value_f32 |
| 355 | << std::endl; |
| 356 | std::cout << "normalMin: " << pdr->normal_min.value_f32 |
| 357 | << std::endl; |
| 358 | std::cout << "ratedMax: " << pdr->rated_max.value_f32 |
| 359 | << std::endl; |
| 360 | std::cout << "ratedMin: " << pdr->rated_min.value_f32 |
| 361 | << std::endl; |
| 362 | break; |
| 363 | default: |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | void printStateEffecterPDR(uint8_t* data) |
| 369 | { |
| 370 | if (data == NULL) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 371 | { |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | struct pldm_state_effecter_pdr* pdr = |
| 376 | (struct pldm_state_effecter_pdr*)data; |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 377 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 378 | std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle |
| 379 | << std::endl; |
| 380 | std::cout << "effecterID: " << pdr->effecter_id << std::endl; |
| 381 | std::cout << "entityType: " << pdr->entity_type << std::endl; |
| 382 | std::cout << "entityInstanceNumber: " << pdr->entity_instance |
| 383 | << std::endl; |
| 384 | std::cout << "containerID: " << pdr->container_id << std::endl; |
| 385 | std::cout << "effecterSemanticID: " << pdr->effecter_semantic_id |
| 386 | << std::endl; |
| 387 | std::cout << "effecterInit: " << unsigned(pdr->effecter_init) |
| 388 | << std::endl; |
| 389 | std::cout << "effecterDescriptionPDR: " |
| 390 | << (unsigned(pdr->has_description_pdr) ? "true" : "false") |
| 391 | << std::endl; |
| 392 | std::cout << "compositeEffecterCount: " |
| 393 | << unsigned(pdr->composite_effecter_count) << std::endl; |
| 394 | |
| 395 | for (size_t i = 0; i < pdr->composite_effecter_count; ++i) |
| 396 | { |
| 397 | struct state_effecter_possible_states* state = |
| 398 | (struct state_effecter_possible_states*)pdr->possible_states + |
| 399 | i * sizeof(state_effecter_possible_states); |
| 400 | std::cout << "stateSetID: " << state->state_set_id << std::endl; |
| 401 | std::cout << "possibleStatesSize: " |
| 402 | << unsigned(state->possible_states_size) << std::endl; |
| 403 | bitfield8_t* bf = reinterpret_cast<bitfield8_t*>(state->states); |
| 404 | std::cout << "possibleStates: " << unsigned(bf->byte) << std::endl; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | void printPDRMsg(const uint32_t nextRecordHndl, const uint16_t respCnt, |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 409 | uint8_t* data) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 410 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 411 | if (data == NULL) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 412 | { |
| 413 | return; |
| 414 | } |
| 415 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 416 | std::cout << "nextRecordHandle: " << nextRecordHndl << std::endl; |
| 417 | std::cout << "responseCount: " << respCnt << std::endl; |
| 418 | |
| 419 | struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data; |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 420 | printCommonPDRHeader(pdr); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 421 | switch (pdr->type) |
| 422 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 423 | case PLDM_NUMERIC_EFFECTER_PDR: |
| 424 | printNumericEffecterPDR(data); |
| 425 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 426 | case PLDM_STATE_EFFECTER_PDR: |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 427 | printStateEffecterPDR(data); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 428 | break; |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 429 | case PLDM_PDR_ENTITY_ASSOCIATION: |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 430 | printPDREntityAssociation(data); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 431 | break; |
| 432 | case PLDM_PDR_FRU_RECORD_SET: |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 433 | printPDRFruRecordSet(data); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 434 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 435 | default: |
| 436 | break; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | private: |
| 441 | uint32_t recordHandle; |
| 442 | }; |
| 443 | |
| 444 | class SetStateEffecter : public CommandInterface |
| 445 | { |
| 446 | public: |
| 447 | ~SetStateEffecter() = default; |
| 448 | SetStateEffecter() = delete; |
| 449 | SetStateEffecter(const SetStateEffecter&) = delete; |
| 450 | SetStateEffecter(SetStateEffecter&&) = default; |
| 451 | SetStateEffecter& operator=(const SetStateEffecter&) = delete; |
| 452 | SetStateEffecter& operator=(SetStateEffecter&&) = default; |
| 453 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 454 | // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2) |
| 455 | static constexpr auto maxEffecterDataSize = 16; |
| 456 | |
| 457 | // compositeEffecterCount(value: 0x01 to 0x08) |
| 458 | static constexpr auto minEffecterCount = 1; |
| 459 | static constexpr auto maxEffecterCount = 8; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 460 | explicit SetStateEffecter(const char* type, const char* name, |
| 461 | CLI::App* app) : |
| 462 | CommandInterface(type, name, app) |
| 463 | { |
| 464 | app->add_option( |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 465 | "-i, --id", effecterId, |
| 466 | "A handle that is used to identify and access the effecter") |
| 467 | ->required(); |
| 468 | app->add_option("-c, --count", effecterCount, |
| 469 | "The number of individual sets of effecter information") |
| 470 | ->required(); |
| 471 | app->add_option( |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 472 | "-d,--data", effecterData, |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 473 | "Set effecter state data\n" |
| 474 | "eg: requestSet0 effecterState0 noChange1 dummyState1 ...") |
| 475 | ->required(); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 479 | { |
| 480 | std::vector<uint8_t> requestMsg( |
| 481 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES); |
| 482 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 483 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 484 | if (effecterCount > maxEffecterCount || |
| 485 | effecterCount < minEffecterCount) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 486 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 487 | std::cerr << "Request Message Error: effecterCount size " |
| 488 | << effecterCount << "is invalid\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 489 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 490 | return {rc, requestMsg}; |
| 491 | } |
| 492 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 493 | if (effecterData.size() > maxEffecterDataSize) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 494 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 495 | std::cerr << "Request Message Error: effecterData size " |
| 496 | << effecterData.size() << "is invalid\n"; |
| 497 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 498 | return {rc, requestMsg}; |
| 499 | } |
| 500 | |
| 501 | auto stateField = parseEffecterData(effecterData, effecterCount); |
| 502 | if (!stateField) |
| 503 | { |
| 504 | std::cerr << "Failed to parse effecter data, effecterCount size " |
| 505 | << effecterCount << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 506 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 507 | return {rc, requestMsg}; |
| 508 | } |
| 509 | |
| 510 | auto rc = encode_set_state_effecter_states_req( |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 511 | instanceId, effecterId, effecterCount, stateField->data(), request); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 512 | return {rc, requestMsg}; |
| 513 | } |
| 514 | |
| 515 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 516 | { |
| 517 | uint8_t completionCode = 0; |
| 518 | auto rc = decode_set_state_effecter_states_resp( |
| 519 | responsePtr, payloadLength, &completionCode); |
| 520 | |
| 521 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 522 | { |
| 523 | std::cerr << "Response Message Error: " |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 524 | << "rc=" << rc << ",cc=" << (int)completionCode << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 525 | return; |
| 526 | } |
| 527 | |
| 528 | std::cout << "SetStateEffecterStates: SUCCESS" << std::endl; |
| 529 | } |
| 530 | |
| 531 | private: |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 532 | uint16_t effecterId; |
| 533 | uint8_t effecterCount; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 534 | std::vector<uint8_t> effecterData; |
| 535 | }; |
| 536 | |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 537 | class SetNumericEffecterValue : public CommandInterface |
| 538 | { |
| 539 | public: |
| 540 | ~SetNumericEffecterValue() = default; |
| 541 | SetNumericEffecterValue() = delete; |
| 542 | SetNumericEffecterValue(const SetNumericEffecterValue&) = delete; |
| 543 | SetNumericEffecterValue(SetNumericEffecterValue&&) = default; |
| 544 | SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete; |
| 545 | SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default; |
| 546 | |
| 547 | explicit SetNumericEffecterValue(const char* type, const char* name, |
| 548 | CLI::App* app) : |
| 549 | CommandInterface(type, name, app) |
| 550 | { |
| 551 | app->add_option( |
| 552 | "-i, --id", effecterId, |
| 553 | "A handle that is used to identify and access the effecter") |
| 554 | ->required(); |
| 555 | app->add_option("-s, --size", effecterDataSize, |
| 556 | "The bit width and format of the setting value for the " |
| 557 | "effecter. enum value: {uint8, sint8, uint16, sint16, " |
| 558 | "uint32, sint32}\n") |
| 559 | ->required(); |
| 560 | app->add_option("-d,--data", maxEffecterValue, |
| 561 | "The setting value of numeric effecter being " |
| 562 | "requested\n") |
| 563 | ->required(); |
| 564 | } |
| 565 | |
| 566 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 567 | { |
| 568 | std::vector<uint8_t> requestMsg( |
| 569 | sizeof(pldm_msg_hdr) + |
| 570 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3); |
| 571 | |
| 572 | uint8_t* effecterValue = (uint8_t*)&maxEffecterValue; |
| 573 | |
| 574 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 575 | size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES; |
| 576 | |
| 577 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 578 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16) |
| 579 | { |
| 580 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1; |
| 581 | } |
| 582 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 583 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32) |
| 584 | { |
| 585 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3; |
| 586 | } |
| 587 | auto rc = encode_set_numeric_effecter_value_req( |
| 588 | 0, effecterId, effecterDataSize, effecterValue, request, |
| 589 | payload_length); |
| 590 | |
| 591 | return {rc, requestMsg}; |
| 592 | } |
| 593 | |
| 594 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 595 | { |
| 596 | uint8_t completionCode = 0; |
| 597 | auto rc = decode_set_numeric_effecter_value_resp( |
| 598 | responsePtr, payloadLength, &completionCode); |
| 599 | |
| 600 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 601 | { |
| 602 | std::cerr << "Response Message Error: " |
| 603 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 604 | << std::endl; |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | std::cout << "SetNumericEffecterValue: SUCCESS" << std::endl; |
| 609 | } |
| 610 | |
| 611 | private: |
| 612 | uint16_t effecterId; |
| 613 | uint8_t effecterDataSize; |
| 614 | uint64_t maxEffecterValue; |
| 615 | }; |
| 616 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 617 | void registerCommand(CLI::App& app) |
| 618 | { |
| 619 | auto platform = app.add_subcommand("platform", "platform type command"); |
| 620 | platform->require_subcommand(1); |
| 621 | |
| 622 | auto getPDR = |
| 623 | platform->add_subcommand("GetPDR", "get platform descriptor records"); |
| 624 | commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR)); |
| 625 | |
| 626 | auto setStateEffecterStates = platform->add_subcommand( |
| 627 | "SetStateEffecterStates", "set effecter states"); |
| 628 | commands.push_back(std::make_unique<SetStateEffecter>( |
| 629 | "platform", "setStateEffecterStates", setStateEffecterStates)); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 630 | |
| 631 | auto setNumericEffecterValue = platform->add_subcommand( |
| 632 | "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter"); |
| 633 | commands.push_back(std::make_unique<SetNumericEffecterValue>( |
| 634 | "platform", "setNumericEffecterValue", setNumericEffecterValue)); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | } // namespace platform |
| 638 | } // namespace pldmtool |