wayle-network 0.1.2

WiFi and wired network management
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
//! NetworkManager state types.

/// NMState values indicate the current overall networking state.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NMState {
    /// Networking state is unknown. Indicates a daemon error that makes it unable to
    /// reasonably assess the state. In such event the applications are expected to assume
    /// Internet connectivity might be present and not disable controls that require network
    /// access. The graphical shells may hide the network accessibility indicator altogether
    /// since no meaningful status indication can be provided.
    Unknown = 0,
    /// Networking is not enabled, the system is being suspended or resumed from suspend.
    Asleep = 10,
    /// No active network connection. The graphical shell should indicate no
    /// network connectivity and the applications should not attempt to access the network.
    Disconnected = 20,
    /// Network connections are being cleaned up. The applications should tear down their
    /// network sessions.
    Disconnecting = 30,
    /// A network connection is being started The graphical shell should indicate the
    /// network is being connected while the applications should still make no attempts to
    /// connect the network.
    Connecting = 40,
    /// Only local IPv4 and/or IPv6 connectivity, but no default route to access
    /// the Internet. The graphical shell should indicate no network connectivity.
    ConnectedLocal = 50,
    /// Site-wide IPv4 and/or IPv6 connectivity only. Default route
    /// is available, but the Internet connectivity check (see "Connectivity" property) did
    /// not succeed. The graphical shell should indicate limited network connectivity.
    ConnectedSite = 60,
    /// Global IPv4 and/or IPv6 Internet connectivity. Internet
    /// connectivity check succeeded, the graphical shell should indicate full network
    /// connectivity.
    ConnectedGlobal = 70,
}

impl NMState {
    /// Convert from D-Bus u32 representation
    pub fn from_u32(value: u32) -> Self {
        match value {
            0 => Self::Unknown,
            10 => Self::Asleep,
            20 => Self::Disconnected,
            30 => Self::Disconnecting,
            40 => Self::Connecting,
            50 => Self::ConnectedLocal,
            60 => Self::ConnectedSite,
            70 => Self::ConnectedGlobal,
            _ => Self::Unknown,
        }
    }
}

/// Device-specific states.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NMDeviceState {
    /// the device's state is unknown
    Unknown = 0,
    /// the device is recognized, but not managed by NetworkManager
    Unmanaged = 10,
    /// the device is managed by NetworkManager, but is not available for use. Reasons may
    /// include the wireless switched off, missing firmware, no ethernet carrier, missing
    /// supplicant or modem manager, etc.
    Unavailable = 20,
    /// the device can be activated, but is currently idle and not connected to a network.
    Disconnected = 30,
    /// Device is preparing the connection to the network. May include operations
    /// like changing the MAC address, setting physical link properties, and anything else
    /// required to connect to the requested network.
    Prepare = 40,
    /// Device is connecting to the requested network. May include operations like
    /// associating with the Wi-Fi AP, dialing the modem, connecting to the remote
    /// Bluetooth device, etc.
    Config = 50,
    /// Device requires more information to continue connecting to the requested
    /// network. Includes secrets like WiFi passphrases, login passwords, PIN codes,
    /// etc.
    NeedAuth = 60,
    /// the device is requesting IPv4 and/or IPv6 addresses and routing information from
    /// the network.
    IpConfig = 70,
    /// Device is checking whether further action is required for the requested network
    /// connection. May include checking whether only local network access is
    /// available, whether a captive portal is blocking access to the Internet, etc.
    IpCheck = 80,
    /// the device is waiting for a secondary connection (like a VPN) which must activated
    /// before the device can be activated
    Secondaries = 90,
    /// the device has a network connection, either local or global.
    Activated = 100,
    /// a disconnection from the current network connection was requested, and the device
    /// is cleaning up resources used for that connection. The network connection may still
    /// be valid.
    Deactivating = 110,
    /// the device failed to connect to the requested network and is cleaning up the
    /// connection request
    Failed = 120,
}

