File indexing completed on 2024-04-21 03:59:48

0001 /*
0002     SPDX-FileCopyrightText: 2013 Lukas Tinkl <ltinkl@redhat.com>
0003     SPDX-FileCopyrightText: 2013-2015 Jan Grulich <jgrulich@redhat.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef MODEMMANAGERQT_BEARER_H
0009 #define MODEMMANAGERQT_BEARER_H
0010 
0011 #include <modemmanagerqt_export.h>
0012 
0013 #include <QObject>
0014 #include <QSharedPointer>
0015 
0016 #include <QDBusPendingReply>
0017 
0018 #include "generictypes.h"
0019 
0020 namespace ModemManager
0021 {
0022 class BearerPrivate;
0023 
0024 /**
0025  * This class represents IP configuration
0026  */
0027 class MODEMMANAGERQT_EXPORT IpConfig
0028 {
0029 public:
0030     /**
0031      * Constructs an empty IP config object
0032      */
0033     IpConfig();
0034 
0035     /**
0036      * Destroys this IpConfig object.
0037      */
0038     ~IpConfig();
0039 
0040     /**
0041      * Constructs an IpConfig object that is a copy of the object @p other.
0042      */
0043     IpConfig(const IpConfig &other);
0044 
0045     /**
0046      * Returns the MMBearerIpMethod
0047      */
0048     MMBearerIpMethod method() const;
0049 
0050     /**
0051      * Sets the MMBearerIpMethod
0052      */
0053     void setMethod(MMBearerIpMethod method);
0054 
0055     /**
0056      * Returns the IP address
0057      */
0058     QString address() const;
0059 
0060     /**
0061      * Sets the IP address
0062      */
0063     void setAddress(const QString &address);
0064 
0065     /**
0066      * Returns the numeric CIDR network prefix (ie, 24, 32, etc)
0067      */
0068     uint prefix() const;
0069 
0070     /**
0071      * Sets the numeric CIDR network prefix
0072      */
0073     void setPrefix(uint prefix);
0074 
0075     /**
0076      * Returns the IP address of the first DNS server
0077      */
0078     QString dns1() const;
0079 
0080     /**
0081      * Sets the IP address of the first DNS server
0082      */
0083     void setDns1(const QString &dns1);
0084 
0085     /**
0086      * Returns the IP address of the second DNS server
0087      */
0088     QString dns2() const;
0089 
0090     /**
0091      * Sets the IP address of the second DNS server
0092      */
0093     void setDns2(const QString &dns2);
0094 
0095     /**
0096      * Returns the IP address of the third DNS server
0097      */
0098     QString dns3() const;
0099 
0100     /**
0101      * Sets the IP address of the third DNS server
0102      */
0103     void setDns3(const QString &dns3);
0104 
0105     /**
0106      * Returns the IP address of the default gateway
0107      */
0108     QString gateway() const;
0109 
0110     /**
0111      * Sets the IP address of the default gateway
0112      */
0113     void setGateway(const QString &gateway);
0114 
0115     /**
0116      * Makes a copy of the IpConfig object @p other.
0117      */
0118     IpConfig &operator=(const IpConfig &other);
0119 
0120 private:
0121     class Private;
0122     Private *const d;
0123 };
0124 
0125 /**
0126  * @brief The Bearer class
0127  *
0128  * This class provides access to specific actions that may be performed on available bearers.
0129  */
0130 class MODEMMANAGERQT_EXPORT Bearer : public QObject
0131 {
0132     Q_OBJECT
0133 public:
0134     typedef QSharedPointer<Bearer> Ptr;
0135     typedef QList<Ptr> List;
0136 
0137     explicit Bearer(const QString &path, QObject *parent = nullptr);
0138     ~Bearer() override;
0139 
0140     /**
0141      * @return the operating system name for the network data interface that
0142      * provides packet data using this bearer.
0143      *
0144      * Connection managers must configure this interface depending on the IP
0145      * "method" given by the ip4Config() or ip6Config() properties set by bearer
0146      * activation.
0147      *
0148      * If MM_BEARER_IP_METHOD_STATIC or MM_BEARER_IP_METHOD_DHCP methods are
0149      * given, the interface will be an ethernet-style interface suitable for DHCP
0150      * or setting static IP configuration on, while if the
0151      * MM_BEARER_IP_METHOD_PPP method is given, the interface will be a serial
0152      * TTY which must then have PPP run over it.
0153      *
0154      */
0155     QString interface() const;
0156 
0157     /**
0158      * @return whether or not the bearer is connected and thus whether packet
0159      * data communication using this bearer is possible.
0160      */
0161     bool isConnected() const;
0162 
0163     /**
0164      * In some devices, packet data service will be suspended while the device
0165      * is handling other communication, like a voice call. If packet data
0166      * service is suspended (but not deactivated) this property will be @p true
0167      */
0168     bool isSuspended() const;
0169 
0170     /**
0171      * If the bearer was configured for IPv4 addressing, upon activation
0172      * this property contains the addressing details for assignment to the data
0173      * interface.
0174      */
0175     IpConfig ip4Config() const;
0176 
0177     /**
0178      * If the bearer was configured for IPv6 addressing, upon activation this
0179      * property contains the addressing details for assignment to the data
0180      * interface.
0181      */
0182     IpConfig ip6Config() const;
0183 
0184     /**
0185      * @return maximum time to wait for a successful IP establishment, when PPP is used.
0186      */
0187     uint ipTimeout() const;
0188 
0189     /**
0190      * @return map of properties used when creating the bearer
0191      * @see IpConfig
0192      */
0193     QVariantMap properties() const;
0194 
0195     /**
0196      * Requests activation of a packet data connection with the network using
0197      * this bearer's properties. Upon successful activation, the modem can send
0198      * and receive packet data and, depending on the addressing capability of
0199      * the modem, a connection manager may need to start PPP, perform DHCP, or
0200      * assign the IP address returned by the modem to the data interface. Upon
0201      * successful return, the ip4Config() and/or ip6Config() properties become
0202      * valid and may contain IP configuration information for the data interface
0203      * associated with this bearer.
0204      */
0205     QDBusPendingReply<void> connectBearer();
0206 
0207     /**
0208      * Disconnect and deactivate this packet data connection.
0209      *
0210      * Any ongoing data session will be terminated and IP addresses become invalid when this method is called.
0211      */
0212     QDBusPendingReply<void> disconnectBearer();
0213 
0214     /**
0215      * Sets the timeout in milliseconds for all async method DBus calls.
0216      * -1 means the default DBus timeout (usually 25 seconds).
0217      */
0218     void setTimeout(int timeout);
0219 
0220     /**
0221      * Returns the current value of the DBus timeout in milliseconds.
0222      * -1 means the default DBus timeout (usually 25 seconds).
0223      */
0224     int timeout() const;
0225 
0226     /**
0227      * @return the DBUS path (uni) to the object
0228      */
0229     QString uni() const;
0230 
0231 Q_SIGNALS:
0232     void interfaceChanged(const QString &iface);
0233     void connectedChanged(bool connected);
0234     void suspendedChanged(bool suspended);
0235     void ip4ConfigChanged(const ModemManager::IpConfig &ipv4Config);
0236     void ip6ConfigChanged(const ModemManager::IpConfig &ipv6Config);
0237     void ipTimeoutChanged(uint ipTimeout);
0238     void propertiesChanged(const QVariantMap &properties);
0239 
0240 private:
0241     Q_DECLARE_PRIVATE(Bearer)
0242     BearerPrivate *const d_ptr;
0243 };
0244 
0245 } // namespace ModemManager
0246 
0247 Q_DECLARE_METATYPE(ModemManager::IpConfig)
0248 
0249 #endif