Change in simtrace2[master]: host sniff: add functions to print flags

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Jul 11 20:32:46 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/9946 )

Change subject: host sniff: add functions to print flags
......................................................................

host sniff: add functions to print flags

Change-Id: If3c0a4790662bcc64db5ff03adcc033836e16ad0
---
M host/simtrace2-sniff.c
1 file changed, 61 insertions(+), 29 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/host/simtrace2-sniff.c b/host/simtrace2-sniff.c
index d5fe48a..efb986f 100644
--- a/host/simtrace2-sniff.c
+++ b/host/simtrace2-sniff.c
@@ -94,6 +94,61 @@
 	return 0;
 }
 
+const struct value_string change_flags[] = {
+	{
+		.value = SNIFF_CHANGE_FLAG_CARD_INSERT,
+		.str = "card inserted",
+	},
+	{
+		.value = SNIFF_CHANGE_FLAG_CARD_EJECT,
+		.str = "card ejected",
+	},
+	{
+		.value = SNIFF_CHANGE_FLAG_RESET_HOLD,
+		.str = "reset hold",
+	},
+	{
+		.value = SNIFF_CHANGE_FLAG_RESET_RELEASE,
+		.str = "reset release",
+	},
+	{
+		.value = SNIFF_CHANGE_FLAG_TIMEOUT_WT,
+		.str = "data transfer timeout",
+	},
+	{
+		.value = 0,
+		.str = NULL,
+	},
+};
+
+const struct value_string data_flags[] = {
+	{
+		.value = SNIFF_DATA_FLAG_ERROR_INCOMPLETE,
+		.str = "incomplete",
+	},
+	{
+		.value = SNIFF_DATA_FLAG_ERROR_MALFORMED,
+		.str = "malformed",
+	},
+	{
+		.value = 0,
+		.str = NULL,
+	},
+};
+
+static void print_flags(const struct value_string* flag_meanings, uint32_t nb_flags, uint32_t flags) {
+	uint32_t i;
+	for (i = 0; i < nb_flags; i++) {
+		if (flags & flag_meanings[i].value) {
+			printf(flag_meanings[i].str);
+			flags &= ~flag_meanings[i].value;
+			if (flags) {
+				printf(", ");
+			}
+		}
+	}
+}
+
 static int process_change(const uint8_t *buf, int len)
 {
 	/* check if there is enough data for the structure */
@@ -103,22 +158,12 @@
 	struct sniff_change *change = (struct sniff_change *)buf;
 
 	printf("Card state change: ");
-	if (change->flags&SNIFF_CHANGE_FLAG_CARD_INSERT) {
-		printf("card inserted ");
+	if (change->flags) {
+		print_flags(change_flags, ARRAY_SIZE(change_flags), change->flags);
+		printf("\n");
+	} else {
+		printf("no changes\n");
 	}
-	if (change->flags&SNIFF_CHANGE_FLAG_CARD_EJECT) {
-		printf("card ejected ");
-	}
-	if (change->flags&SNIFF_CHANGE_FLAG_RESET_HOLD) {
-		printf("reset hold ");
-	}
-	if (change->flags&SNIFF_CHANGE_FLAG_RESET_RELEASE) {
-		printf("reset release ");
-	}
-	if (change->flags&SNIFF_CHANGE_FLAG_TIMEOUT_WT) {
-		printf("data transfer timeout ");
-	}
-	printf("\n");
 
 	return 0;
 }
@@ -176,20 +221,7 @@
 	}
 	if (data->flags) {
 		printf(" (");
-		if (data->flags & SNIFF_DATA_FLAG_ERROR_INCOMPLETE) {
-			printf("incomplete");
-			data->flags &= ~SNIFF_DATA_FLAG_ERROR_INCOMPLETE;
-			if (data->flags) {
-				printf(", ");
-			}
-		}
-		if (data->flags & SNIFF_DATA_FLAG_ERROR_MALFORMED) {
-			printf("malformed");
-			data->flags &= ~SNIFF_DATA_FLAG_ERROR_MALFORMED;
-			if (data->flags) {
-				printf(", ");
-			}
-		}
+		print_flags(data_flags, ARRAY_SIZE(data_flags), data->flags);
 		printf(")");
 	}
 	printf(": ");

-- 
To view, visit https://gerrit.osmocom.org/9946
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: If3c0a4790662bcc64db5ff03adcc033836e16ad0
Gerrit-Change-Number: 9946
Gerrit-PatchSet: 6
Gerrit-Owner: Kévin Redon <kredon at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180711/a5238064/attachment.htm>


More information about the gerrit-log mailing list