Vpd Tool Defect.
Output from the vpd-tool for any non printable character
will be in hex.
Previously the non printable characters were represented in
unicode encoding standard.
Fixed the defect.
Tested on simics for the below cases:
Case 1:
./vpd-tool -r -O /system/chassis/motherboard/ebmc_card_bmc -R VCFG -K Z0
{
"/system/chassis/motherboard/ebmc_card_bmc": {
"Z0": "0x001125c10000"
}
}
Case 2:
./vpd-tool -r -O /system/chassis/motherboard -R VSBP -K IM
{
"/system/chassis/motherboard": {
"IM": "0x50001001"
}
}
Case 3:
./vpd-tool -r -O /system/chassis/motherboard/ebmc_card_bmc -R VW10 -K DR
{
"/system/chassis/motherboard/ebmc_card_bmc": {
"DR": "EBMC VW10 "
}
}
Signed-off-by: PriyangaRamasamy <priyanga24@in.ibm.com>
Change-Id: Ia815b5818f64327eb070f21b06283bff0acd2207
diff --git a/vpd_tool_impl.cpp b/vpd_tool_impl.cpp
index 26ff983..5ffb041 100644
--- a/vpd_tool_impl.cpp
+++ b/vpd_tool_impl.cpp
@@ -23,6 +23,40 @@
}
}
+string VpdTool::getPrintableValue(const vector<unsigned char>& vec)
+{
+ string str{};
+ bool printableChar = true;
+ for (auto i : vec)
+ {
+ if (!isprint(i))
+ {
+ printableChar = false;
+ break;
+ }
+ }
+
+ if (!printableChar)
+ {
+ stringstream ss;
+ string hexRep = "0x";
+ ss << hexRep;
+ str = ss.str();
+
+ // convert Decimal to Hex
+ for (auto& v : vec)
+ {
+ ss << setfill('0') << setw(2) << hex << (int)v;
+ str = ss.str();
+ }
+ }
+ else
+ {
+ str = string(vec.begin(), vec.end());
+ }
+ return str;
+}
+
void VpdTool::eraseInventoryPath(string& fru)
{
// Power supply frupath comes with INVENTORY_PATH appended in prefix.
@@ -126,7 +160,8 @@
if (auto vec = get_if<Binary>(&response))
{
- kwVal.emplace(kw, string(vec->begin(), vec->end()));
+ string printableVal = getPrintableValue(*vec);
+ kwVal.emplace(kw, printableVal);
}
}
catch (const SdBusError& e)
@@ -296,10 +331,12 @@
makeDBusCall(INVENTORY_PATH + fruPath, interface + recordName, keyword)
.read(response);
+ string printableVal{};
if (auto vec = get_if<Binary>(&response))
{
- kwVal.emplace(keyword, string(vec->begin(), vec->end()));
+ printableVal = getPrintableValue(*vec);
}
+ kwVal.emplace(keyword, printableVal);
output.emplace(fruPath, kwVal);
@@ -309,35 +346,6 @@
{
json output = json::object({});
json kwVal = json::object({});
-
- if (e.id == 316) // invalid UTF-8 byte exception
- {
- stringstream ss;
- string hexByte;
- string hexRep = "0x";
- ss << hexRep;
- hexByte = ss.str();
-
- // convert Decimal to Hex
- if (auto resp = get_if<Binary>(&response))
- {
- for (auto& vec : *resp)
- {
- if ((int)vec == 0)
- {
- ss << hex << (int)vec;
- hexByte = ss.str();
- }
- ss << hex << (int)vec;
- hexByte = ss.str();
- }
- }
-
- kwVal.emplace(keyword, hexByte);
- output.emplace(fruPath, kwVal);
-
- debugger(output);
- }
}
}
diff --git a/vpd_tool_impl.hpp b/vpd_tool_impl.hpp
index 8757c31..b490fcc 100644
--- a/vpd_tool_impl.hpp
+++ b/vpd_tool_impl.hpp
@@ -3,6 +3,7 @@
#include "types.hpp"
#include <nlohmann/json.hpp>
+#include <string>
using json = nlohmann::json;
@@ -162,6 +163,18 @@
void forceReset(const nlohmann::basic_json<>& jsObject);
/**
+ * @brief Get Printable Value
+ *
+ * Checks if the vector value has non printable characters.
+ * And returns hex value if non printable char is found else
+ * returns ascii value.
+ *
+ * @param[in] vector - Reference of the Binary vector
+ * @return printable value - either in hex or in ascii.
+ */
+ std::string getPrintableValue(const std::vector<unsigned char>& vec);
+
+ /**
* @brief Constructor
* Constructor is called during the
* object instantiation for dumpInventory option and