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 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 341 | if (!stringTable) |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 342 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 343 | std::cerr << "GetBIOSStringTable Error" << std::endl; |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 344 | return; |
| 345 | } |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 346 | std::cout << "PLDM StringTable: " << std::endl; |
| 347 | std::cout << "BIOSStringHandle : BIOSString" << std::endl; |
| 348 | |
| 349 | for (auto tableEntry : BIOSTableIter<PLDM_BIOS_STRING_TABLE>( |
| 350 | stringTable->data(), stringTable->size())) |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 351 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 352 | auto strHandle = |
| 353 | pldm_bios_table_string_entry_decode_handle(tableEntry); |
| 354 | auto strTableData = decodeStringFromStringEntry(tableEntry); |
| 355 | std::cout << strHandle << " : " << strTableData << std::endl; |
| 356 | } |
| 357 | } |
| 358 | void decodeAttributeTable(const std::optional<Table>& attrTable, |
| 359 | const std::optional<Table>& stringTable) |
| 360 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 361 | if (!stringTable) |
| 362 | { |
| 363 | std::cerr << "GetBIOSAttributeTable Error" << std::endl; |
| 364 | return; |
| 365 | } |
| 366 | std::cout << "PLDM AttributeTable: " << std::endl; |
| 367 | for (auto entry : BIOSTableIter<PLDM_BIOS_ATTR_TABLE>( |
| 368 | attrTable->data(), attrTable->size())) |
| 369 | { |
| 370 | auto attrHandle = |
| 371 | pldm_bios_table_attr_entry_decode_attribute_handle(entry); |
| 372 | auto attrNameHandle = |
| 373 | pldm_bios_table_attr_entry_decode_string_handle(entry); |
| 374 | auto attrType = static_cast<pldm_bios_attribute_type>( |
| 375 | pldm_bios_table_attr_entry_decode_attribute_type(entry)); |
| 376 | std::cout << "AttributeHandle: " << attrHandle |
| 377 | << ", AttributeNameHandle: " |
| 378 | << displayStringHandle(attrNameHandle, stringTable) |
| 379 | << std::endl; |
| 380 | std::cout << "\tAttributeType: " << attrTypeMap.at(attrType) |
| 381 | << std::endl; |
| 382 | switch (attrType) |
| 383 | { |
| 384 | case PLDM_BIOS_ENUMERATION: |
| 385 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
| 386 | { |
| 387 | auto pvNum = |
| 388 | pldm_bios_table_attr_entry_enum_decode_pv_num(entry); |
| 389 | std::vector<uint16_t> pvHandls(pvNum); |
| 390 | pldm_bios_table_attr_entry_enum_decode_pv_hdls( |
| 391 | entry, pvHandls.data(), pvHandls.size()); |
| 392 | auto defNum = |
| 393 | pldm_bios_table_attr_entry_enum_decode_def_num(entry); |
| 394 | std::vector<uint8_t> defIndices(defNum); |
| 395 | pldm_bios_table_attr_entry_enum_decode_def_indices( |
| 396 | entry, defIndices.data(), defIndices.size()); |
| 397 | std::cout << "\tNumberOfPossibleValues: " << (int)pvNum |
| 398 | << std::endl; |
| 399 | |
| 400 | for (size_t i = 0; i < pvHandls.size(); i++) |
| 401 | { |
| 402 | std::cout |
| 403 | << "\t\tPossibleValueStringHandle" |
| 404 | << "[" << i << "] = " |
| 405 | << displayStringHandle(pvHandls[i], stringTable) |
| 406 | << std::endl; |
| 407 | } |
| 408 | std::cout << "\tNumberOfDefaultValues: " << (int)defNum |
| 409 | << std::endl; |
| 410 | for (size_t i = 0; i < defIndices.size(); i++) |
| 411 | { |
| 412 | std::cout << "\t\tDefaultValueStringHandleIndex" |
| 413 | << "[" << i << "] = " << (int)defIndices[i] |
| 414 | << ", StringHandle = " |
| 415 | << displayStringHandle( |
| 416 | pvHandls[defIndices[i]], stringTable) |
| 417 | << std::endl; |
| 418 | } |
| 419 | break; |
| 420 | } |
| 421 | case PLDM_BIOS_INTEGER: |
| 422 | case PLDM_BIOS_INTEGER_READ_ONLY: |
| 423 | { |
| 424 | uint64_t lower, upper, def; |
| 425 | uint32_t scalar; |
| 426 | pldm_bios_table_attr_entry_integer_decode( |
| 427 | entry, &lower, &upper, &scalar, &def); |
| 428 | std::cout << "\tLowerBound: " << lower << std::endl |
| 429 | << "\tUpperBound: " << upper << std::endl |
| 430 | << "\tScalarIncrement: " << scalar << std::endl |
| 431 | << "\tDefaultValue: " << def << std::endl; |
| 432 | break; |
| 433 | } |
| 434 | case PLDM_BIOS_STRING: |
| 435 | case PLDM_BIOS_STRING_READ_ONLY: |
| 436 | { |
| 437 | auto strType = |
| 438 | pldm_bios_table_attr_entry_string_decode_string_type( |
| 439 | entry); |
| 440 | auto min = |
| 441 | pldm_bios_table_attr_entry_string_decode_min_length( |
| 442 | entry); |
| 443 | auto max = |
| 444 | pldm_bios_table_attr_entry_string_decode_max_length( |
| 445 | entry); |
| 446 | auto def = |
| 447 | pldm_bios_table_attr_entry_string_decode_def_string_length( |
| 448 | entry); |
| 449 | std::vector<char> defString(def + 1); |
| 450 | pldm_bios_table_attr_entry_string_decode_def_string( |
| 451 | entry, defString.data(), defString.size()); |
| 452 | std::cout |
| 453 | << "\tStringType: 0x" << std::hex << std::setw(2) |
| 454 | << std::setfill('0') << (int)strType << std::dec |
| 455 | << std::setw(0) << std::endl |
| 456 | << "\tMinimumStringLength: " << (int)min << std::endl |
| 457 | << "\tMaximumStringLength: " << (int)max << std::endl |
| 458 | << "\tDefaultStringLength: " << (int)def << std::endl |
| 459 | << "\tDefaultString: " << defString.data() << std::endl; |
| 460 | break; |
| 461 | } |
| 462 | case PLDM_BIOS_PASSWORD: |
| 463 | case PLDM_BIOS_PASSWORD_READ_ONLY: |
| 464 | std::cout << "Password attribute: Not Supported" |
| 465 | << std::endl; |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | void decodeAttributeValueTable(const std::optional<Table>& attrValTable, |
| 470 | const std::optional<Table>& attrTable, |
| 471 | const std::optional<Table>& stringTable) |
| 472 | { |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 473 | if (!attrValTable) |
| 474 | { |
| 475 | std::cerr << "GetBIOSAttributeValueTable Error" << std::endl; |
| 476 | return; |
| 477 | } |
| 478 | std::cout << "PLDM AttributeValueTable: " << std::endl; |
| 479 | for (auto tableEntry : BIOSTableIter<PLDM_BIOS_ATTR_VAL_TABLE>( |
| 480 | attrValTable->data(), attrValTable->size())) |
| 481 | { |
| 482 | auto attrHandle = |
| 483 | pldm_bios_table_attr_value_entry_decode_attribute_handle( |
| 484 | tableEntry); |
| 485 | auto attrType = static_cast<pldm_bios_attribute_type>( |
| 486 | pldm_bios_table_attr_value_entry_decode_attribute_type( |
| 487 | tableEntry)); |
| 488 | std::cout << "AttributeHandle: " << attrHandle << std::endl; |
| 489 | std::cout << "\tAttributeType: " << attrTypeMap.at(attrType) |
| 490 | << std::endl; |
| 491 | switch (attrType) |
| 492 | { |
| 493 | case PLDM_BIOS_ENUMERATION: |
| 494 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
| 495 | { |
| 496 | |
| 497 | auto count = |
| 498 | pldm_bios_table_attr_value_entry_enum_decode_number( |
| 499 | tableEntry); |
| 500 | std::vector<uint8_t> handles(count); |
| 501 | pldm_bios_table_attr_value_entry_enum_decode_handles( |
| 502 | tableEntry, handles.data(), handles.size()); |
| 503 | std::cout << "\tNumberOfCurrentValues: " << (int)count |
| 504 | << std::endl; |
| 505 | for (size_t i = 0; i < handles.size(); i++) |
| 506 | { |
| 507 | std::cout |
| 508 | << "\tCurrentValueStringHandleIndex[" << i |
| 509 | << "] = " << (int)handles[i] << ", StringHandle = " |
| 510 | << displayEnumValueByIndex(attrHandle, handles[i], |
| 511 | attrTable, stringTable) |
| 512 | << std::endl; |
| 513 | } |
| 514 | break; |
| 515 | } |
| 516 | case PLDM_BIOS_INTEGER: |
| 517 | case PLDM_BIOS_INTEGER_READ_ONLY: |
| 518 | { |
| 519 | auto cv = |
| 520 | pldm_bios_table_attr_value_entry_integer_decode_cv( |
| 521 | tableEntry); |
| 522 | std::cout << "\tCurrentValue: " << cv << std::endl; |
| 523 | break; |
| 524 | } |
| 525 | case PLDM_BIOS_STRING: |
| 526 | case PLDM_BIOS_STRING_READ_ONLY: |
| 527 | { |
| 528 | auto stringLength = |
| 529 | pldm_bios_table_attr_value_entry_string_decode_length( |
| 530 | tableEntry); |
| 531 | variable_field currentString; |
| 532 | pldm_bios_table_attr_value_entry_string_decode_string( |
| 533 | tableEntry, ¤tString); |
| 534 | std::cout << "\tCurrentStringLength: " << stringLength |
| 535 | << std::endl |
| 536 | << "\tCurrentString: " |
| 537 | << std::string(reinterpret_cast<const char*>( |
| 538 | currentString.ptr), |
| 539 | currentString.length) |
| 540 | << std::endl; |
| 541 | |
| 542 | break; |
| 543 | } |
| 544 | case PLDM_BIOS_PASSWORD: |
| 545 | case PLDM_BIOS_PASSWORD_READ_ONLY: |
| 546 | std::cout << "Password attribute: Not Supported" |
| 547 | << std::endl; |
| 548 | } |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | }; |
| 552 | |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 553 | void registerCommand(CLI::App& app) |
| 554 | { |
| 555 | auto bios = app.add_subcommand("bios", "bios type command"); |
| 556 | bios->require_subcommand(1); |
| 557 | auto getDateTime = bios->add_subcommand("GetDateTime", "get date time"); |
| 558 | commands.push_back( |
| 559 | std::make_unique<GetDateTime>("bios", "GetDateTime", getDateTime)); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 560 | |
| 561 | auto setDateTime = |
| 562 | bios->add_subcommand("SetDateTime", "set host date time"); |
| 563 | commands.push_back( |
| 564 | std::make_unique<SetDateTime>("bios", "setDateTime", setDateTime)); |
Sridevi Ramesh | cdfe114 | 2020-01-31 05:42:50 -0600 | [diff] [blame] | 565 | |
| 566 | auto getBIOSTable = bios->add_subcommand("GetBIOSTable", "get bios table"); |
| 567 | commands.push_back( |
| 568 | std::make_unique<GetBIOSTable>("bios", "GetBIOSTable", getBIOSTable)); |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | } // namespace bios |
| 572 | |
| 573 | } // namespace pldmtool |