File indexing completed on 2024-04-21 15:06:32

0001 /*
0002     SPDX-FileCopyrightText: 2008, 2011 Will Stephenson <wstephenson@kde.org>
0003     SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza <lamarque@kde.org>
0004     SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com>
0005     SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
0006 
0007     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0008 */
0009 
0010 #ifndef NETWORKMANAGERQT_WIRELESSDEVICE_H
0011 #define NETWORKMANAGERQT_WIRELESSDEVICE_H
0012 
0013 #include "accesspoint.h"
0014 #include "device.h"
0015 #include "wirelessnetwork.h"
0016 #include <networkmanagerqt/networkmanagerqt_export.h>
0017 
0018 #include <QDBusObjectPath>
0019 #include <QDBusPendingReply>
0020 
0021 namespace NetworkManager
0022 {
0023 class WirelessDevicePrivate;
0024 
0025 /**
0026  * A wireless network interface
0027  */
0028 class NETWORKMANAGERQT_EXPORT WirelessDevice : public Device
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     typedef QSharedPointer<WirelessDevice> Ptr;
0034     typedef QList<Ptr> List;
0035 
0036     /**
0037      * The device's current operating mode
0038      */
0039     enum OperationMode {
0040         Unknown = 0, /**< not associated with a network */
0041         Adhoc, /**< part of an adhoc network */
0042         Infra, /**< a station in an infrastructure wireless network */
0043         ApMode, /**< access point in an infrastructure network */
0044     };
0045     Q_ENUM(OperationMode)
0046     /**
0047      * Capabilities (currently all encryption/authentication related) of the device
0048      * @note FreqValid, Freq2Ghz, Freq5Ghz are available in runtime NM >= 1.0.2
0049      */
0050     enum Capability {
0051         NoCapability = 0x0, /**< Null capability */
0052         Wep40 = 0x1, /**< 40 bit WEP cipher */
0053         Wep104 = 0x2, /**< 104 bit WEP cipher */
0054         Tkip = 0x4, /**< TKIP encryption cipher */
0055         Ccmp = 0x8, /**< CCMP encryption cipher */
0056         Wpa = 0x10, /**< WPA authentication protocol */
0057         Rsn = 0x20, /**< RSN authethication protocol */
0058         ApCap = 0x40, /**< The device supports Access Point mode. */
0059         AdhocCap = 0x80, /**< The device supports Ad-Hoc mode. */
0060         FreqValid = 0x100, /**< The device properly reports information about supported frequencies */
0061         Freq2Ghz = 0x200, /**< The device supports 2.4Ghz frequencies */
0062         Freq5Ghz = 0x400, /**< The device supports 5Ghz frequencies */
0063         Mesh = 0x1000, /**< The device supports acting as a mesh point */
0064         IBSSRsn = 0x2000, /**< device supports WPA2/RSN in an IBSS network */
0065     };
0066     Q_DECLARE_FLAGS(Capabilities, Capability)
0067     /**
0068      * Creates a new WirelessDevice object.
0069      *
0070      * @param path the DBus path of the devise
0071      */
0072     explicit WirelessDevice(const QString &path, QObject *parent = nullptr);
0073     /**
0074      * Destroys a WirelessDevice object.
0075      */
0076     ~WirelessDevice() override;
0077     /**
0078      * Return the type
0079      */
0080     Type type() const override;
0081     /**
0082      * List of wireless networks currently visible to the hardware
0083      */
0084     QStringList accessPoints() const;
0085     /**
0086      * Asks the device for a new scan of available wireless networks
0087      * @param options Options of scan
0088      * No documentation for options yet, see
0089      * https://projects.gnome.org/NetworkManager/developers/api/09/spec.html#org.freedesktop.NetworkManager.Device.Wireless
0090      */
0091     QDBusPendingReply<> requestScan(const QVariantMap &options = QVariantMap());
0092     /**
0093      * AccessPoint pointer this interface is currently associated with
0094      */
0095     AccessPoint::Ptr activeAccessPoint() const;
0096     /**
0097      * The permanent hardware address of the network interface
0098      */
0099     QString permanentHardwareAddress() const;
0100     /**
0101      * The hardware address currently used by the network interface
0102      */
0103     QString hardwareAddress() const;
0104 
0105     /**
0106      * Retrieves the operation mode of this network.
0107      *
0108      * @return the current mode
0109      * @see OperationMode
0110      */
0111     WirelessDevice::OperationMode mode() const;
0112     /**
0113      * Retrieves the effective bit rate currently attainable by this device.
0114      *
0115      * @return the bitrate in Kbit/s
0116      */
0117     int bitRate() const;
0118     /**
0119      * The LastScan property value, converted to QDateTime
0120      * @since 5.62.0
0121      * @note will always return invalid QDateTime when runtime NM < 1.12
0122      * @return
0123      */
0124     QDateTime lastScan() const;
0125     /**
0126      * The time the last RequestScan function was called
0127      * @since 5.62.0
0128      * @return
0129      */
0130     QDateTime lastRequestScan() const;
0131     /**
0132      * Retrieves the capabilities of this wifi network.
0133      *
0134      * @return the flag set describing the capabilities
0135      * @see Capabilities
0136      */
0137     WirelessDevice::Capabilities wirelessCapabilities() const;
0138 
0139     /**
0140      * Helper method to convert wire representation of operation mode to enum
0141      */
0142     static WirelessDevice::OperationMode convertOperationMode(uint);
0143     /**
0144      * Helper method to convert wire representation of capabilities to enum
0145      */
0146     static WirelessDevice::Capabilities convertCapabilities(uint);
0147     /**
0148      * Finds access point object given its Unique Network Identifier.
0149      *
0150      * @param uni the identifier of the AP to find from this network interface
0151      * @returns a valid AccessPoint object if a network having the given UNI for this device is known to the system, 0 otherwise
0152      */
0153     AccessPoint::Ptr findAccessPoint(const QString &uni);
0154 
0155     /**
0156      * Return the current list of networks
0157      */
0158     WirelessNetwork::List networks() const;
0159 
0160     /**
0161      * Find a network with the given @p ssid, a Null object is
0162      * returned if it can not be found
0163      */
0164     WirelessNetwork::Ptr findNetwork(const QString &ssid) const;
0165 
0166 Q_SIGNALS:
0167     /**
0168      * This signal is emitted when the bitrate of this network has changed.
0169      *
0170      * @param bitrate the new bitrate value for this network
0171      */
0172     void bitRateChanged(int bitrate);
0173     /**
0174      * The active network changed.
0175      */
0176     void activeAccessPointChanged(const QString &);
0177     /**
0178      * The device switched operating mode.
0179      */
0180     void modeChanged(WirelessDevice::OperationMode);
0181     /**
0182      * The device changed its capabilities
0183      */
0184     void wirelessCapabilitiesChanged(Capabilities);
0185     /**
0186      * The device changed its hardware address
0187      */
0188     void hardwareAddressChanged(const QString &);
0189     /**
0190      * The device changed its permanent hardware address
0191      */
0192     void permanentHardwareAddressChanged(const QString &);
0193     /**
0194      * The device changed its properties
0195      */
0196     void wirelessPropertiesChanged(uint); // TODO this is bogus, remove
0197     /**
0198      * A new wireless access point appeared
0199      */
0200     void accessPointAppeared(const QString &uni);
0201     /**
0202      * A wireless access point disappeared
0203      */
0204     void accessPointDisappeared(const QString &uni);
0205     /**
0206      * A wireless network appeared
0207      */
0208     void networkAppeared(const QString &ssid);
0209     /**
0210      * A wireless network disappeared
0211      */
0212     void networkDisappeared(const QString &ssid);
0213     /**
0214      * The LastScan property has changed, meaning a scan has just finished
0215      * @since 5.62.0
0216      * @note will never be emitted when runtime NM < 1.12
0217      * @see lastScanTime
0218      */
0219     void lastScanChanged(const QDateTime &dateTime);
0220 
0221 private:
0222     Q_DECLARE_PRIVATE(WirelessDevice)
0223 };
0224 
0225 } // namespace NetworkManager
0226 #endif // NETWORKMANAGERQT_WIRELESSDEVICE_H