From 2343148da81a06c5776c5ca80f26e30a72b8c758 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 28 Mar 2022 11:15:24 +0200 Subject: [PATCH 1/4] core: introduce "unavailable" rfkill state Introduce a new "unavailable" rfkill state to indicate that no rfkill hardware was found. Currently it is still handled as "unblocked". --- src/core/nm-manager.c | 5 +++++ src/core/nm-rfkill-manager.c | 14 ++++++++------ src/core/nm-rfkill-manager.h | 9 +++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index 046fa819e9..05650f79bf 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -2323,6 +2323,11 @@ _rfkill_radio_state_set_from_manager(NMRfkillManager *rfkill_mgr, RfkillRadioState *rstate) { switch (nm_rfkill_manager_get_rfkill_state(rfkill_mgr, rtype)) { + case NM_RFKILL_STATE_UNAVAILABLE: + rstate->sw_enabled = TRUE; + rstate->hw_enabled = TRUE; + rstate->os_owner = TRUE; + return; case NM_RFKILL_STATE_UNBLOCKED: rstate->sw_enabled = TRUE; rstate->hw_enabled = TRUE; diff --git a/src/core/nm-rfkill-manager.c b/src/core/nm-rfkill-manager.c index 9eac097294..60404c5321 100644 --- a/src/core/nm-rfkill-manager.c +++ b/src/core/nm-rfkill-manager.c @@ -84,6 +84,8 @@ static const char * nm_rfkill_state_to_string(NMRfkillState state) { switch (state) { + case NM_RFKILL_STATE_UNAVAILABLE: + return "unavailable"; case NM_RFKILL_STATE_UNBLOCKED: return "unblocked"; case NM_RFKILL_STATE_SOFT_BLOCKED: @@ -188,8 +190,8 @@ recheck_killswitches(NMRfkillManager *self) /* Default state is unblocked */ for (i = 0; i < NM_RFKILL_TYPE_MAX; i++) { - poll_states[i] = NM_RFKILL_STATE_UNBLOCKED; - platform_states[i] = NM_RFKILL_STATE_UNBLOCKED; + poll_states[i] = NM_RFKILL_STATE_UNAVAILABLE; + platform_states[i] = NM_RFKILL_STATE_UNAVAILABLE; platform_checked[i] = FALSE; } @@ -222,12 +224,12 @@ recheck_killswitches(NMRfkillManager *self) dev_state = sysfs_state_to_nm_state(sysfs_state, sysfs_reason); nm_log_dbg(LOGD_RFKILL, - "%s rfkill%s switch %s state now %d/%u reason: 0x%x", + "%s rfkill%s switch %s state now %d/%s reason: 0x%x", nm_rfkill_type_to_string(ks->rtype), ks->platform ? " platform" : "", ks->name, sysfs_state, - dev_state, + nm_rfkill_state_to_string(dev_state), sysfs_reason); if (ks->platform == FALSE) { @@ -248,7 +250,7 @@ recheck_killswitches(NMRfkillManager *self) /* blocked platform switch state overrides device state, otherwise * let the device state stand. (bgo #655773) */ - if (platform_states[i] != NM_RFKILL_STATE_UNBLOCKED) + if (platform_states[i] > NM_RFKILL_STATE_UNBLOCKED) poll_states[i] = platform_states[i]; } @@ -396,7 +398,7 @@ nm_rfkill_manager_init(NMRfkillManager *self) c_list_init(&priv->killswitch_lst_head); for (i = 0; i < NM_RFKILL_TYPE_MAX; i++) - priv->rfkill_states[i] = NM_RFKILL_STATE_UNBLOCKED; + priv->rfkill_states[i] = NM_RFKILL_STATE_UNAVAILABLE; priv->udev_client = nm_udev_client_new(NM_MAKE_STRV("rfkill"), handle_uevent, self); diff --git a/src/core/nm-rfkill-manager.h b/src/core/nm-rfkill-manager.h index a9c723f154..acca144532 100644 --- a/src/core/nm-rfkill-manager.h +++ b/src/core/nm-rfkill-manager.h @@ -8,16 +8,17 @@ #define __NM_RFKILL_MANAGER_H__ typedef enum { - NM_RFKILL_STATE_UNBLOCKED = 0, - NM_RFKILL_STATE_SOFT_BLOCKED = 1, - NM_RFKILL_STATE_HARD_BLOCKED = 2, + NM_RFKILL_STATE_UNAVAILABLE = 0, + NM_RFKILL_STATE_UNBLOCKED = 1, + NM_RFKILL_STATE_SOFT_BLOCKED = 2, + NM_RFKILL_STATE_HARD_BLOCKED = 3, /* NM_RFKILL_STATE_HARD_BLOCKED_OS_NOT_OWNER means that the CSME firmware * is currently controlling the device. This feature is implmented on Intel * wifi devices only. * The NetworkManager can get ownership on the device, but it requires to * first ask ownership through the iwlmei kernel module. */ - NM_RFKILL_STATE_HARD_BLOCKED_OS_NOT_OWNER = 3, + NM_RFKILL_STATE_HARD_BLOCKED_OS_NOT_OWNER = 4, } NMRfkillState; typedef enum { From 580ef03bee96aec3d361d95569c88207ac0ddddb Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 21 Mar 2022 10:19:37 +0100 Subject: [PATCH 2/4] core: export radio flags Introduce a RadioFlags property on the manager object. For now it contains two bits WLAN_AVAILABLE, WWAN_AVAILABLE to indicate whether any radio interface is present in the system. The presence of a radio is detected by looking at devices and rfkill switches. In future, any radio-related read-only boolean flag can be exposed via this property, including the already existing WirelessHardwareEnabled and WwanHardwareEnabled properties. --- .../org.freedesktop.NetworkManager.xml | 10 +++ src/core/nm-manager.c | 75 +++++++++++++++---- src/core/nm-manager.h | 1 + src/core/nm-rfkill-manager.c | 14 ++++ src/core/nm-rfkill-manager.h | 2 + src/libnm-core-public/nm-dbus-interface.h | 18 +++++ 6 files changed, 107 insertions(+), 13 deletions(-) diff --git a/introspection/org.freedesktop.NetworkManager.xml b/introspection/org.freedesktop.NetworkManager.xml index b0ac658b2d..65859881ba 100644 --- a/introspection/org.freedesktop.NetworkManager.xml +++ b/introspection/org.freedesktop.NetworkManager.xml @@ -384,6 +384,16 @@ --> + + +