diff mbox series

[4/4] rfkill: support hard block reason in C code

Message ID 20210116125146.31932-5-markus.theil@tu-ilmenau.de
State New
Headers show
Series Updates for rfkill | expand

Commit Message

Markus Theil Jan. 16, 2021, 12:51 p.m. UTC
Signed-off-by: Markus Theil <markus.theil@tu-ilmenau.de>
---
 rfkill.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/rfkill.c b/rfkill.c
index 8cd81fe..7fa5c39 100644
--- a/rfkill.c
+++ b/rfkill.c
@@ -51,15 +51,16 @@  static void rfkill_event(void)
 			break;
 		}
 
-		if (len != RFKILL_EVENT_SIZE_V1) {
+		if (len != RFKILL_EVENT_SIZE_V1 && len != RFKILL_EVENT_SIZE_V1 + 1) {
 			fprintf(stderr, "Wrong size of RFKILL event\n");
 			continue;
 		}
 
 		gettimeofday(&tv, NULL);
-		printf("%ld.%06u: idx %u type %u op %u soft %u hard %u\n",
+		printf("%ld.%06u: idx %u type %u op %u soft %u hard %u hard block reasons 0x%02x\n",
 			(long) tv.tv_sec, (unsigned int) tv.tv_usec,
-			event.idx, event.type, event.op, event.soft, event.hard);
+			event.idx, event.type, event.op, event.soft, event.hard,
+			event.hard_block_reasons);
 		fflush(stdout);
 	}
 
@@ -214,7 +215,7 @@  static int rfkill_list(const char *param)
 			break;
 		}
 
-		if (len != RFKILL_EVENT_SIZE_V1) {
+		if (len != RFKILL_EVENT_SIZE_V1 && len != RFKILL_EVENT_SIZE_V1 + 1) {
 			fprintf(stderr, "Wrong size of RFKILL event\n");
 			continue;
 		}
@@ -242,6 +243,16 @@  static int rfkill_list(const char *param)
 						type2string(event.type));
 		printf("\tSoft blocked: %s\n", event.soft ? "yes" : "no");
 		printf("\tHard blocked: %s\n", event.hard ? "yes" : "no");
+		if (len >= RFKILL_EVENT_SIZE_V1 + 1) {
+			printf("\tHard block reasons: ");
+			if (event.hard_block_reasons == 0)
+				printf("[NONE]");
+			if (event.hard_block_reasons & RFKILL_HARD_BLOCK_NOT_OWNER)
+				printf("[NOT_OWNER]");
+			if (event.hard_block_reasons & RFKILL_HARD_BLOCK_SIGNAL)
+				printf("[SIGNAL]");
+			printf("\n");
+		}
 	}
 
 	close(fd);