Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wireless network device capabilities #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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