azalea_shell/service/dbus/network_manager/
proxy.rs

1use std::collections::HashMap;
2
3use zbus::proxy;
4use zbus::zvariant::{OwnedObjectPath, OwnedValue};
5
6/// NetworkManager root interface
7///
8/// See:
9/// - <https://networkmanager.dev/docs/api/latest/gdbus-org.freedesktop.NetworkManager.html>
10/// - <https://people.freedesktop.org/~lkundrak/nm-docs/gdbus-org.freedesktop.NetworkManager.html>
11#[proxy(
12    default_service = "org.freedesktop.NetworkManager",
13    default_path = "/org/freedesktop/NetworkManager",
14    interface = "org.freedesktop.NetworkManager"
15)]
16pub trait NetworkManager {
17    async fn get_devices(&self) -> zbus::Result<Vec<OwnedObjectPath>>;
18    async fn get_all_devices(&self) -> zbus::Result<Vec<OwnedObjectPath>>;
19    fn sleep(&self, sleep: bool) -> zbus::Result<()>;
20    fn enable(&self, enable: bool) -> zbus::Result<()>;
21    fn deactivate_connection(
22        &self,
23        active_connection: OwnedObjectPath,
24    ) -> zbus::Result<Vec<OwnedObjectPath>>;
25    fn activate_connection(
26        &self,
27        connection: OwnedObjectPath,
28        device: OwnedObjectPath,
29        specific_object: OwnedObjectPath,
30    ) -> zbus::Result<OwnedObjectPath>;
31
32    #[zbus(property)]
33    fn active_connections(&self) -> zbus::Result<Vec<OwnedObjectPath>>;
34
35    #[zbus(property)]
36    fn networking_enabled(&self) -> zbus::Result<bool>;
37
38    #[zbus(property)]
39    fn wireless_enabled(&self) -> zbus::Result<bool>;
40
41    #[zbus(property)]
42    fn wwan_enabled(&self) -> zbus::Result<bool>;
43
44    #[zbus(property)]
45    fn version(&self) -> zbus::Result<String>;
46
47    #[zbus(property)]
48    fn state(&self) -> zbus::Result<NMState>;
49
50    #[zbus(property)]
51    fn connectivity(&self) -> zbus::Result<NMConnectivityState>;
52
53    #[zbus(signal)]
54    fn properties_changed(&self, properties: HashMap<String, OwnedValue>) -> zbus::Result<()>;
55}
56
57/// NMState values indicate the current overall networking state.
58///
59/// See: <https://people.freedesktop.org/~lkundrak/nm-docs/nm-dbus-types.html#NMState>
60#[derive(
61    Default,
62    Clone,
63    Debug,
64    serde_repr::Serialize_repr,
65    serde_repr::Deserialize_repr,
66    OwnedValue,
67    zbus::zvariant::Type,
68)]
69#[repr(u32)]
70#[zvariant(signature = "u")]
71pub enum NMState {
72    #[default]
73    /// Networking state is unknown
74    NMStateUnknown = 0,
75
76    /// Networking is not enabled
77    NMStateAsleep = 10,
78
79    /// There is no active network connection
80    NMStateDisconnected = 20,
81
82    /// Network connections are being cleaned up
83    NMStateDisconnecting = 30,
84
85    /// A network connection is being started
86    NMStateConnecting = 40,
87
88    /// There is only local IPv4 and/or IPv6 connectivity
89    NMStateConnectedLocal = 50,
90
91    /// There is only site-wide IPv4 and/or IPv6 connectivity
92    NMStateConnectedSite = 60,
93
94    /// There is global IPv4 and/or IPv6 Internet connectivity
95    NMStateConnectedGlobal = 70,
96}
97
98/// NMState values indicate the current overall networking state.
99///
100/// See: <https://people.freedesktop.org/~lkundrak/nm-docs/nm-dbus-types.html#NMConnectivityState>
101#[derive(
102    Default, Clone, Debug, serde_repr::Serialize_repr, serde_repr::Deserialize_repr, OwnedValue,
103)]
104#[repr(u32)]
105#[zvariant(signature = "u")]
106pub enum NMConnectivityState {
107    #[default]
108    /// Network connectivity is unknown.
109    NMConnectivityUnknown = 1,
110
111    /// The host is not connected to any network.
112    NMConnectivityNone = 2,
113
114    /// The host is behind a captive portal and cannot reach the full Internet.
115    NMConnectivityPortal = 3,
116
117    /// The host is connected to a network, but does not appear to be able to reach the full Internet.
118    NMConnectivityLimited = 4,
119
120    /// The host is connected to a network, and appears to be able to reach the full Internet.
121    NMConnectivityFull = 5,
122}
123
124/// NMDeviceState values indicate the device state.
125///
126/// See: <https://people.freedesktop.org/~lkundrak/nm-docs/nm-dbus-types.html#NMDeviceState>
127#[derive(
128    PartialEq,
129    Default,
130    Clone,
131    Debug,
132    serde_repr::Serialize_repr,
133    serde_repr::Deserialize_repr,
134    OwnedValue,
135)]
136#[repr(u32)]
137#[zvariant(signature = "u")]
138pub enum NMDeviceState {
139    #[default]
140    /// The device's state is unknown
141    NMDeviceStateUnknown = 0,
142
143    /// The device is recognized, but not managed by networkmanager
144    NMDeviceStateUnmanaged = 10,
145
146    /// The device is managed by networkmanager, but is not available for use. reasons may include
147    /// the wireless switched off, missing firmware, no ethernet carrier, missing supplicant or
148    /// modem manager, etc.
149    NMDeviceStateUnavailable = 20,
150
151    /// The device can be activated, but is currently idle and not connected to a network.
152    NMDeviceStateDisconnected = 30,
153
154    /// The device is preparing the connection to the network. this may include operations like
155    /// changing the mac address, setting physical link properties, and anything else required to
156    /// connect to the requested network.
157    NMDeviceStatePrepare = 40,
158
159    /// The device is connecting to the requested network. this may include operations like
160    /// associating with the wifi ap, dialing the modem, connecting to the remote bluetooth device,
161    /// etc.
162    NMDeviceStateConfig = 50,
163
164    /// The device requires more information to continue connecting to the requested network. this
165    /// includes secrets like wifi passphrases, login passwords, pin codes, etc.
166    NMDeviceStateNeedAuth = 60,
167
168    /// The device is requesting ipv4 and/or ipv6 addresses and routing information from the
169    /// network.
170    NMDeviceStateIpConfig = 70,
171
172    /// The device is checking whether further action is required for the requested network
173    /// connection. this may include checking whether only local network access is available,
174    /// whether a captive portal is blocking access to the internet, etc.
175    NMDeviceStateIpCheck = 80,
176
177    /// The device is waiting for a secondary connection (like a vpn) which must activated before
178    /// the device can be activated
179    NMDeviceStateSecondaries = 90,
180
181    /// The device has a network connection, either local or global.
182    NMDeviceStateActivated = 100,
183
184    /// A disconnection from the current network connection was requested, and The device is
185    /// cleaning up resources used for that connection. the network connection may still be valid.
186    NMDeviceStateDeactivating = 110,
187
188    /// The device failed to connect to the requested network and is cleaning up the connection
189    /// request
190    NMDeviceStateFailed = 120,
191}
192
193/// NMDeviceType indicates the type of device, e.g.: wifi, ethernet, bluetooth, etc
194///
195/// See: <https://people.freedesktop.org/~lkundrak/nm-docs/nm-dbus-types.html#NMDeviceType>
196#[derive(
197    Default, Clone, Debug, serde_repr::Serialize_repr, serde_repr::Deserialize_repr, OwnedValue,
198)]
199#[repr(u32)]
200#[zvariant(signature = "u")]
201pub enum NMDeviceType {
202    #[default]
203    NMDeviceTypeUnknown = 0,
204
205    NMDeviceTypeGeneric = 14,
206
207    NMDeviceTypeEthernet = 1,
208
209    NMDeviceTypeWifi = 2,
210
211    NMDeviceTypeUnused1 = 3,
212
213    NMDeviceTypeUnused2 = 4,
214
215    NMDeviceTypeBt = 5,
216
217    NMDeviceTypeOlpcMesh = 6,
218
219    NMDeviceTypeWimax = 7,
220
221    NMDeviceTypeModem = 8,
222
223    NMDeviceTypeInfiniband = 9,
224
225    NMDeviceTypeBond = 10,
226
227    NMDeviceTypeVlan = 11,
228
229    NMDeviceTypeAdsl = 12,
230
231    NMDeviceTypeBridge = 13,
232
233    NMDeviceTypeTeam = 15,
234
235    NMDeviceTypeTun = 16,
236
237    NMDeviceTypeIpTunnel = 17,
238
239    NMDeviceTypeMacvlan = 18,
240
241    NMDeviceTypeVxlan = 19,
242
243    NMDeviceTypeVeth = 20,
244}
245
246/// Netowkr Manager Device DBus interface
247///
248/// See: <https://people.freedesktop.org/~lkundrak/nm-docs/gdbus-org.freedesktop.NetworkManager.Device.html>
249#[proxy(
250    default_service = "org.freedesktop.NetworkManager",
251    interface = "org.freedesktop.NetworkManager.Device"
252)]
253pub trait NetworkManagerDevice {
254    fn disconnect(&self) -> zbus::Result<()>;
255
256    #[zbus(property)]
257    fn state(&self) -> zbus::Result<NMDeviceState>;
258
259    #[zbus(property)]
260    fn device_type(&self) -> zbus::Result<NMDeviceType>;
261
262    #[zbus(property)]
263    fn interface(&self) -> zbus::Result<String>;
264
265    #[zbus(property)]
266    fn active_connection(&self) -> zbus::Result<OwnedObjectPath>;
267}
268
269/// Network Manager Settings DBus interface
270///
271/// See: <https://people.freedesktop.org/~lkundrak/nm-docs/gdbus-org.freedesktop.NetworkManager.Settings>
272#[proxy(
273    default_service = "org.freedesktop.NetworkManager",
274    default_path = "/org/freedesktop/NetworkManager/Settings",
275    interface = "org.freedesktop.NetworkManager.Settings"
276)]
277pub trait NetworkManagerSettings {
278    fn list_connections(&self) -> zbus::Result<Vec<OwnedObjectPath>>;
279
280    #[zbus(property)]
281    fn connections(&self) -> zbus::Result<Vec<OwnedObjectPath>>;
282}
283
284/// Network Manager Settings Connection DBus interface
285///
286/// See: <https://people.freedesktop.org/~lkundrak/nm-docs/gdbus-org.freedesktop.NetworkManager.Settings.Connection.html>
287#[proxy(
288    default_service = "org.freedesktop.NetworkManager",
289    interface = "org.freedesktop.NetworkManager.Settings.Connection"
290)]
291pub trait NetworkManagerSettingsConnection {
292    /// This is a nested dictionary...
293    ///
294    /// It would be nice to have nested dictionaries, but it's not supported, see <https://github.com/z-galaxy/zbus/issues/312>
295    fn get_settings(
296        &self,
297    ) -> zbus::Result<HashMap<String, HashMap<String, zbus::zvariant::OwnedValue>>>;
298}
299
300/// Network Manager Connection Active DBus interface
301///
302/// See: <https://people.freedesktop.org/~lkundrak/nm-docs/gdbus-org.freedesktop.NetworkManager.Connection.Active.html>
303#[proxy(
304    default_service = "org.freedesktop.NetworkManager",
305    interface = "org.freedesktop.NetworkManager.Connection.Active"
306)]
307pub trait NetworkManagerConnectionActive {
308    /// This refers to the connection settings...
309    #[zbus(property)]
310    fn connection(&self) -> zbus::Result<OwnedObjectPath>;
311}