File indexing completed on 2024-04-14 03:57:46

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