Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 1 | #include "pldm_bios_cmd.hpp" |
| 2 | |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 3 | #include "bios_utils.hpp" |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 4 | #include "pldm_cmd_helper.hpp" |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 5 | #include "utils.hpp" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <optional> |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 9 | |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 10 | #include "libpldm/bios_table.h" |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 11 | #include "libpldm/utils.h" |
| 12 | |
| 13 | namespace pldmtool |
| 14 | { |
| 15 | |
| 16 | namespace bios |
| 17 | { |
| 18 | |
| 19 | namespace |
| 20 | { |
| 21 | |
| 22 | using namespace pldmtool::helper; |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 23 | using namespace pldm::bios::utils; |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 24 | |
| 25 | std::vector<std::unique_ptr<CommandInterface>> commands; |
| 26 | |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 27 | const std::map<const char*, pldm_bios_table_types> pldmBIOSTableTypes{ |
| 28 | {"StringTable", PLDM_BIOS_STRING_TABLE}, |
| 29 | {"AttributeTable", PLDM_BIOS_ATTR_TABLE}, |
| 30 | {"AttributeValueTable", PLDM_BIOS_ATTR_VAL_TABLE}, |
| 31 | }; |
| 32 | |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 33 | } // namespace |
| 34 | |
| 35 | class GetDateTime : public CommandInterface |
| 36 | { |
| 37 | public: |
| 38 | ~GetDateTime() = default; |
| 39 | GetDateTime() = delete; |
| 40 | GetDateTime(const GetDateTime&) = delete; |
| 41 | GetDateTime(GetDateTime&&) = default; |
| 42 | GetDateTime& operator=(const GetDateTime&) = delete; |
| 43 | GetDateTime& operator=(GetDateTime&&) = default; |
| 44 | |
| 45 | using CommandInterface::CommandInterface; |
| 46 | |
| 47 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 48 | { |
| 49 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr)); |
| 50 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 51 | |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 52 | auto rc = encode_get_date_time_req(instanceId, request); |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 53 | return {rc, requestMsg}; |
| 54 | } |
| 55 | |
| 56 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 57 | { |
| 58 | uint8_t cc = 0; |
| 59 | |
| 60 | uint8_t seconds, minutes, hours, day, month; |
| 61 | uint16_t year; |
| 62 | auto rc = |
| 63 | decode_get_date_time_resp(responsePtr, payloadLength, &cc, &seconds, |
| 64 | &minutes, &hours, &day, &month, &year); |
| 65 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 66 | { |
| 67 | std::cerr << "Response Message Error: " |
| 68 | << "rc=" << rc << ",cc=" << (int)cc << std::endl; |
| 69 | return; |
| 70 | } |
| 71 | std::cout << "Date & Time : " << std::endl; |
Sridevi Ramesh | 213a855 | 2020-02-03 00:59:30 -0600 | [diff] [blame] | 72 | std::cout << "YYYY-MM-DD HH:MM:SS - "; |
| 73 | std::cout << bcd2dec16(year); |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 74 | std::cout << "-"; |
| 75 | setWidth(month); |
Sridevi Ramesh | 213a855 | 2020-02-03 00:59:30 -0600 | [diff] [blame] | 76 | std::cout << "-"; |
| 77 | setWidth(day); |
| 78 | std::cout << " "; |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 79 | setWidth(hours); |
| 80 | std::cout << ":"; |
| 81 | setWidth(minutes); |
| 82 | std::cout << ":"; |
| 83 | setWidth(seconds); |
| 84 | std::cout << std::endl; |
| 85 | } |
| 86 | |
| 87 | private: |
| 88 | void setWidth(uint8_t data) |
| 89 | { |
| 90 | std::cout << std::setfill('0') << std::setw(2) |
| 91 | << static_cast<uint32_t>(bcd2dec8(data)); |
| 92 | } |
| 93 | }; |
| 94 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 95 | class SetDateTime : public CommandInterface |
| 96 | { |
| 97 | public: |
| 98 | ~SetDateTime() = default; |
| 99 | SetDateTime() = delete; |
| 100 | SetDateTime(const SetDateTime&) = delete; |
| 101 | SetDateTime(SetDateTime&&) = default; |
| 102 | SetDateTime& operator=(const SetDateTime&) = delete; |
| 103 | SetDateTime& operator=(SetDateTime&&) = default; |
| 104 | |
| 105 | explicit SetDateTime(const char* type, const char* name, CLI::App* app) : |
| 106 | CommandInterface(type, name, app) |
| 107 | { |
| 108 | app->add_option("-d,--data", tmData, |
| 109 | "set date time data\n" |
| 110 | "eg: YYYYMMDDHHMMSS") |
| 111 | ->required(); |
| 112 | } |
| 113 | |
| 114 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 115 | { |
| 116 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 117 | sizeof(struct pldm_set_date_time_req)); |
| 118 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 119 | uint16_t year = 0; |
| 120 | uint8_t month = 0; |
| 121 | uint8_t day = 0; |
| 122 | uint8_t hours = 0; |
| 123 | uint8_t minutes = 0; |
| 124 | uint8_t seconds = 0; |
| 125 | |
| 126 | if (!uintToDate(tmData, &year, &month, &day, &hours, &minutes, |
| 127 | &seconds)) |
| 128 | { |
| 129 | std::cerr << "decode date Error: " |
| 130 | << "tmData=" << tmData << std::endl; |
| 131 | |
| 132 | return {PLDM_ERROR_INVALID_DATA, requestMsg}; |
| 133 | } |
| 134 | |
| 135 | auto rc = encode_set_date_time_req( |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 136 | instanceId, seconds, minutes, hours, day, month, year, request, |
| 137 | sizeof(struct pldm_set_date_time_req)); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 138 | |
| 139 | return {rc, requestMsg}; |
| 140 | } |
| 141 | |
| 142 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 143 | { |
| 144 | uint8_t completionCode = 0; |
| 145 | auto rc = decode_set_date_time_resp(responsePtr, payloadLength, |
| 146 | &completionCode); |
| 147 | |
| 148 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 149 | { |
| 150 | std::cerr << "Response Message Error: " |
| 151 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 152 | << std::endl; |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | std::cout << "SetDateTime: SUCCESS" << std::endl; |
| 157 | } |
| 158 | |
| 159 | private: |
| 160 | uint64_t tmData; |
| 161 | }; |
| 162 | |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 163 | class GetBIOSTable : public CommandInterface |
| 164 | { |
| 165 | public: |
| 166 | ~GetBIOSTable() = default; |
| 167 | GetBIOSTable() = delete; |
| 168 | GetBIOSTable(const GetBIOSTable&) = delete; |
| 169 | GetBIOSTable(GetBIOSTable&&) = default; |
| 170 | GetBIOSTable& operator=(const GetBIOSTable&) = delete; |
| 171 | GetBIOSTable& operator=(GetBIOSTable&&) = default; |
| 172 | |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 173 | using Table = std::vector<uint8_t>; |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 174 | |
| 175 | explicit GetBIOSTable(const char* type, const char* name, CLI::App* app) : |
| 176 | CommandInterface(type, name, app) |
| 177 | { |
| 178 | app->add_option("-t,--type", pldmBIOSTableType, "pldm bios table type") |
| 179 | ->required() |
| 180 | ->transform( |
| 181 | CLI::CheckedTransformer(pldmBIOSTableTypes, CLI::ignore_case)); |
| 182 | } |
| 183 | |
| 184 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 185 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 186 | return {PLDM_ERROR, {}}; |
| 187 | } |
| 188 | void parseResponseMsg(pldm_msg*, size_t) override |
| 189 | { |
| 190 | } |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 191 | |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 192 | std::optional<Table> getBIOSTable(pldm_bios_table_types tableType) |
| 193 | { |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 194 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 195 | PLDM_GET_BIOS_TABLE_REQ_BYTES); |
| 196 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 197 | |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 198 | auto rc = encode_get_bios_table_req(instanceId, 0, PLDM_GET_FIRSTPART, |
| 199 | tableType, request); |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 200 | if (rc != PLDM_SUCCESS) |
| 201 | { |
| 202 | std::cerr << "Encode GetBIOSTable Error, tableType=," << tableType |
| 203 | << " ,rc=" << rc << std::endl; |
| 204 | return std::nullopt; |
| 205 | } |
| 206 | std::vector<uint8_t> responseMsg; |
| 207 | rc = pldmSendRecv(requestMsg, responseMsg); |
| 208 | if (rc != PLDM_SUCCESS) |
| 209 | { |
| 210 | std::cerr << "PLDM: Communication Error, rc =" << rc << std::endl; |
| 211 | return std::nullopt; |
| 212 | } |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 213 | |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 214 | uint8_t cc = 0, transferFlag = 0; |
| 215 | uint32_t nextTransferHandle = 0; |
| 216 | size_t bios_table_offset; |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 217 | auto responsePtr = |
| 218 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 219 | auto payloadLength = responseMsg.size() - sizeof(pldm_msg_hdr); |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 220 | |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 221 | rc = decode_get_bios_table_resp(responsePtr, payloadLength, &cc, |
| 222 | &nextTransferHandle, &transferFlag, |
| 223 | &bios_table_offset); |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 224 | |
| 225 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 226 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 227 | std::cerr << "GetBIOSTable Response Error: tableType=" << tableType |
| 228 | << ", rc=" << rc << ", cc=" << (int)cc << std::endl; |
| 229 | return std::nullopt; |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 230 | } |
| 231 | auto tableData = |
| 232 | reinterpret_cast<char*>((responsePtr->payload) + bios_table_offset); |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 233 | auto tableSize = payloadLength - sizeof(nextTransferHandle) - |
| 234 | sizeof(transferFlag) - sizeof(cc); |
| 235 | return std::make_optional<Table>(tableData, tableData + tableSize); |
| 236 | } |
| 237 | |
| 238 | void exec() override |
| 239 | { |
| 240 | |
| 241 | switch (pldmBIOSTableType) |
| 242 | { |
| 243 | case PLDM_BIOS_STRING_TABLE: |
| 244 | { |
| 245 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 246 | decodeStringTable(stringTable); |
| 247 | break; |
| 248 | } |
| 249 | case PLDM_BIOS_ATTR_TABLE: |
| 250 | { |
| 251 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 252 | auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE); |
| 253 | |
| 254 | decodeAttributeTable(attrTable, stringTable); |
| 255 | } |
| 256 | break; |
| 257 | case PLDM_BIOS_ATTR_VAL_TABLE: |
| 258 | { |
| 259 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 260 | auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE); |
| 261 | auto attrValTable = getBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE); |
| 262 | |
| 263 | decodeAttributeValueTable(attrValTable, attrTable, stringTable); |
| 264 | break; |
| 265 | } |
| 266 | } |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | private: |
| 270 | pldm_bios_table_types pldmBIOSTableType; |
| 271 | |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 272 | static inline const std::map<pldm_bios_attribute_type, const char*> |
| 273 | attrTypeMap = { |
| 274 | {PLDM_BIOS_ENUMERATION, "BIOSEnumeration"}, |
| 275 | {PLDM_BIOS_ENUMERATION_READ_ONLY, "BIOSEnumerationReadOnly"}, |
| 276 | {PLDM_BIOS_STRING, "BIOSString"}, |
| 277 | {PLDM_BIOS_STRING_READ_ONLY, "BIOSStringReadOnly"}, |
| 278 | {PLDM_BIOS_PASSWORD, "BIOSPassword"}, |
| 279 | {PLDM_BIOS_PASSWORD_READ_ONLY, "BIOSPasswordReadOnly"}, |
| 280 | {PLDM_BIOS_INTEGER, "BIOSInteger"}, |
| 281 | {PLDM_BIOS_INTEGER_READ_ONLY, "BIOSIntegerReadOnly"}, |
| 282 | |
| 283 | }; |
| 284 | |
| 285 | std::string decodeStringFromStringEntry( |
| 286 | const pldm_bios_string_table_entry* stringEntry) |
| 287 | { |
| 288 | auto strLength = |
| 289 | pldm_bios_table_string_entry_decode_string_length(stringEntry); |
| 290 | std::vector<char> buffer(strLength + 1 /* sizeof '\0' */); |
| 291 | pldm_bios_table_string_entry_decode_string(stringEntry, buffer.data(), |
| 292 | buffer.size()); |
| 293 | |
| 294 | return std::string(buffer.data(), buffer.data() + strLength); |
| 295 | } |
| 296 | |
| 297 | std::string displayStringHandle(uint16_t handle, |
| 298 | const std::optional<Table>& stringTable) |
| 299 | { |
| 300 | std::string displayString = std::to_string(handle); |
| 301 | if (!stringTable) |
| 302 | { |
| 303 | return displayString; |
| 304 | } |
| 305 | auto stringEntry = pldm_bios_table_string_find_by_handle( |
| 306 | stringTable->data(), stringTable->size(), handle); |
| 307 | if (stringEntry == nullptr) |
| 308 | { |
| 309 | return displayString; |
| 310 | } |
| 311 | |
| 312 | return displayString + "(" + decodeStringFromStringEntry(stringEntry) + |
| 313 | ")"; |
| 314 | } |
| 315 | |
| 316 | std::string displayEnumValueByIndex(uint16_t attrHandle, uint8_t index, |
| 317 | const std::optional<Table>& attrTable, |
| 318 | const std::optional<Table>& stringTable) |
| 319 | { |
| 320 | std::string displayString; |
| 321 | if (!attrTable) |
| 322 | { |
| 323 | return displayString; |
| 324 | } |
| 325 | |
| 326 | auto attrEntry = pldm_bios_table_attr_find_by_handle( |
| 327 | attrTable->data(), attrTable->size(), attrHandle); |
| 328 | if (attrEntry == nullptr) |
| 329 | { |
| 330 | return displayString; |
| 331 | } |
| 332 | auto pvNum = pldm_bios_table_attr_entry_enum_decode_pv_num(attrEntry); |
| 333 | std::vector<uint16_t> pvHandls(pvNum); |
| 334 | pldm_bios_table_attr_entry_enum_decode_pv_hdls( |
| 335 | attrEntry, pvHandls.data(), pvHandls.size()); |
| 336 | return displayStringHandle(pvHandls[index], stringTable); |
| 337 | } |
| 338 | |
| 339 | void decodeStringTable(const std::optional<Table>& stringTable) |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 340 | { |
| 341 | std::cout << "Parsed Response Msg: " << std::endl; |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 342 | if (!stringTable) |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 343 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 344 | std::cerr << "GetBIOSStringTable Error" << std::endl; |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 345 | return; |
| 346 | } |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 347 | std::cout << "PLDM StringTable: " << std::endl; |
| 348 | std::cout << "BIOSStringHandle : BIOSString" << std::endl; |
| 349 | |
| 350 | for (auto tableEntry : BIOSTableIter<PLDM_BIOS_STRING_TABLE>( |
| 351 | stringTable->data(), stringTable->size())) |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 352 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 353 | auto strHandle = |
| 354 | pldm_bios_table_string_entry_decode_handle(tableEntry); |
| 355 | auto strTableData = decodeStringFromStringEntry(tableEntry); |
| 356 | std::cout << strHandle << " : " << strTableData << std::endl; |
| 357 | } |
| 358 | } |
| 359 | void decodeAttributeTable(const std::optional<Table>& attrTable, |
| 360 | const std::optional<Table>& stringTable) |
| 361 | { |
| 362 | std::cout << "Parsed Response Msg: " << std::endl; |
| 363 | if (!stringTable) |
| 364 | { |
| 365 | std::cerr << "GetBIOSAttributeTable Error" << std::endl; |
| 366 | return; |
| 367 | } |
| 368 | std::cout << "PLDM AttributeTable: " << std::endl; |
| 369 | for (auto entry : BIOSTableIter<PLDM_BIOS_ATTR_TABLE>( |
| 370 | attrTable->data(), attrTable->size())) |
| 371 | { |
| 372 | auto attrHandle = |
| 373 | pldm_bios_table_attr_entry_decode_attribute_handle(entry); |
| 374 | auto attrNameHandle = |
| 375 | pldm_bios_table_attr_entry_decode_string_handle(entry); |
| 376 | auto attrType = static_cast<pldm_bios_attribute_type>( |
| 377 | pldm_bios_table_attr_entry_decode_attribute_type(entry)); |
| 378 | std::cout << "AttributeHandle: " << attrHandle |
| 379 | << ", AttributeNameHandle: " |
| 380 | << displayStringHandle(attrNameHandle, stringTable) |
| 381 | << std::endl; |
| 382 | std::cout << "\tAttributeType: " << attrTypeMap.at(attrType) |
| 383 | << std::endl; |
| 384 | switch (attrType) |
| 385 | { |
| 386 | case PLDM_BIOS_ENUMERATION: |
| 387 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
| 388 | { |
| 389 | auto pvNum = |
| 390 | pldm_bios_table_attr_entry_enum_decode_pv_num(entry); |
| 391 | std::vector<uint16_t> pvHandls(pvNum); |
| 392 | pldm_bios_table_attr_entry_enum_decode_pv_hdls( |
| 393 | entry, pvHandls.data(), pvHandls.size()); |
| 394 | auto defNum = |
| 395 | pldm_bios_table_attr_entry_enum_decode_def_num(entry); |
| 396 | std::vector<uint8_t> defIndices(defNum); |
| 397 | pldm_bios_table_attr_entry_enum_decode_def_indices( |
| 398 | entry, defIndices.data(), defIndices.size()); |
| 399 | std::cout << "\tNumberOfPossibleValues: " << (int)pvNum |
| 400 | << std::endl; |
| 401 | |
| 402 | for (size_t i = 0; i < pvHandls.size(); i++) |
| 403 | { |
| 404 | std::cout |
| 405 | << "\t\tPossibleValueStringHandle" |
| 406 | << "[" << i << "] = " |
| 407 | << displayStringHandle(pvHandls[i], stringTable) |
| 408 | << std::endl; |
| 409 | } |
| 410 | std::cout << "\tNumberOfDefaultValues: " << (int)defNum |
| 411 | << std::endl; |
| 412 | for (size_t i = 0; i < defIndices.size(); i++) |
| 413 | { |
| 414 | std::cout << "\t\tDefaultValueStringHandleIndex" |
| 415 | << "[" << i << "] = " << (int)defIndices[i] |
| 416 | << ", StringHandle = " |
| 417 | << displayStringHandle( |
| 418 | pvHandls[defIndices[i]], stringTable) |
| 419 | << std::endl; |
| 420 | } |
| 421 | break; |
| 422 | } |
| 423 | case PLDM_BIOS_INTEGER: |
| 424 | case PLDM_BIOS_INTEGER_READ_ONLY: |
| 425 | { |
| 426 | uint64_t lower, upper, def; |
| 427 | uint32_t scalar; |
| 428 | pldm_bios_table_attr_entry_integer_decode( |
| 429 | entry, &lower, &upper, &scalar, &def); |
| 430 | std::cout << "\tLowerBound: " << lower << std::endl |
| 431 | << "\tUpperBound: " << upper << std::endl |
| 432 | << "\tScalarIncrement: " << scalar << std::endl |
| 433 | << "\tDefaultValue: " << def << std::endl; |
| 434 | break; |
| 435 | } |
| 436 | case PLDM_BIOS_STRING: |
| 437 | case PLDM_BIOS_STRING_READ_ONLY: |
| 438 | { |
| 439 | auto strType = |
| 440 | pldm_bios_table_attr_entry_string_decode_string_type( |
| 441 | entry); |
| 442 | auto min = |
| 443 | pldm_bios_table_attr_entry_string_decode_min_length( |
| 444 | entry); |
| 445 | auto max = |
| 446 | pldm_bios_table_attr_entry_string_decode_max_length( |
| 447 | entry); |
| 448 | auto def = |
| 449 | pldm_bios_table_attr_entry_string_decode_def_string_length( |
| 450 | entry); |
| 451 | std::vector<char> defString(def + 1); |
| 452 | pldm_bios_table_attr_entry_string_decode_def_string( |
| 453 | entry, defString.data(), defString.size()); |
| 454 | std::cout |
| 455 | << "\tStringType: 0x" << std::hex << std::setw(2) |
| 456 | << std::setfill('0') << (int)strType << std::dec |
| 457 | << std::setw(0) << std::endl |
| 458 | << "\tMinimumStringLength: " << (int)min << std::endl |
| 459 | << "\tMaximumStringLength: " << (int)max << std::endl |
| 460 | << "\tDefaultStringLength: " << (int)def << std::endl |
| 461 | << "\tDefaultString: " << defString.data() << std::endl; |
| 462 | break; |
| 463 | } |
| 464 | case PLDM_BIOS_PASSWORD: |
| 465 | case PLDM_BIOS_PASSWORD_READ_ONLY: |
| 466 | std::cout << "Password attribute: Not Supported" |
| 467 | << std::endl; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | void decodeAttributeValueTable(const std::optional<Table>& attrValTable, |
| 472 | const std::optional<Table>& attrTable, |
| 473 | const std::optional<Table>& stringTable) |
| 474 | { |
| 475 | std::cout << "Parsed Response Msg: " << std::endl; |
| 476 | if (!attrValTable) |
| 477 | { |
| 478 | std::cerr << "GetBIOSAttributeValueTable Error" << std::endl; |
| 479 | return; |
| 480 | } |
| 481 | std::cout << "PLDM AttributeValueTable: " << std::endl; |
| 482 | for (auto tableEntry : BIOSTableIter<PLDM_BIOS_ATTR_VAL_TABLE>( |
| 483 | attrValTable->data(), attrValTable->size())) |
| 484 | { |
| 485 | auto attrHandle = |
| 486 | pldm_bios_table_attr_value_entry_decode_attribute_handle( |
| 487 | tableEntry); |
| 488 | auto attrType = static_cast<pldm_bios_attribute_type>( |
| 489 | pldm_bios_table_attr_value_entry_decode_attribute_type( |
| 490 | tableEntry)); |
| 491 | std::cout << "AttributeHandle: " << attrHandle << std::endl; |
| 492 | std::cout << "\tAttributeType: " << attrTypeMap.at(attrType) |
| 493 | << std::endl; |
| 494 | switch (attrType) |
| 495 | { |
| 496 | case PLDM_BIOS_ENUMERATION: |
| 497 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
| 498 | { |
| 499 | |
| 500 | auto count = |
| 501 | pldm_bios_table_attr_value_entry_enum_decode_number( |
| 502 | tableEntry); |
| 503 | std::vector<uint8_t> handles(count); |
| 504 | pldm_bios_table_attr_value_entry_enum_decode_handles( |
| 505 | tableEntry, handles.data(), handles.size()); |
| 506 | std::cout << "\tNumberOfCurrentValues: " << (int)count |
| 507 | << std::endl; |
| 508 | for (size_t i = 0; i < handles.size(); i++) |
| 509 | { |
| 510 | std::cout |
| 511 | << "\tCurrentValueStringHandleIndex[" << i |
| 512 | << "] = " << (int)handles[i] << ", StringHandle = " |
| 513 | << displayEnumValueByIndex(attrHandle, handles[i], |
| 514 | attrTable, stringTable) |
| 515 | << std::endl; |
| 516 | } |
| 517 | break; |
| 518 | } |
| 519 | case PLDM_BIOS_INTEGER: |
| 520 | case PLDM_BIOS_INTEGER_READ_ONLY: |
| 521 | { |
| 522 | auto cv = |
| 523 | pldm_bios_table_attr_value_entry_integer_decode_cv( |
| 524 | tableEntry); |
| 525 | std::cout << "\tCurrentValue: " << cv << std::endl; |
| 526 | break; |
| 527 | } |
| 528 | case PLDM_BIOS_STRING: |
| 529 | case PLDM_BIOS_STRING_READ_ONLY: |
| 530 | { |
| 531 | auto stringLength = |
| 532 | pldm_bios_table_attr_value_entry_string_decode_length( |
| 533 | tableEntry); |
| 534 | variable_field currentString; |
| 535 | pldm_bios_table_attr_value_entry_string_decode_string( |
| 536 | tableEntry, ¤tString); |
| 537 | std::cout << "\tCurrentStringLength: " << stringLength |
| 538 | << std::endl |
| 539 | << "\tCurrentString: " |
| 540 | << std::string(reinterpret_cast<const char*>( |
| 541 | currentString.ptr), |
| 542 | currentString.length) |
| 543 | << std::endl; |
| 544 | |
| 545 | break; |
| 546 | } |
| 547 | case PLDM_BIOS_PASSWORD: |
| 548 | case PLDM_BIOS_PASSWORD_READ_ONLY: |
| 549 | std::cout << "Password attribute: Not Supported" |
| 550 | << std::endl; |
| 551 | } |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | }; |
| 555 | |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 556 | void registerCommand(CLI::App& app) |
| 557 | { |
| 558 | auto bios = app.add_subcommand("bios", "bios type command"); |
| 559 | bios->require_subcommand(1); |
| 560 | auto getDateTime = bios->add_subcommand("GetDateTime", "get date time"); |
| 561 | commands.push_back( |
| 562 | std::make_unique<GetDateTime>("bios", "GetDateTime", getDateTime)); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 563 | |
| 564 | auto setDateTime = |
| 565 | bios->add_subcommand("SetDateTime", "set host date time"); |
| 566 | commands.push_back( |
| 567 | std::make_unique<SetDateTime>("bios", "setDateTime", setDateTime)); |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 568 | |
| 569 | auto getBIOSTable = bios->add_subcommand("GetBIOSTable", "get bios table"); |
| 570 | commands.push_back( |
| 571 | std::make_unique<GetBIOSTable>("bios", "GetBIOSTable", getBIOSTable)); |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | } // namespace bios |
| 575 | |
| 576 | } // namespace pldmtool |