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/.

Kévin Redon gerrit-no-reply at lists.osmocom.org
Tue Jul 10 14:04:08 UTC 2018


Kévin Redon has uploaded this change for review. ( 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, 58 insertions(+), 29 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/46/9946/1

diff --git a/host/simtrace2-sniff.c b/host/simtrace2-sniff.c
index d5fe48a..765ced3 100644
--- a/host/simtrace2-sniff.c
+++ b/host/simtrace2-sniff.c
@@ -94,6 +94,58 @@
 	return 0;
 }
 
+struct flag_meaning_t {
+	const uint32_t flag;
+	const char* meaning;
+};
+
+const struct flag_meaning_t change_flags[] = {
+	{
+		.flag = SNIFF_CHANGE_FLAG_CARD_INSERT,
+		.meaning = "card inserted",
+	},
+	{
+		.flag = SNIFF_CHANGE_FLAG_CARD_EJECT,
+		.meaning = "card ejected",
+	},
+	{
+		.flag = SNIFF_CHANGE_FLAG_RESET_HOLD,
+		.meaning = "reset hold",
+	},
+	{
+		.flag = SNIFF_CHANGE_FLAG_RESET_RELEASE,
+		.meaning = "reset release",
+	},
+	{
+		.flag = SNIFF_CHANGE_FLAG_TIMEOUT_WT,
+		.meaning = "data transfer timeout",
+	},
+};
+
+const struct flag_meaning_t data_flags[] = {
+	{
+		.flag = SNIFF_DATA_FLAG_ERROR_INCOMPLETE,
+		.meaning = "incomplete",
+	},
+	{
+		.flag = SNIFF_DATA_FLAG_ERROR_MALFORMED,
+		.meaning = "malformed",
+	},
+};
+
+static void print_flags(const struct flag_meaning_t* flag_meanings, uint32_t nb_flags, uint32_t flags) {
+	uint32_t i;
+	for (i = 0; i < nb_flags; i++) {
+		if (flags & flag_meanings[i].flag) {
+			printf(flag_meanings[i].meaning);
+			flags &= ~flag_meanings[i].flag;
+			if (flags) {
+				printf(", ");
+			}
+		}
+	}
+}
+
 static int process_change(const uint8_t *buf, int len)
 {
 	/* check if there is enough data for the structure */
@@ -103,22 +155,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 +218,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: newchange
Gerrit-Change-Id: If3c0a4790662bcc64db5ff03adcc033836e16ad0
Gerrit-Change-Number: 9946
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180710/0ed8c6b5/attachment.htm>


More information about the gerrit-log mailing list