summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kacej <[email protected]>2018-04-27 21:42:25 +0200
committerMartin Kacej <[email protected]>2018-04-27 21:42:25 +0200
commit0ed9e08c7d9754e2a2c96b7d97f58231bffc9d6e (patch)
tree2bdd1b4d91e002f85bfd03eb07ceb766c6781e92
parent0cbe4762d41bb22b3176517381a8e4501ae06487 (diff)
mobile utils creating connection refactored, added access point support
-rw-r--r--libs/mobileutils.cpp133
-rw-r--r--libs/mobileutils.h4
2 files changed, 93 insertions, 44 deletions
diff --git a/libs/mobileutils.cpp b/libs/mobileutils.cpp
index 896daf8..8a03538 100644
--- a/libs/mobileutils.cpp
+++ b/libs/mobileutils.cpp
@@ -105,57 +105,66 @@ void MobileUtils::addConnectionFromQML(const QVariantMap &QMLmap)
if (QMLmap.isEmpty())
return;
+ NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless));
+ connectionSettings->setId(QMLmap.value(QLatin1String("id")).toString());
+ connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
+
+ NetworkManager::WirelessSetting::Ptr wirelessSettings = NetworkManager::WirelessSetting::Ptr(new NetworkManager::WirelessSetting());
+ wirelessSettings->setSsid(QMLmap.value(QLatin1String("id")).toString().toUtf8());
if (QMLmap["mode"].toString() == "infrastructure") {
- NetworkManager::WirelessSetting::Ptr wirelessSettings = NetworkManager::WirelessSetting::Ptr(new NetworkManager::WirelessSetting());
- wirelessSettings->setSsid(QMLmap.value(QLatin1String("id")).toString().toUtf8());
wirelessSettings->setMode(NetworkManager::WirelessSetting::Infrastructure);
+ }
+ if (QMLmap["mode"].toString() == "ap") {
+ wirelessSettings->setMode(NetworkManager::WirelessSetting::Ap);
+ }
+ if (QMLmap.contains("hidden")) {
+ wirelessSettings->setHidden(QMLmap.value("hidden").toBool());
+ }
- NetworkManager::Ipv4Setting::Ptr ipSettings = NetworkManager::Ipv4Setting::Ptr(new NetworkManager::Ipv4Setting());
- if (QMLmap["method"] == QLatin1String("auto")) {
- ipSettings->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Automatic);
- } else {
- ipSettings->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Manual);
- NetworkManager::IpAddress ipaddr;
- ipaddr.setIp(QHostAddress(QMLmap["address"].toString()));
- ipaddr.setPrefixLength(QMLmap["prefix"].toInt());
- ipaddr.setGateway(QHostAddress(QMLmap["gateway"].toString()));
- ipSettings->setAddresses(QList<NetworkManager::IpAddress>({ipaddr}));
- ipSettings->setDns(QList<QHostAddress>({QHostAddress(QMLmap["dns"].toString())}));
- }
+ NetworkManager::Ipv4Setting::Ptr ipSettings = NetworkManager::Ipv4Setting::Ptr(new NetworkManager::Ipv4Setting());
+ if (QMLmap["method"] == QLatin1String("auto")) {
+ ipSettings->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Automatic);
+ }
+ if (QMLmap["method"] == QLatin1String("shared")) {
+ ipSettings->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Shared);
+ }
+ if (QMLmap["method"] == QLatin1String("manual")) {
+ ipSettings->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Manual);
+ NetworkManager::IpAddress ipaddr;
+ ipaddr.setIp(QHostAddress(QMLmap["address"].toString()));
+ ipaddr.setPrefixLength(QMLmap["prefix"].toInt());
+ ipaddr.setGateway(QHostAddress(QMLmap["gateway"].toString()));
+ ipSettings->setAddresses(QList<NetworkManager::IpAddress>({ipaddr}));
+ ipSettings->setDns(QList<QHostAddress>({QHostAddress(QMLmap["dns"].toString())}));
+ }
- NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless));
- connectionSettings->setId(QMLmap.value(QLatin1String("id")).toString());
- connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
-
- NMVariantMapMap map = connectionSettings->toMap();
- map.insert("802-11-wireless",wirelessSettings->toMap());
- map.insert("ipv4",ipSettings->toMap());
-
- if (QMLmap.contains("802-11-wireless-security")) {
- QVariantMap securMap = QMLmap["802-11-wireless-security"].toMap();
- int type = securMap["type"].toInt();
- if (!type == NetworkManager::NoneSecurity) {
- NetworkManager::WirelessSecuritySetting::Ptr securitySettings = NetworkManager::WirelessSecuritySetting::Ptr(new NetworkManager::WirelessSecuritySetting());
- if (type == NetworkManager::Wpa2Psk ) {
- securitySettings->setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaPsk);
- securitySettings->setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg::Open);
- securitySettings->setPskFlags(NetworkManager::Setting::SecretFlagType::AgentOwned);
- securitySettings->setPsk(securMap["password"].toString());
- }
-
- if (type == NetworkManager::StaticWep) {
- securitySettings->setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt::Wep);
- securitySettings->setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg::Open);
- securitySettings->setWepKeyType(NetworkManager::WirelessSecuritySetting::WepKeyType::Hex);
- securitySettings->setWepKeyFlags(NetworkManager::Setting::SecretFlagType::AgentOwned);
- securitySettings->setWepKey0(securMap["password"].toString());
- }
- map.insert("802-11-wireless-security",securitySettings->toMap());
+ NMVariantMapMap map = connectionSettings->toMap();
+ map.insert("802-11-wireless",wirelessSettings->toMap());
+ map.insert("ipv4",ipSettings->toMap());
+
+ if (QMLmap.contains("802-11-wireless-security")) {
+ QVariantMap securMap = QMLmap["802-11-wireless-security"].toMap();
+ int type = securMap["type"].toInt();
+ if (!type == NetworkManager::NoneSecurity) {
+ NetworkManager::WirelessSecuritySetting::Ptr securitySettings = NetworkManager::WirelessSecuritySetting::Ptr(new NetworkManager::WirelessSecuritySetting());
+ if (type == NetworkManager::Wpa2Psk ) {
+ securitySettings->setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaPsk); // TODO ap
+ securitySettings->setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg::Open);
+ securitySettings->setPskFlags(NetworkManager::Setting::SecretFlagType::AgentOwned);
+ securitySettings->setPsk(securMap["password"].toString());
+ }
+ if (type == NetworkManager::StaticWep) {
+ securitySettings->setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt::Wep);
+ securitySettings->setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg::Open);
+ securitySettings->setWepKeyType(NetworkManager::WirelessSecuritySetting::WepKeyType::Hex);
+ securitySettings->setWepKeyFlags(NetworkManager::Setting::SecretFlagType::AgentOwned);
+ securitySettings->setWepKey0(securMap["password"].toString());
}
+ map.insert("802-11-wireless-security",securitySettings->toMap());
}
- //qWarning() << map;
- NetworkManager::addConnection(map);
}
+ //qWarning() << map;
+ NetworkManager::addConnection(map);
}
void MobileUtils::updateConnectionFromQML(const QString &path, const QVariantMap &map)
@@ -202,3 +211,39 @@ void MobileUtils::updateConnectionFromQML(const QString &path, const QVariantMap
}
con->update(toUpdateMap);
}
+
+QString MobileUtils::getAccessPointDevice()
+{
+ NetworkManager::WirelessDevice::Ptr device;
+ foreach (const NetworkManager::Device::Ptr &dev, NetworkManager::networkInterfaces()) {
+ if (dev->type() == NetworkManager::Device::Wifi){
+ device = dev.staticCast<NetworkManager::WirelessDevice>();
+ if (device->wirelessCapabilities().testFlag(NetworkManager::WirelessDevice::ApCap))
+ break; // we have wireless device with access point capability
+ }
+ }
+ if (device) {
+ return device->uni();
+ } else {
+ qWarning() << "No wireless device found";
+ }
+ return QString();
+}
+
+QString MobileUtils::getAccesPointConnection()
+{
+ foreach (const NetworkManager::Connection::Ptr &con, NetworkManager::listConnections()) {
+ NetworkManager::Setting::Ptr d = con->settings()->setting(NetworkManager::Setting::Wireless);
+ if (!d.isNull()){
+ if( d.staticCast<NetworkManager::WirelessSetting>()->mode() == NetworkManager::WirelessSetting::Ap){
+ return con->path();
+ }
+ }
+ }
+ return QString();
+}
+
+void MobileUtils::startAccessPoint(const QString &uuid, const QString &device)
+{
+ return QString();
+}
diff --git a/libs/mobileutils.h b/libs/mobileutils.h
index de7577c..2df7311 100644
--- a/libs/mobileutils.h
+++ b/libs/mobileutils.h
@@ -32,6 +32,10 @@ public:
Q_INVOKABLE QVariantMap getActiveConnectionInfo(const QString &connection);
Q_INVOKABLE void addConnectionFromQML(const QVariantMap &QMLmap);
Q_INVOKABLE void updateConnectionFromQML(const QString &path, const QVariantMap &map);
+ Q_INVOKABLE QString getAccessPointDevice();
+ Q_INVOKABLE QString getAccesPointConnection();
+ Q_INVOKABLE void startAccessPoint(const QString &uuid,const QString &device);
+
};
#endif // MOBILEUTILS_H