[PATCH] lib: fwts_dump_data: add function for simply dump raw data
Ivan Hu
ivan.hu at canonical.com
Fri Jun 9 03:45:33 UTC 2023
BugLink: https://bugs.launchpad.net/fwts/+bug/2023351
The generic dump function could simply dump raw data without address and
readable ASCII printout.
instead dumping
Vendor-specific data:
0000: 12 23 34 45 56 67 78 89 9A AB BC CD DE EF FF 55 .#4EVgx........U
Interface:
Interface Type: 0x01
Reserved: 0x00000000
It could add prefix for data alignment as well.
Signed-off-by: Ivan Hu <ivan.hu at canonical.com>
---
src/lib/include/fwts_dump_data.h | 1 +
src/lib/src/fwts_dump_data.c | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/src/lib/include/fwts_dump_data.h b/src/lib/include/fwts_dump_data.h
index 3dea7e45..5e255754 100644
--- a/src/lib/include/fwts_dump_data.h
+++ b/src/lib/include/fwts_dump_data.h
@@ -23,5 +23,6 @@
#include "fwts.h"
void fwts_dump_raw_data(char *buffer, const size_t len, const uint8_t *data, const int where, const size_t bytes);
+void fwts_dump_raw_data_prefix(char *buffer, const size_t len, const uint8_t *data, const char *prefix, const size_t bytes);
#endif
diff --git a/src/lib/src/fwts_dump_data.c b/src/lib/src/fwts_dump_data.c
index a56f3230..60287a9d 100644
--- a/src/lib/src/fwts_dump_data.c
+++ b/src/lib/src/fwts_dump_data.c
@@ -61,3 +61,29 @@ void fwts_dump_raw_data(
buffer[n++] = (data[i] < 32 || data[i] > 126) ? '.' : data[i];
buffer[n] = '\0';
}
+
+/*
+ * fwts_dump_raw_data_prefix()
+ * simply print raw uint8 data of length `nbytes` into a buffer (length len)
+ * as a hex dump. nbytes must be no more than 16 with prefix. The prefix could
+ * be used as alighment.
+ */
+void fwts_dump_raw_data_prefix(
+ char *buffer, /* buffer to contained formatted dump */
+ const size_t len, /* Length of buffer */
+ const uint8_t *data, /* Octects to dump */
+ const char *prefix, /* Prefix string or for alignment */
+ const size_t nbytes) /* Number of bytes to dump, max 16 */
+{
+ int i;
+ int n = 0;
+ int nbytes_max = nbytes > 16 ? 16 : nbytes;
+
+ n = snprintf(buffer, len, "%s", prefix);
+
+ /* Hex dump */
+ for (i = 0; i < nbytes_max; i++)
+ n += snprintf(buffer + n, len - n, "%2.2X ", data[i]);
+
+ buffer[n] = '\0';
+}
--
2.34.1
More information about the fwts-devel
mailing list