Commit graph

17 commits

Author SHA1 Message Date
Beniamino Galvani
580ef03bee 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.
2022-03-29 09:34:07 +02:00
Beniamino Galvani
2343148da8 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".
2022-03-29 09:12:36 +02:00
Emmanuel Grumbach
237c028e53
rfkill: fix the rfkill reason property query and parsing
The udev property is RFKILL_HW_BLOCK_REASON and it is returned as a
bitmap in hexadecimal.

Fixes: 9c4fbbe1b8 ('rfkill: query the hardware rfkill reason from udev')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1128
2022-03-02 09:13:57 +01:00
Emmanuel Grumbach
9c4fbbe1b8 rfkill: query the hardware rfkill reason from udev
The kernel may add a reason for hardware rfkill. Make the NetworkManager
able eto fetch it and parse it.
For now, no action will be taken upon the new reasons.

The different reasons that the kernel can expose are either the radio
was switched off by a hardware rfkill switch. This reason is adveritsed
by bit 0 in the bitmap returned by RFKILL_STATE_REASON udev property.
This is the rfkill that existed until now.

The new reason is mapped to bit 1 and teaches the user space that the
wifi device is currently used by the CSME firmware on the platform. In
that case, the NetworkManager can ask CSME (through the iwlmei kernel
module) what BSSID the CSME firmware is associated to. Once the
NetworkManager gets to the conclusion is has the credentials to connect
to that very same AP, it can request the wifi device and the CSME
firmware will allow the host to take the ownership on the device. CSME
will give 3 seconds to the host to get an IP or it'll take the device
back. In order to complete all the process until we get the DHCP ACK
within 3 seconds, the NetworkManager will need to optimize the scan and
limit the scan to that specific BSSID on that specific channel.

All this flow is not implemented yet, but the first step is to identify
that the device is not owned by the host.
2022-02-24 23:04:48 +02:00
Thomas Haller
26e9deb831
core/rfkill: cleanup arguments for "rfkill-changed" signal
The signal parameters are G_TYPE_UINT. We should not assume that our
enums are a compatible integer type.

In practice of course they always were. Let's just be clear about when
we have an integer and when we have an enum.
2022-02-08 18:58:54 +01:00
Thomas Haller
aa15ec6090
core/rfkill: use nm_streq() in "nm-rfkill-manager.c" 2022-02-08 18:58:54 +01:00
Thomas Haller
e3e17f0b4b
core/rfkill: use CList to track Rfkill killswitches
GSList is almost always the wrong choice. We can just embed
the next pointers in the structure using the intrusive CList.
2022-02-08 18:58:53 +01:00
Thomas Haller
bc7a387072
core/rfkill: cleanup initializing Killswitch struct
- use slice allocator
- use designated initializers
- first determine all parameters in killswitch_new() before
  setting ks.
- drop unnecessary memset().
2022-02-08 18:58:53 +01:00
Thomas Haller
96abd25c72
core/rfkill: don't assert for valid string in rfkill_type_to_enum()
"str" comes from udev. This is not a trusted component, and we must not assert
for valid input.
2022-02-08 18:58:53 +01:00
Thomas Haller
a19ca08bcf
core/rfkill: rename rfkill_state_to_desc() to nm_rfkill_state_to_string() 2022-02-08 18:58:53 +01:00
Thomas Haller
6b001b0685
core/rfkill: add nm_rfkill_type_to_string() helper 2022-02-08 18:58:53 +01:00
Thomas Haller
454992ed85
core/rfkill: add "nm" prefix to RfKillState and RfKillType enums
Names in header files should have an "nm" prefix. We do that pretty
consistently. Fix the offenders RfKillState and RfKillType.

Also, rename the RfKillState enums to follow the type name. For example,
NM_RFKILL_STATE_SOFT_BLOCKED instead of RFKILL_SOFT_BLOCKED.

Also, when we camel-case a typedef (NMRfKillState) we would want that
the lower-case names use underscore between the words. So it should be
`nm_rf_kill_state_to_string()`. But that looks awkward. So the right solution
here is to also rename "RfKill" to "Rfkill". That make is consistent
with the spelling of the existing `NMRfkillManager` type and the
`nm-rfkill-manager.h` file.
2022-02-08 18:58:53 +01:00
Thomas Haller
615221a99c format: reformat source tree with clang-format 13.0
We use clang-format for automatic formatting of our source files.
Since clang-format is actively maintained software, the actual
formatting depends on the used version of clang-format. That is
unfortunate and painful, but really unavoidable unless clang-format
would be strictly bug-compatible.

So the version that we must use is from the current Fedora release, which
is also tested by our gitlab-ci. Previously, we were using Fedora 34 with
clang-tools-extra-12.0.1-1.fc34.x86_64.

As Fedora 35 comes along, we need to update our formatting as Fedora 35
comes with version "13.0.0~rc1-1.fc35".
An alternative would be to freeze on version 12, but that has different
problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it
would be cumbersome for our developers which are on Fedora 35 to use a
clang that they cannot easily install).

The (differently painful) solution is to reformat from time to time, as we
switch to a new Fedora (and thus clang) version.
Usually we would expect that such a reformatting brings minor changes.
But this time, the changes are huge. That is mentioned in the release
notes [1] as

  Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353)

[1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
2021-11-29 09:31:09 +00:00
Thomas Haller
4d12a6ac3d
build: move "shared/nm-{base,udev-aux}" to "src/libnm-{base,udev-aux}" 2021-02-24 12:48:19 +01:00
Thomas Haller
dc2afc9b77
all: add "src/core/nm-default-daemon.h" as replacement for "nm-default.h" 2021-02-09 12:38:18 +01:00
Thomas Haller
60800b33b4
all: drop unnecessary cast of g_object_new()
Our cast macros (like NM_AUTH_SUBJECT()) are plain C pointer casts,
unless when building with more asserts enabled.

Still, they are unnecessary and even their ability to check the type
(with more asserts) is not needed, because we must trust glib's
g_object_new() to return reasonable objects. That is a basic
requirement, that we don't need to assert against.

Also, in the majority of cases we don't do this either.
2021-02-08 17:02:09 +01:00
Thomas Haller
ac1a9e03e4
all: move "src/" directory to "src/core/"
Currently "src/" mostly contains the source code of the daemon.
I say mostly, because that is not true, there are also the device,
settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp
helper, and probably more.

Also we have source code under libnm-core/, libnm/, clients/, and
shared/ directories. That is all confusing.

We should have one "src" directory, that contains subdirectories. Those
subdirectories should contain individual parts (libraries or
applications), that possibly have dependencies on other subdirectories.
There should be a flat hierarchy of directories under src/, which
contains individual modules.

As the name "src/" is already taken, that prevents any sensible
restructuring of the code.

As a first step, move "src/" to "src/core/". This gives space to
reorganize the code better by moving individual components into "src/".

For inspiration, look at systemd's "src/" directory.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
2021-02-04 09:45:55 +01:00
Renamed from src/nm-rfkill-manager.c (Browse further)