impl NMDeviceState {
    /// Convert from D-Bus u32 representation
    pub fn from_u32(value: u32) -> Self {
        match value {
            0 => Self::Unknown,
            10 => Self::Unmanaged,
            20 => Self::Unavailable,
            30 => Self::Disconnected,
            40 => Self::Prepare,
            50 => Self::Config,
            60 => Self::NeedAuth,
            70 => Self::IpConfig,
            80 => Self::IpCheck,
            90 => Self::Secondaries,
            100 => Self::Activated,
            110 => Self::Deactivating,
            120 => Self::Failed,
            _ => Self::Unknown,
        }
    }
}

/// NMActiveConnectionState values indicate the state of a connection to a specific
/// network while it is starting, connected, or disconnecting from that network.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NMActiveConnectionState {
    /// the state of the connection is unknown
    Unknown = 0,
    /// a network connection is being prepared
    Activating = 1,
    /// there is a connection to the network
    Activated = 2,
    /// the network connection is being torn down and cleaned up
    Deactivating = 3,
    /// the network connection is disconnected and will be removed
    Deactivated = 4,
}

impl NMActiveConnectionState {
    /// Convert from D-Bus u32 representation
    pub fn from_u32(value: u32) -> Self {
        match value {
            0 => Self::Unknown,
            1 => Self::Activating,
            2 => Self::Activated,
            3 => Self::Deactivating,
            4 => Self::Deactivated,
            _ => Self::Unknown,
        }
    }
}

/// VPN connection states.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NMVpnConnectionState {
    /// The state of the VPN connection is unknown.
    Unknown = 0,
    /// The VPN connection is preparing to connect.
    Prepare = 1,
    /// The VPN connection needs authorization credentials.
    NeedAuth = 2,
    /// The VPN connection is being established.
    Connect = 3,
    /// The VPN connection is getting an IP address.
    IpConfigGet = 4,
    /// The VPN connection is active.
    Activated = 5,
    /// The VPN connection failed.
    Failed = 6,
    /// The VPN connection is disconnected.
    Disconnected = 7,
}

impl NMVpnConnectionState {
    /// Convert from D-Bus u32 representation
    pub fn from_u32(value: u32) -> Self {
        match value {
            0 => Self::Unknown,
            1 => Self::Prepare,
            2 => Self::NeedAuth,
            3 => Self::Connect,
            4 => Self::IpConfigGet,
            5 => Self::Activated,
            6 => Self::Failed,
            7 => Self::Disconnected,
            _ => Self::Unknown,
        }
    }
}

