Skip to content

Commit

Permalink
Merge PR #32: Add wireless network device capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins committed Nov 6, 2024
2 parents 81ea35f + 84f717a commit 4cf8a01
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libnymea-networkmanager/networkmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ NetworkManager::NetworkManagerError NetworkManager::startAccessPoint(const QStri
if (!wirelessNetworkDevice)
return NetworkManagerErrorInvalidNetworkDeviceType;


if (!wirelessNetworkDevice->wirelessCapabilities().testFlag(WirelessNetworkDevice::WirelessCapabilityAP))
return NetworkManagerErrorUnsupportedFeature;

// Note: https://developer.gnome.org/NetworkManager/stable/ref-settings.html

// Create network settings for access point
Expand Down
1 change: 1 addition & 0 deletions libnymea-networkmanager/networkmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class NetworkManager : public QObject
NetworkManagerErrorNetworkingDisabled,
NetworkManagerErrorNetworkManagerNotAvailable,
NetworkManagerErrorInvalidConfiguration,
NetworkManagerErrorUnsupportedFeature
};
Q_ENUM(NetworkManagerError)

Expand Down
12 changes: 12 additions & 0 deletions libnymea-networkmanager/wirelessnetworkdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ WirelessNetworkDevice::WirelessNetworkDevice(const QDBusObjectPath &objectPath,
readAccessPoints();

m_macAddress = m_wirelessInterface->property("HwAddress").toString();
m_wirelessCapabilities = static_cast<WirelessCapabilities>(m_wirelessInterface->property("WirelessCapabilities").toUInt());
m_wirelessMode = static_cast<WirelessMode>(m_wirelessInterface->property("Mode").toUInt());
m_bitRate = m_wirelessInterface->property("Bitrate").toInt() / 1000;
setActiveAccessPoint(qdbus_cast<QDBusObjectPath>(m_wirelessInterface->property("ActiveAccessPoint")));
Expand All @@ -107,6 +108,11 @@ int WirelessNetworkDevice::bitRate() const
return m_bitRate;
}

WirelessNetworkDevice::WirelessCapabilities WirelessNetworkDevice::wirelessCapabilities() const
{
return m_wirelessCapabilities;
}

WirelessNetworkDevice::WirelessMode WirelessNetworkDevice::wirelessMode() const
{
return m_wirelessMode;
Expand Down Expand Up @@ -236,6 +242,11 @@ void WirelessNetworkDevice::processProperties(const QVariantMap &properties)
emit wirelessModeChanged(m_wirelessMode);
}

if (properties.contains("WirelessCapabilities")) {
m_wirelessCapabilities = static_cast<WirelessCapabilities>(m_wirelessInterface->property("WirelessCapabilities").toUInt());
emit wirelessCapabilitiesChanged(m_wirelessCapabilities);
}

// Note: available since 1.12 (-1 means never scanned)
if (properties.contains("LastScan")) {
m_lastScan = m_wirelessInterface->property("LastScan").toInt();
Expand All @@ -262,6 +273,7 @@ QDebug operator<<(QDebug debug, WirelessNetworkDevice *device)
{
debug.nospace() << "WirelessNetworkDevice(" << device->interface() << ", ";
debug.nospace() << device->macAddress() << ", ";
debug.nospace() << device->wirelessCapabilities() << ", ";
debug.nospace() << device->wirelessMode() << ", ";
debug.nospace() << device->bitRate() << " [Mb/s], ";
debug.nospace() << device->deviceStateString() << ") ";
Expand Down
21 changes: 21 additions & 0 deletions libnymea-networkmanager/wirelessnetworkdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,30 @@ class WirelessNetworkDevice : public NetworkDevice
};
Q_ENUM(WirelessMode)

enum WirelessCapability {
WirelessCapabilityNone = 0x0000,
WirelessCapabilityCipherWEP40 = 0x0001,
WirelessCapabilityCipherWEP104 = 0x0002,
WirelessCapabilityCipherTKIP = 0x0004,
WirelessCapabilityCipherCCMP = 0x0008,
WirelessCapabilityWPA = 0x0010,
WirelessCapabilityRSN = 0x0020,
WirelessCapabilityAP = 0x0040,
WirelessCapabilityAdHoc = 0x0080,
WirelessCapabilityFreqValid = 0x0100,
WirelessCapability2Ghz = 0x0200,
WirelessCapability5Ghz = 0x0400,
};
Q_ENUM(WirelessCapability)
Q_DECLARE_FLAGS(WirelessCapabilities, WirelessCapability)
Q_FLAG(WirelessCapabilities)

explicit WirelessNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = nullptr);

// Properties
QString macAddress() const;
int bitRate() const;
WirelessCapabilities wirelessCapabilities() const;
WirelessMode wirelessMode() const;
WirelessAccessPoint *activeAccessPoint();

Expand All @@ -72,6 +91,7 @@ class WirelessNetworkDevice : public NetworkDevice

signals:
void bitRateChanged(int bitRate);
void wirelessCapabilitiesChanged(WirelessCapabilities wirelessCapabilities);
void wirelessModeChanged(WirelessMode mode);
void lastScanChanged(int lastScan);

Expand All @@ -87,6 +107,7 @@ private slots:

int m_bitRate;
QString m_macAddress;
WirelessCapabilities m_wirelessCapabilities = WirelessCapabilityNone;
WirelessMode m_wirelessMode = WirelessModeUnknown;
int m_lastScan = -1;
QDBusObjectPath m_activeAccessPointObjectPath;
Expand Down

0 comments on commit 4cf8a01

Please sign in to comment.