Fix "ID String Type/Length Code" byte for get sdr command
Root cause :
Currently, the byte of "Type/Length Code" for dbus-sdr
get sdr record command is incorrect when the length of
sensor name is longer than 16 bytes. The suffix of the
sensor name would be replace with blank and resize the
sensor name with FULL_RECORD_ID_STR_MAX_LENGTH. Due to
this reason the "Type/Length Code" would record incorrect
data 0x10 (i.e. 16 bytes length sensor ID string).
Solution :
Resizing the sensor name when it is still longer than 16
bytes after replacing the suffix with blank.
Example :
Sensor Name = cpu0_pvccd_hv_Output_Current
The result of getting SDR record without this change.
0a 00 09 00 51 01 3b 20 00 09 07 1d 00 68 03 01
04 22 04 22 12 12 80 05 00 00 b8 00 b0 00 00 d2
00 00 00 00 00 00 00 79 00 00 85 00 00 00 00 00
00 d0 63 70 75 30 5f 70 76 63 63 64 5f 68 76 00
00 00
The result of getting SDR record with this change.
0a 00 09 00 51 01 3b 20 00 09 07 1d 00 68 03 01
04 22 04 22 12 12 80 05 00 00 b8 00 b0 00 00 d2
00 00 00 00 00 00 00 79 00 00 85 00 00 00 00 00
00 cd 63 70 75 30 5f 70 76 63 63 64 5f 68 76 00
00 00
Tested:
Check the type/length byte is correct through ipmi cmd.
Google-Bug-Id: 315753500
Google-Bug-Id: 318615639
Change-Id: I0a89ab967ee58166037c71c85750783a15a19ad2
Signed-off-by: Duke Du <Duke.Du@quantatw.com>
(cherry picked from commit 83d772ae2ce548b2c289811d940c03dfa5cbcf5a)
diff --git a/recipes-phosphor/ipmi/phosphor-ipmi-host/0003-Fix-ID-String-Type-Length-Code-byte-for-get-sdr-comm.patch b/recipes-phosphor/ipmi/phosphor-ipmi-host/0003-Fix-ID-String-Type-Length-Code-byte-for-get-sdr-comm.patch
new file mode 100644
index 0000000..b485e8a
--- /dev/null
+++ b/recipes-phosphor/ipmi/phosphor-ipmi-host/0003-Fix-ID-String-Type-Length-Code-byte-for-get-sdr-comm.patch
@@ -0,0 +1,66 @@
+From 589142a6617a28edd089f68f767897494dcd05a8 Mon Sep 17 00:00:00 2001
+From: Duke Du <Duke.Du@quantatw.com>
+Date: Wed, 20 Dec 2023 10:19:36 +0800
+Subject: [PATCH] Fix "ID String Type/Length Code" byte for get sdr command
+
+Root cause :
+Currently, the byte of "Type/Length Code" for dbus-sdr
+get sdr record command is incorrect when the length of
+sensor name is longer than 16 bytes. The suffix of the
+sensor name would be replace with blank and resize the
+sensor name with FULL_RECORD_ID_STR_MAX_LENGTH. Due to
+this reason the "Type/Length Code" would record incorrect
+data 0x10 (i.e. 16 bytes length sensor ID string).
+
+Solution :
+Resizing the sensor name when it is still longer than 16
+bytes after replacing the suffix with blank.
+
+Example :
+Sensor Name = cpu0_pvccd_hv_Output_Current
+
+The result of getting SDR record without this change.
+0a 00 09 00 51 01 3b 20 00 09 07 1d 00 68 03 01
+04 22 04 22 12 12 80 05 00 00 b8 00 b0 00 00 d2
+00 00 00 00 00 00 00 79 00 00 85 00 00 00 00 00
+00 d0 63 70 75 30 5f 70 76 63 63 64 5f 68 76 00
+00 00
+
+The result of getting SDR record with this change.
+0a 00 09 00 51 01 3b 20 00 09 07 1d 00 68 03 01
+04 22 04 22 12 12 80 05 00 00 b8 00 b0 00 00 d2
+00 00 00 00 00 00 00 79 00 00 85 00 00 00 00 00
+00 cd 63 70 75 30 5f 70 76 63 63 64 5f 68 76 00
+00 00
+
+Resize code reference:
+https://gerrit.openbmc.org/c/openbmc/phosphor-host-ipmid/+/49755
+
+Upstream info / review: https://gerrit.openbmc.org/c/openbmc/phosphor-host-ipmid/+/68337
+Upstream-Status: Submitted
+Justification: Fix "ID String Type/Length Code" byte for get sdr command (b/315753500).
+Google-Bug-Id: 315753500
+Signed-off-by: Duke Du <Duke.Du@quantatw.com>
+---
+ dbus-sdr/sdrutils.cpp | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/dbus-sdr/sdrutils.cpp b/dbus-sdr/sdrutils.cpp
+index 07d67747..3cc0e691 100644
+--- a/dbus-sdr/sdrutils.cpp
++++ b/dbus-sdr/sdrutils.cpp
+@@ -67,7 +67,10 @@ std::string parseSdrIdFromPath(const std::string& path)
+ #endif
+
+ // as a backup and if nothing else is configured
+- name.resize(FULL_RECORD_ID_STR_MAX_LENGTH);
++ if (name.size() > FULL_RECORD_ID_STR_MAX_LENGTH)
++ {
++ name.resize(FULL_RECORD_ID_STR_MAX_LENGTH);
++ }
+ }
+ return name;
+ }
+--
+2.34.1
+
diff --git a/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend b/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend
index a30963d..7884436 100644
--- a/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend
+++ b/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend
@@ -4,4 +4,5 @@
FILESEXTRAPATHS:prepend:gbmc := "${THISDIR}/phosphor-ipmi-host:"
SRC_URI:append:gbmc = " \
file://0002-Support-packing-cable-presence-sensor-state-into-dis.patch \
+ file://0003-Fix-ID-String-Type-Length-Code-byte-for-get-sdr-comm.patch \
"