/// Device state change reason codes
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NMDeviceStateReason {
    /// No reason given
    None = 0,
    /// Unknown error
    Unknown = 1,
    /// Device is now managed
    NowManaged = 2,
    /// Device is now unmanaged
    NowUnmanaged = 3,
    /// The device could not be readied for configuration
    ConfigFailed = 4,
    /// IP configuration could not be reserved (no available address, timeout, etc)
    IpConfigUnavailable = 5,
    /// The IP config is no longer valid
    IpConfigExpired = 6,
    /// Secrets were required, but not provided
    NoSecrets = 7,
    /// 802.1x supplicant disconnected
    SupplicantDisconnect = 8,
    /// 802.1x supplicant configuration failed
    SupplicantConfigFailed = 9,
    /// 802.1x supplicant failed
    SupplicantFailed = 10,
    /// 802.1x supplicant took too long to authenticate
    SupplicantTimeout = 11,
    /// PPP service failed to start
    PppStartFailed = 12,
    /// PPP service disconnected
    PppDisconnect = 13,
    /// PPP failed
    PppFailed = 14,
    /// DHCP client failed to start
    DhcpStartFailed = 15,
    /// DHCP client error
    DhcpError = 16,
    /// DHCP client failed
    DhcpFailed = 17,
    /// Shared connection service failed to start
    SharedStartFailed = 18,
    /// Shared connection service failed
    SharedFailed = 19,
    /// AutoIP service failed to start
    AutoIpStartFailed = 20,
    /// AutoIP service error
    AutoIpError = 21,
    /// AutoIP service failed
    AutoIpFailed = 22,
    /// The line is busy
    ModemBusy = 23,
    /// No dial tone
    ModemNoDialTone = 24,
    /// No carrier could be established
    ModemNoCarrier = 25,
    /// The dialing request timed out
    ModemDialTimeout = 26,
    /// The dialing attempt failed
    ModemDialFailed = 27,
    /// Modem initialization failed
    ModemInitFailed = 28,
    /// Failed to select the specified APN
    GsmApnFailed = 29,
    /// Not searching for networks
    GsmRegistrationNotSearching = 30,
    /// Network registration denied
    GsmRegistrationDenied = 31,
    /// Network registration timed out
    GsmRegistrationTimeout = 32,
    /// Failed to register with the requested network
    GsmRegistrationFailed = 33,
    /// PIN check failed
    GsmPinCheckFailed = 34,
    /// Necessary firmware for the device may be missing
    FirmwareMissing = 35,
    /// The device was removed
    Removed = 36,
    /// NetworkManager went to sleep
    Sleeping = 37,
    /// The device's active connection disappeared
    ConnectionRemoved = 38,
    /// Device disconnected by user or client
    UserRequested = 39,
    /// Carrier/link changed
    Carrier = 40,
    /// The device's existing connection was assumed
    ConnectionAssumed = 41,
    /// The supplicant is now available
    SupplicantAvailable = 42,
    /// The modem could not be found
    ModemNotFound = 43,
    /// The Bluetooth connection failed or timed out
    BtFailed = 44,
    /// GSM Modem's SIM Card not inserted
    GsmSimNotInserted = 45,
    /// GSM Modem's SIM Pin required
    GsmSimPinRequired = 46,
    /// GSM Modem's SIM Puk required
    GsmSimPukRequired = 47,
    /// GSM Modem's SIM wrong
    GsmSimWrong = 48,
    /// InfiniBand device does not support connected mode
    InfinibandMode = 49,
    /// A dependency of the connection failed
    DependencyFailed = 50,
    /// Problem with the RFC 2684 Ethernet over ADSL bridge
    Br2684Failed = 51,
    /// ModemManager not running
    ModemManagerUnavailable = 52,
    /// The Wi-Fi network could not be found
    SsidNotFound = 53,
    /// A secondary connection of the base connection failed
    SecondaryConnectionFailed = 54,
    /// DCB or FCoE setup failed
    DcbFcoeFailed = 55,
    /// teamd control failed
    TeamdControlFailed = 56,
    /// Modem failed or no longer available
    ModemFailed = 57,
    /// Modem now ready and available
    ModemAvailable = 58,
    /// SIM PIN was incorrect
    SimPinIncorrect = 59,
    /// New connection activation was enqueued
    NewActivation = 60,
    /// the device's parent changed
    ParentChanged = 61,
    /// the device parent's management changed
    ParentManagedChanged = 62,
    /// problem communicating with Open vSwitch database
    OvsdbFailed = 63,
    /// a duplicate IP address was detected
    IpAddressDuplicate = 64,
    /// The selected IP method is not supported
    IpMethodUnsupported = 65,
    /// configuration of SR-IOV parameters failed
    SriovConfigurationFailed = 66,
    /// The Wi-Fi P2P peer could not be found
    PeerNotFound = 67,
    /// The device handler dispatcher returned an error. Since: 1.46
    DeviceHandlerFailed = 68,
    /// The device type is unmanaged by default. Since: 1.48
    UnmanagedByDefault = 69,
    /// The device is an external device and is unconfigured (down or without addresses). Since: 1.48
    UnmanagedExternalDown = 70,
    /// The link is not initialized by udev. Since: 1.48
    UnmanagedLinkNotInit = 71,
    /// NetworkManager is quitting. Since: 1.48
    UnmanagedQuitting = 72,
    /// Networking is disabled or the system is suspended. Since: 1.56
    UnmanagedManagerDisabled = 73,
    /// Unmanaged by user decision in NetworkManager.conf. Since: 1.48
    UnmanagedUserConf = 74,
    /// Unmanaged by explicit user decision (e.g. `nmcli device set $DEV managed no`). Since: 1.48
    UnmanagedUserExplicit = 75,
    /// Unmanaged via settings plugin (keyfile `unmanaged-devices` or ifcfg-rh `NM_CONTROLLED=no`). Since: 1.48
    UnmanagedUserSettings = 76,
    /// Unmanaged via udev rule. Since: 1.48
    UnmanagedUserUdev = 77,
    /// NetworkManager was disabled (networking off). Since: 1.56
    NetworkingOff = 78,
    /// The modem's operator code wasn't available, and auto-configuration was requested. Since: 1.56
    ModemNoOperatorCode = 79,
}

