From patchwork Sat Feb 6 15:34:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 378302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21B0CC433DB for ; Sat, 6 Feb 2021 15:35:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B83BD64E84 for ; Sat, 6 Feb 2021 15:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230090AbhBFPfR (ORCPT ); Sat, 6 Feb 2021 10:35:17 -0500 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:40985 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbhBFPfQ (ORCPT ); Sat, 6 Feb 2021 10:35:16 -0500 Received: from isengard.fritz.box (unknown [87.147.51.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 154C358005E; Sat, 6 Feb 2021 16:34:34 +0100 (CET) From: Markus Theil To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Markus Theil Subject: [PATCH 1/3] rfkill: update rfkill.h Date: Sat, 6 Feb 2021 16:34:09 +0100 Message-Id: <20210206153411.19097-1-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Signed-off-by: Markus Theil --- 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)); /* From patchwork Sat Feb 6 15:34:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 377901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19D77C433DB for ; Sat, 6 Feb 2021 15:36:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0E6664E86 for ; Sat, 6 Feb 2021 15:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230179AbhBFPfV (ORCPT ); Sat, 6 Feb 2021 10:35:21 -0500 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:40988 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbhBFPfQ (ORCPT ); Sat, 6 Feb 2021 10:35:16 -0500 Received: from isengard.fritz.box (unknown [87.147.51.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 3E9C5580060; Sat, 6 Feb 2021 16:34:34 +0100 (CET) From: Markus Theil To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Markus Theil Subject: [PATCH 2/3] rfkill.c: deal with updated struct size Date: Sat, 6 Feb 2021 16:34:10 +0100 Message-Id: <20210206153411.19097-2-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210206153411.19097-1-markus.theil@tu-ilmenau.de> References: <20210206153411.19097-1-markus.theil@tu-ilmenau.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Signed-off-by: Markus Theil --- 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; } From patchwork Sat Feb 6 15:34:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 378301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 352E3C433E0 for ; Sat, 6 Feb 2021 15:36:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAED664E84 for ; Sat, 6 Feb 2021 15:35:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbhBFPf7 (ORCPT ); Sat, 6 Feb 2021 10:35:59 -0500 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:41000 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbhBFPf7 (ORCPT ); Sat, 6 Feb 2021 10:35:59 -0500 Received: from isengard.fritz.box (unknown [87.147.51.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 65CE758006C; Sat, 6 Feb 2021 16:34:34 +0100 (CET) From: Markus Theil To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Markus Theil Subject: [PATCH 3/3] rfkill: support hard block reason in C code Date: Sat, 6 Feb 2021 16:34:11 +0100 Message-Id: <20210206153411.19097-3-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210206153411.19097-1-markus.theil@tu-ilmenau.de> References: <20210206153411.19097-1-markus.theil@tu-ilmenau.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Signed-off-by: Markus Theil --- 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);