2021-02-06 15:36:37

by Markus Theil

[permalink] [raw]
Subject: [PATCH 1/3] rfkill: update rfkill.h

Signed-off-by: Markus Theil <[email protected]>
---
rfkill.h | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/rfkill.h b/rfkill.h
index 058757f..03e8af8 100644
--- a/rfkill.h
+++ b/rfkill.h
@@ -59,6 +59,8 @@ enum rfkill_type {
* @RFKILL_OP_DEL: a device was removed
* @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device
* @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all)
+ * into a state, also updating the default state used for devices that
+ * are hot-plugged later.
*/
enum rfkill_operation {
RFKILL_OP_ADD = 0,
@@ -67,6 +69,16 @@ enum rfkill_operation {
RFKILL_OP_CHANGE_ALL,
};

+/**
+ * enum rfkill_hard_block_reasons - hard block reasons
+ * @RFKILL_HARD_BLOCK_SIGNAL: the hardware rfkill signal is active
+ * @RFKILL_HARD_BLOCK_NOT_OWNER: the NIC is not owned by the host
+ */
+enum rfkill_hard_block_reasons {
+ RFKILL_HARD_BLOCK_SIGNAL = 1 << 0,
+ RFKILL_HARD_BLOCK_NOT_OWNER = 1 << 1,
+};
+
/**
* struct rfkill_event - events for userspace on /dev/rfkill
* @idx: index of dev rfkill
@@ -74,6 +86,8 @@ enum rfkill_operation {
* @op: operation code
* @hard: hard state (0/1)
* @soft: soft state (0/1)
+ * @hard_block_reasons: valid if hard is set. One or several reasons from
+ * &enum rfkill_hard_block_reasons.
*
* Structure used for userspace communication on /dev/rfkill,
* used for events from the kernel and control to the kernel.
@@ -82,7 +96,9 @@ struct rfkill_event {
__u32 idx;
__u8 type;
__u8 op;
- __u8 soft, hard;
+ __u8 soft;
+ __u8 hard;
+ __u8 hard_block_reasons;
} __attribute__((packed));

/*
--
2.30.0


2021-02-06 15:37:29

by Markus Theil

[permalink] [raw]
Subject: [PATCH 2/3] rfkill.c: deal with updated struct size

Signed-off-by: Markus Theil <[email protected]>
---
rfkill.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/rfkill.c b/rfkill.c
index 8cd81fe..6b5ca2c 100644
--- a/rfkill.c
+++ b/rfkill.c
@@ -45,13 +45,14 @@ static void rfkill_event(void)
if (n == 0)
continue;

+ memset(&event, 0, sizeof(event));
len = read(fd, &event, sizeof(event));
if (len < 0) {
perror("Reading of RFKILL events failed");
break;
}

- if (len != RFKILL_EVENT_SIZE_V1) {
+ if (len < RFKILL_EVENT_SIZE_V1) {
fprintf(stderr, "Wrong size of RFKILL event\n");
continue;
}
@@ -206,6 +207,7 @@ static int rfkill_list(const char *param)
}

while (1) {
+ memset(&event, 0, sizeof(event));
len = read(fd, &event, sizeof(event));
if (len < 0) {
if (errno == EAGAIN)
@@ -214,7 +216,7 @@ static int rfkill_list(const char *param)
break;
}

- if (len != RFKILL_EVENT_SIZE_V1) {
+ if (len < RFKILL_EVENT_SIZE_V1) {
fprintf(stderr, "Wrong size of RFKILL event\n");
continue;
}
--
2.30.0

2021-02-06 15:37:47

by Markus Theil

[permalink] [raw]
Subject: [PATCH 3/3] rfkill: support hard block reason in C code

Signed-off-by: Markus Theil <[email protected]>
---
rfkill.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/rfkill.c b/rfkill.c
index 6b5ca2c..253ee46 100644
--- a/rfkill.c
+++ b/rfkill.c
@@ -58,9 +58,10 @@ static void rfkill_event(void)
}

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);
}

@@ -244,6 +245,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);
--
2.30.0