impl NMDeviceStateReason {
    /// Converts from the D-Bus u32 representation.
    pub fn from_u32(value: u32) -> Self {
        match value {
            0 => Self::None,
            1 => Self::Unknown,
            2 => Self::NowManaged,
            3 => Self::NowUnmanaged,
            4 => Self::ConfigFailed,
            5 => Self::IpConfigUnavailable,
            6 => Self::IpConfigExpired,
            7 => Self::NoSecrets,
            8 => Self::SupplicantDisconnect,
            9 => Self::SupplicantConfigFailed,
            10 => Self::SupplicantFailed,
            11 => Self::SupplicantTimeout,
            12 => Self::PppStartFailed,
            13 => Self::PppDisconnect,
            14 => Self::PppFailed,
            15 => Self::DhcpStartFailed,
            16 => Self::DhcpError,
            17 => Self::DhcpFailed,
            18 => Self::SharedStartFailed,
            19 => Self::SharedFailed,
            20 => Self::AutoIpStartFailed,
            21 => Self::AutoIpError,
            22 => Self::AutoIpFailed,
            23 => Self::ModemBusy,
            24 => Self::ModemNoDialTone,
            25 => Self::ModemNoCarrier,
            26 => Self::ModemDialTimeout,
            27 => Self::ModemDialFailed,
            28 => Self::ModemInitFailed,
            29 => Self::GsmApnFailed,
            30 => Self::GsmRegistrationNotSearching,
            31 => Self::GsmRegistrationDenied,
            32 => Self::GsmRegistrationTimeout,
            33 => Self::GsmRegistrationFailed,
            34 => Self::GsmPinCheckFailed,
            35 => Self::FirmwareMissing,
            36 => Self::Removed,
            37 => Self::Sleeping,
            38 => Self::ConnectionRemoved,
            39 => Self::UserRequested,
            40 => Self::Carrier,
            41 => Self::ConnectionAssumed,
            42 => Self::SupplicantAvailable,
            43 => Self::ModemNotFound,
            44 => Self::BtFailed,
            45 => Self::GsmSimNotInserted,
            46 => Self::GsmSimPinRequired,
            47 => Self::GsmSimPukRequired,
            48 => Self::GsmSimWrong,
            49 => Self::InfinibandMode,
            50 => Self::DependencyFailed,
            51 => Self::Br2684Failed,
            52 => Self::ModemManagerUnavailable,
            53 => Self::SsidNotFound,
            54 => Self::SecondaryConnectionFailed,
            55 => Self::DcbFcoeFailed,
            56 => Self::TeamdControlFailed,
            57 => Self::ModemFailed,
            58 => Self::ModemAvailable,
            59 => Self::SimPinIncorrect,
            60 => Self::NewActivation,
            61 => Self::ParentChanged,
            62 => Self::ParentManagedChanged,
            63 => Self::OvsdbFailed,
            64 => Self::IpAddressDuplicate,
            65 => Self::IpMethodUnsupported,
            66 => Self::SriovConfigurationFailed,
            67 => Self::PeerNotFound,
            68 => Self::DeviceHandlerFailed,
            69 => Self::UnmanagedByDefault,
            70 => Self::UnmanagedExternalDown,
            71 => Self::UnmanagedLinkNotInit,
            72 => Self::UnmanagedQuitting,
            73 => Self::UnmanagedManagerDisabled,
            74 => Self::UnmanagedUserConf,
            75 => Self::UnmanagedUserExplicit,
            76 => Self::UnmanagedUserSettings,
            77 => Self::UnmanagedUserUdev,
            78 => Self::NetworkingOff,
            79 => Self::ModemNoOperatorCode,
            _ => Self::Unknown,
        }
    }
}

