summaryrefslogtreecommitdiffstats
path: root/network/wifiadapter.cpp
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2022-01-28 16:54:55 -0500
committerScott Murray <scott.murray@konsulko.com>2022-01-28 17:00:09 -0500
commit5ef90db242ad29c9772f2237b477c58ef65545c7 (patch)
treef9b7b2e56a0aaec37bb9ef99faa316465613b941 /network/wifiadapter.cpp
parent0fee9bfb0f656b78f34c44542329760be2980892 (diff)
Re-enable network supportmarlin_12.92.0marlin/12.92.012.92.0
Rework network support code to use new connman-glib library instead of the previously disabled agl-service-network API. The only user visible change is that a few extra previously exported header files have been pruned from installation to avoid exposing GLib usage and potentially requiring users needing to build against it. Bug-AGL: SPEC-4182 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: Iab8f3c9d04ee603e06b80dfd92ac03d9d52af477
Diffstat (limited to 'network/wifiadapter.cpp')
-rw-r--r--network/wifiadapter.cpp169
1 files changed, 105 insertions, 64 deletions
diff --git a/network/wifiadapter.cpp b/network/wifiadapter.cpp
index 98f73fa..0670eff 100644
--- a/network/wifiadapter.cpp
+++ b/network/wifiadapter.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Konsulko Group
+ * Copyright (C) 2019,2022 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,92 +19,133 @@
#include <QtQml/QQmlEngine>
#include "network.h"
-#include "networkadapter.h"
+#include "wifiadapter.h"
#include "wifinetworkmodel.h"
#include "connectionprofile.h"
WifiAdapter::WifiAdapter(Network *network, QQmlContext *context, QObject *parent) :
- QObject(parent),
- AdapterIf(),
- m_wifiConnected(false),
- m_wifiEnabled(false),
- m_wifiStrength(0),
- m_model(nullptr),
- nw(network)
+ QObject(parent),
+ AdapterIf(),
+ m_wifiConnected(false),
+ m_wifiEnabled(false),
+ m_wifiStrength(0),
+ m_model(nullptr),
+ nw(network)
{
- m_model = new WifiNetworkModel();
- QSortFilterProxyModel *model = new QSortFilterProxyModel();
- model->setSourceModel(m_model);
- model->setSortRole(WifiNetworkModel::WifiNetworkRoles::SsidRole);
- model->setSortCaseSensitivity(Qt::CaseInsensitive);
- model->sort(0);
-
- context->setContextProperty("WifiNetworkModel", m_model);
- QObject::connect(m_model, &WifiNetworkModel::strengthChanged, this, &WifiAdapter::updateWifiStrength);
- context->setContextProperty("WifiAdapter", this);
+ m_model = new WifiNetworkModel();
+ QSortFilterProxyModel *model = new QSortFilterProxyModel();
+ model->setSourceModel(m_model);
+ model->setSortRole(WifiNetworkModel::WifiNetworkRoles::SsidRole);
+ model->setSortCaseSensitivity(Qt::CaseInsensitive);
+ model->sort(0);
+
+ context->setContextProperty("WifiNetworkModel", m_model);
+ QObject::connect(m_model, &WifiNetworkModel::strengthChanged, this, &WifiAdapter::updateWifiStrength);
+ context->setContextProperty("WifiAdapter", this);
}
WifiAdapter::~WifiAdapter()
{
- delete m_model;
+ delete m_model;
}
-void WifiAdapter::updateStatus(QJsonObject properties)
+void WifiAdapter::updateStatus(const QVariantMap &properties)
{
- if (properties.contains("connected")) {
- m_wifiConnected = properties.value("connected").toBool();
- emit wifiConnectedChanged(m_wifiConnected);
- }
-
- if (properties.contains("powered")) {
- m_wifiEnabled = properties.value("powered").toBool();
- emit wifiEnabledChanged(m_wifiEnabled);
- if (m_wifiEnabled)
- nw->getServices();
- }
+ QString key = "Connected";
+ if (properties.contains(key)) {
+ m_wifiConnected = properties.value(key).toBool();
+ emit wifiConnectedChanged(m_wifiConnected);
+ }
+
+ key = "Powered";
+ if (properties.contains(key)) {
+ m_wifiEnabled = properties.value(key).toBool();
+ emit wifiEnabledChanged(m_wifiEnabled);
+ if (m_wifiEnabled)
+ nw->getServices();
+ }
}
void WifiAdapter::updateWifiStrength(int strength)
{
- m_wifiStrength = strength;
- emit wifiStrengthChanged(m_wifiStrength);
+ m_wifiStrength = strength;
+ emit wifiStrengthChanged(m_wifiStrength);
}
-void WifiAdapter::updateProperties(QString id, QJsonObject properties)
+void WifiAdapter::updateProperties(const QString &id, const QVariantMap &properties)
{
- if (m_model->getNetwork(id))
- m_model->updateProperties(id, properties);
+ if (m_model->getNetwork(id))
+ m_model->updateProperties(id, properties);
}
-bool WifiAdapter::addService(QString id, QJsonObject properties)
+bool WifiAdapter::addService(const QString &id, const QVariantMap &properties)
{
- QString type = properties.value("type").toString();
- if (type != getType())
- return false;
-
- QString ssid = properties.value("name").toString();
- // Ignore hidden SSIDs or services already added
- if (m_model->getNetwork(id) || (ssid == ""))
- return false;
-
- QString state = properties.value("state").toString();
- int strength = properties.value("strength").toInt();
- // Initially support only IPv4 and the first security method found
- QString address = properties.value("ipv4").toObject().value("address").toString();
- QString security = properties.value("security").toArray().at(0).toString();
-
- ConnectionProfile *network = new ConnectionProfile(address, security, id, state, ssid,
- strength, "", "", "", "", "");
- m_model->addNetwork(network);
-
- if ((state == "ready") || (state == "online"))
- updateWifiStrength(strength);
-
- return true;
+ QString type;
+ QString key = "Type";
+ if (properties.contains(key)) {
+ type = properties.value(key).toString();
+ if (type != getType())
+ return false;
+ }
+
+ QString ssid;
+ key = "Name";
+ if (properties.contains(key))
+ ssid = properties.value(key).toString();
+
+ // Ignore hidden SSIDs or services already added
+ if (m_model->getNetwork(id) || (ssid == ""))
+ return false;
+
+ QString state;
+ key = "State";
+ if (properties.contains(key))
+ state = properties.value(key).toString();
+
+ int strength = 0;
+ key = "Strength";
+ if (properties.contains(key))
+ strength = properties.value(key).toInt();
+
+ // Initially support only IPv4 and the first security method found
+ QString address;
+ key = "IPv4";
+ if (properties.contains(key)) {
+ QVariantMap ip4_map = properties.value(key).toMap();
+
+ key = "Address";
+ if (ip4_map.contains(key))
+ address = ip4_map.value(key).toString();
+ }
+
+ QString security;
+ key = "Security";
+ if (properties.contains(key)) {
+ QVariantList security_list = properties.value(key).toList();
+
+ if (!security_list.isEmpty())
+ security = security_list[0].toString();
+ }
+
+#if LIBQTAPPFW_NETWORK_DEBUG
+ qDebug() << "WifiAdapter::addService: address = " << address
+ << ", id = " << id
+ << ", state = " << state
+ << ", ssid = " << ssid
+ << ", strength = " << strength
+ << ", security = " << security;
+#endif
+ ConnectionProfile *network = new ConnectionProfile(address, security, id, state, ssid,
+ strength, "", "", "", "", "");
+ m_model->addNetwork(network);
+
+ if ((state == "ready") || (state == "online"))
+ updateWifiStrength(strength);
+
+ return true;
}
-void WifiAdapter::removeService(QString id)
+void WifiAdapter::removeService(const QString &id)
{
- m_model->removeNetwork(m_model->getNetwork(id));
-
+ m_model->removeNetwork(m_model->getNetwork(id));
}