FruDevice: Check for language code
Currently we are supporting only english language for 8 bit ascii
string parsing. If language code detected as non english, we still
allows parsing for language independent data like binary, bcd type
etc but for language dependent data with type code (11) mentioned
in section 13 of FRU specification, we are reporting this as an
error for non english language code. As per section 10, chassis
area info will always be in english that's why it doesn't have
any language bytes in it's field header.
Signed-off-by: Vijay Khemka <vijaykhemkalinux@gmail.com>
Change-Id: I3dec0d37110f877da48e484104281389d54047a8
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index ffae574..79e142a 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -694,7 +694,8 @@
*/
static std::pair<DecodeState, std::string>
decodeFRUData(std::vector<uint8_t>::const_iterator& iter,
- const std::vector<uint8_t>::const_iterator& end)
+ const std::vector<uint8_t>::const_iterator& end,
+ bool isLangEng)
{
std::string value;
unsigned int i;
@@ -743,6 +744,17 @@
/* For language-code dependent encodings, assume 8-bit ASCII */
value = std::string(iter, iter + len);
iter += len;
+
+ /* English text is encoded in 8-bit ASCII + Latin 1. All other
+ * languages are required to use 2-byte unicode. FruDevice does not
+ * handle unicode.
+ */
+ if (!isLangEng)
+ {
+ std::cerr << "Error: Non english string is not supported \n";
+ return make_pair(DecodeState::err, value);
+ }
+
break;
case FRUDataEncoding::bcdPlus:
@@ -778,14 +790,20 @@
return make_pair(DecodeState::ok, value);
}
-static void checkLang(uint8_t lang)
+static bool checkLangEng(uint8_t lang)
{
// If Lang is not English then the encoding is defined as 2-byte UNICODE,
// but we don't support that.
if (lang && lang != 25)
{
- std::cerr << "Warning: language other then English is not "
- "supported \n";
+ std::cerr << "Warning: languages other than English is not "
+ "supported\n";
+ // Return language flag as non english
+ return false;
+ }
+ else
+ {
+ return true;
}
}
@@ -932,6 +950,10 @@
ret = resCodes::resWarn;
}
+ /* Set default language flag to true as Chassis Fru area are always
+ * encoded in English defined in Section 10 of Fru specification
+ */
+ bool isLangEng = true;
switch (area)
{
case fruAreas::fruAreaChassis:
@@ -947,7 +969,7 @@
uint8_t lang = *fruBytesIter;
result["BOARD_LANGUAGE_CODE"] =
std::to_string(static_cast<int>(lang));
- checkLang(lang);
+ isLangEng = checkLangEng(lang);
fruBytesIter += 1;
unsigned int minutes = *fruBytesIter |
@@ -978,7 +1000,7 @@
uint8_t lang = *fruBytesIter;
result["PRODUCT_LANGUAGE_CODE"] =
std::to_string(static_cast<int>(lang));
- checkLang(lang);
+ isLangEng = checkLangEng(lang);
fruBytesIter += 1;
fruAreaFieldNames = &PRODUCT_FRU_AREAS;
break;
@@ -994,7 +1016,8 @@
DecodeState state;
do
{
- auto res = decodeFRUData(fruBytesIter, fruBytesIterEndArea);
+ auto res =
+ decodeFRUData(fruBytesIter, fruBytesIterEndArea, isLangEng);
state = res.first;
std::string value = res.second;
std::string name;