/// Active connection state reasons.
///
/// Since: 1.8
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NMActiveConnectionStateReason {
    /// The reason for the active connection state change is unknown.
    Unknown = 0,
    /// No reason was given for the active connection state change.
    None = 1,
    /// The active connection changed state because the user disconnected it.
    UserDisconnected = 2,
    /// The active connection changed state because the device it was using was
    /// disconnected.
    DeviceDisconnected = 3,
    /// The service providing the VPN connection was stopped.
    ServiceStopped = 4,
    /// The IP config of the active connection was invalid.
    IpConfigInvalid = 5,
    /// The connection attempt to the VPN service timed out.
    ConnectTimeout = 6,
    /// A timeout occurred while starting the service providing the VPN connection.
    ServiceStartTimeout = 7,
    /// Starting the service providing the VPN connection failed.
    ServiceStartFailed = 8,
    /// Necessary secrets for the connection were not provided.
    NoSecrets = 9,
    /// Authentication to the server failed.
    LoginFailed = 10,
    /// The connection was deleted from settings.
    ConnectionRemoved = 11,
    /// Master connection of this connection failed to activate.
    DependencyFailed = 12,
    /// Could not create the software device link.
    DeviceRealizeFailed = 13,
    /// The device this connection depended on disappeared.
    DeviceRemoved = 14,
}

impl NMActiveConnectionStateReason {
    /// Convert from D-Bus u32 representation
    pub fn from_u32(value: u32) -> Self {
        match value {
            0 => Self::Unknown,
            1 => Self::None,
            2 => Self::UserDisconnected,
            3 => Self::DeviceDisconnected,
            4 => Self::ServiceStopped,
            5 => Self::IpConfigInvalid,
            6 => Self::ConnectTimeout,
            7 => Self::ServiceStartTimeout,
            8 => Self::ServiceStartFailed,
            9 => Self::NoSecrets,
            10 => Self::LoginFailed,
            11 => Self::ConnectionRemoved,
            12 => Self::DependencyFailed,
            13 => Self::DeviceRealizeFailed,
            14 => Self::DeviceRemoved,
            _ => Self::Unknown,
        }
    }
}

/// VPN state change reasons.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NMVpnConnectionStateReason {
    /// The reason for the VPN connection state change is unknown.
    Unknown = 0,
    /// No reason was given for the VPN connection state change.
    None = 1,
    /// The VPN connection changed state because the user disconnected it.
    UserDisconnected = 2,
    /// The VPN connection changed state because the device it was using was disconnected.
    DeviceDisconnected = 3,
    /// The service providing the VPN connection was stopped.
    ServiceStopped = 4,
    /// The IP config of the VPN connection was invalid.
    IpConfigInvalid = 5,
    /// The connection attempt to the VPN service timed out.
    ConnectTimeout = 6,
    /// A timeout occurred while starting the service providing the VPN connection.
    ServiceStartTimeout = 7,
    /// Starting the service providing the VPN connection failed.
    ServiceStartFailed = 8,
    /// Necessary secrets for the VPN connection were not provided.
    NoSecrets = 9,
    /// Authentication to the VPN server failed.
    LoginFailed = 10,
    /// The VPN connection was deleted from settings.
    ConnectionRemoved = 11,
}

impl NMVpnConnectionStateReason {
    /// Convert from D-Bus u32 representation
    pub fn from_u32(value: u32) -> Self {
        match value {
            0 => Self::Unknown,
            1 => Self::None,
            2 => Self::UserDisconnected,
            3 => Self::DeviceDisconnected,
            4 => Self::ServiceStopped,
            5 => Self::IpConfigInvalid,
            6 => Self::ConnectTimeout,
            7 => Self::ServiceStartTimeout,
            8 => Self::ServiceStartFailed,
            9 => Self::NoSecrets,
            10 => Self::LoginFailed,
            11 => Self::ConnectionRemoved,
            _ => Self::Unknown,
        }
    }
}

/// The result of a checkpoint Rollback() operation for a specific device.
///
/// Since: 1.4
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NMRollbackResult {
    /// the rollback succeeded.
    Ok = 0,
    /// the device no longer exists.
    ErrNoDevice = 1,
    /// the device is now unmanaged.
    ErrDeviceUnmanaged = 2,
    /// other errors during rollback.
    ErrFailed = 3,
}

impl NMRollbackResult {
    /// Convert from D-Bus u32 representation
    pub fn from_u32(value: u32) -> Self {
        match value {
            0 => Self::Ok,
            1 => Self::ErrNoDevice,
            2 => Self::ErrDeviceUnmanaged,
            3 => Self::ErrFailed,
            _ => Self::ErrFailed,
        }
    }
}

/// Current network connectivity status.
///
/// Simplified view of network state that combines multiple NetworkManager
/// states into broader categories.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum NetworkStatus {
    /// Full network connectivity with internet access
    Connected,

    /// Establishing network connection
    /// (obtaining IP, authenticating, etc.)
    Connecting,

    /// No network connection
    Disconnected,
}

impl NetworkStatus {
    /// Derive network status from device state.
    ///
    /// Maps the detailed NetworkManager device states to simplified
    /// connectivity status for UI display.
    pub fn from_device_state(state: NMDeviceState) -> Self {
        match state {
            NMDeviceState::Activated => Self::Connected,
            NMDeviceState::Prepare
            | NMDeviceState::Config
            | NMDeviceState::NeedAuth
            | NMDeviceState::IpConfig
            | NMDeviceState::IpCheck
            | NMDeviceState::Secondaries => Self::Connecting,
            _ => Self::Disconnected,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn from_device_state_returns_connected_when_activated() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Activated),
            NetworkStatus::Connected
        );
    }

    #[test]
    fn from_device_state_returns_connecting_for_prepare() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Prepare),
            NetworkStatus::Connecting
        );
    }

    #[test]
    fn from_device_state_returns_connecting_for_config() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Config),
            NetworkStatus::Connecting
        );
    }

    #[test]
    fn from_device_state_returns_connecting_for_need_auth() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::NeedAuth),
            NetworkStatus::Connecting
        );
    }

    #[test]
    fn from_device_state_returns_connecting_for_ip_config() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::IpConfig),
            NetworkStatus::Connecting
        );
    }

    #[test]
    fn from_device_state_returns_connecting_for_ip_check() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::IpCheck),
            NetworkStatus::Connecting
        );
    }

    #[test]
    fn from_device_state_returns_connecting_for_secondaries() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Secondaries),
            NetworkStatus::Connecting
        );
    }

    #[test]
    fn from_device_state_returns_disconnected_for_unknown() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Unknown),
            NetworkStatus::Disconnected
        );
    }

    #[test]
    fn from_device_state_returns_disconnected_for_unmanaged() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Unmanaged),
            NetworkStatus::Disconnected
        );
    }

    #[test]
    fn from_device_state_returns_disconnected_for_unavailable() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Unavailable),
            NetworkStatus::Disconnected
        );
    }

    #[test]
    fn from_device_state_returns_disconnected_for_disconnected() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Disconnected),
            NetworkStatus::Disconnected
        );
    }

    #[test]
    fn from_device_state_returns_disconnected_for_deactivating() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Deactivating),
            NetworkStatus::Disconnected
        );
    }

    #[test]
    fn from_device_state_returns_disconnected_for_failed() {
        assert_eq!(
            NetworkStatus::from_device_state(NMDeviceState::Failed),
            NetworkStatus::Disconnected
        );
    }
}