diff options
author | Raquel Medina <raquel.medina@konsulko.com> | 2019-09-09 00:35:55 +0200 |
---|---|---|
committer | raquel medina <raquel.medina@konsulko.com> | 2019-09-10 14:09:30 +0000 |
commit | 4221fd2f9e5b72090fe5c2c5f19aa16ab8bf68b8 (patch) | |
tree | 82a6e7e606c85e75e36cdd71c07f6f5aed802f4d /network | |
parent | a824dc2de24ac3789207a5fb9d89400bc83891f9 (diff) |
wired: add hooks for addressing configuration
- Add new roles to provide UI clients with the
active configuration (values obtained from the
stack: agl-service-network binding + connman).
- Add Q_INVOKABLE methods to feed new values
from the UI client.
SPEC-2676
Signed-off-by: Raquel Medina <raquel.medina@konsulko.com>
Change-Id: Id239ddc549ec8471d44d56f7631d4e9e3efda798
Diffstat (limited to 'network')
-rw-r--r-- | network/connectionprofile.cpp | 61 | ||||
-rw-r--r-- | network/connectionprofile.h | 24 | ||||
-rw-r--r-- | network/network.cpp | 44 | ||||
-rw-r--r-- | network/network.h | 2 | ||||
-rw-r--r-- | network/wifiadapter.cpp | 11 | ||||
-rw-r--r-- | network/wiredadapter.cpp | 21 | ||||
-rw-r--r-- | network/wirednetworkmodel.cpp | 55 | ||||
-rw-r--r-- | network/wirednetworkmodel.h | 4 |
8 files changed, 206 insertions, 16 deletions
diff --git a/network/connectionprofile.cpp b/network/connectionprofile.cpp index 8e30e47..6fec374 100644 --- a/network/connectionprofile.cpp +++ b/network/connectionprofile.cpp @@ -5,9 +5,16 @@ ConnectionProfile::ConnectionProfile(const QString &address, const QString &service, const QString &state, const QString &ssid, - const int &strength) + const int &strength, + const QString &netmask, + const QString &gateway, + const QString &amethod, + const QString &ns, + const QString &nsmethod) : m_address(address), m_security(security), m_service(service), - m_state(state), m_ssid(ssid), m_strength(strength) + m_state(state), m_ssid(ssid), m_strength(strength), m_netmask(netmask), + m_gateway(gateway), m_addrmethod(amethod), m_nameservers(ns), + m_nsmethod(nsmethod) { } @@ -41,6 +48,31 @@ int ConnectionProfile::strength() const return m_strength; } +QString ConnectionProfile::netmask() const +{ + return m_netmask; +} + +QString ConnectionProfile::gateway() const +{ + return m_gateway; +} + +QString ConnectionProfile::nameservers() const +{ + return m_nameservers; +} + +QString ConnectionProfile::addrmethod() const +{ + return m_addrmethod; +} + +QString ConnectionProfile::nsmethod() const +{ + return m_nsmethod; +} + void ConnectionProfile::setAddress(const QString address) { m_address = address; @@ -55,3 +87,28 @@ void ConnectionProfile::setStrength(const int strength) { m_strength = strength; } + +void ConnectionProfile::setNetmask(const QString netmask) +{ + m_netmask = netmask; +} + +void ConnectionProfile::setGateway(const QString gateway) +{ + m_gateway = gateway; +} + +void ConnectionProfile::setNameservers(const QString nameservers) +{ + m_nameservers = nameservers; +} + +void ConnectionProfile::setAddrMethod(const QString method) +{ + m_addrmethod = method; +} + +void ConnectionProfile::setNSMethod(const QString method) +{ + m_nsmethod = method; +} diff --git a/network/connectionprofile.h b/network/connectionprofile.h index 1f5bafa..92bbd0f 100644 --- a/network/connectionprofile.h +++ b/network/connectionprofile.h @@ -11,16 +11,33 @@ class ConnectionProfile const QString &service, const QString &ssid, const QString &state, - const int &strength); + const int &strength, + const QString &netmask, + const QString &gateway, + const QString &amethod, + const QString &ns, + const QString &nsmethod); + QString address() const; QString service() const; QString ssid() const; QString security() const; QString state() const; int strength() const; + QString netmask() const; + QString gateway() const; + QString nameservers() const; + QString addrmethod() const; + QString nsmethod() const; + void setAddress(const QString address); void setState(const QString state); void setStrength(const int strength); + void setNetmask(const QString netmask); + void setGateway(const QString gateway); + void setNameservers(const QString nameservers); + void setAddrMethod(const QString method); + void setNSMethod(const QString method); private: QString m_address; @@ -29,6 +46,11 @@ class ConnectionProfile QString m_state; QString m_ssid; int m_strength; + QString m_netmask; + QString m_gateway; + QString m_addrmethod; + QString m_nameservers; + QString m_nsmethod; }; #endif // CONNECTION_PROFILE_H diff --git a/network/network.cpp b/network/network.cpp index 4ce701f..f7baf06 100644 --- a/network/network.cpp +++ b/network/network.cpp @@ -102,6 +102,50 @@ void Network::input(int id, QString passphrase) delete nmsg; } +void Network::configureAddress(QString service, QVariantList paramlist) +{ + NetworkMessage *nmsg = new NetworkMessage(); + QJsonObject parameter, properties; + QJsonArray values = QJsonArray::fromVariantList(paramlist); + + if (values.isEmpty() || values.count() < 4) { + qWarning("Invalid addressing params"); + return; + } + + properties.insert("method", values[0]); + properties.insert("address", values[1]); + properties.insert("netmask", values[2]); + properties.insert("gateway", values[3]); + parameter.insert("properties", properties); + parameter.insert("service", service); + + nmsg->createRequest("set_property", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; +} + +void Network::configureNameServer(QString service, QVariantList paramlist) +{ + NetworkMessage *nmsg = new NetworkMessage(); + QJsonObject parameter, properties; + QJsonArray values = QJsonArray::fromVariantList(paramlist); + + if (values.isEmpty() || values.count() < 2) { + qWarning("Invalid nameserver params"); + return; + } + + parameter.insert("service", service); + properties.insert("method", values[0]); + properties.insert("nameservers", values[1]); + parameter.insert("properties", properties); + + nmsg->createRequest("set_property", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; +} + void Network::getServices() { NetworkMessage *nmsg = new NetworkMessage(); diff --git a/network/network.h b/network/network.h index b289f42..aa83fed 100644 --- a/network/network.h +++ b/network/network.h @@ -42,6 +42,8 @@ class Network : public QObject Q_INVOKABLE void remove(QString service); Q_INVOKABLE void power(bool on, QString type = "wifi"); Q_INVOKABLE void input(int id, QString passphrase); + Q_INVOKABLE void configureAddress(QString service, QVariantList paramlist); + Q_INVOKABLE void configureNameServer(QString service, QVariantList paramlist); void getServices(); AdapterIf* findAdapter(QString type); diff --git a/network/wifiadapter.cpp b/network/wifiadapter.cpp index 440e541..98f73fa 100644 --- a/network/wifiadapter.cpp +++ b/network/wifiadapter.cpp @@ -83,17 +83,18 @@ bool WifiAdapter::addService(QString id, QJsonObject properties) 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(); - // Ignore hidden SSIDs or services already added - if (m_model->getNetwork(id) || (ssid == "")) - return false; - - ConnectionProfile *network = new ConnectionProfile(address, security, id, state, ssid, strength); + ConnectionProfile *network = new ConnectionProfile(address, security, id, state, ssid, + strength, "", "", "", "", ""); m_model->addNetwork(network); if ((state == "ready") || (state == "online")) diff --git a/network/wiredadapter.cpp b/network/wiredadapter.cpp index 224d13a..297ba44 100644 --- a/network/wiredadapter.cpp +++ b/network/wiredadapter.cpp @@ -74,16 +74,25 @@ bool WiredAdapter::addService(QString id, QJsonObject properties) if (type != getType()) return false; - QString state = properties.value("state").toString(); - // 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(); - // Ignore services already added if (m_model->getNetwork(id)) return false; - ConnectionProfile *network = new ConnectionProfile(address, security, id, state, "",0); + QString state = properties.value("state").toString(); + // Initially support only IPv4 and the first security method found + QString security = properties.value("security").toArray().at(0).toString(); + QJsonObject ipv4obj = properties.value("ipv4").toObject(); + QString address = ipv4obj.value("address").toString(); + QString netmask = ipv4obj.value("netmask").toString(); + QString gateway = ipv4obj.value("gateway").toString(); + QString amethod = ipv4obj.value("method").toString(); + QString ns = properties.value("nameservers").toString(); + QString nsmethod = (amethod == "dhcp")? "auto" : "manual"; + + ConnectionProfile *network = new ConnectionProfile(address, security, id, + state, "", 0, netmask, + gateway, amethod, ns, + nsmethod); m_model->addNetwork(network); return true; diff --git a/network/wirednetworkmodel.cpp b/network/wirednetworkmodel.cpp index 01a50fb..0d1209e 100644 --- a/network/wirednetworkmodel.cpp +++ b/network/wirednetworkmodel.cpp @@ -8,6 +8,40 @@ WiredNetworkModel::WiredNetworkModel(QObject *parent) { } +QVariantList WiredNetworkModel::readCurrentRouteConfig(const QModelIndex &index) const +{ + QVariantList ret; + + if (!index.isValid()) + return ret; + + if (index.row() < 0 || index.row() >= this->m_networks.count()) + return ret; + + const ConnectionProfile *network = this->m_networks[index.row()]; + ret.append(network->addrmethod()); + ret.append(network->address()); + ret.append(network->netmask()); + ret.append(network->gateway()); + return ret; +} + +QVariantList WiredNetworkModel::readCurrentNameServerConfig(const QModelIndex &index) const +{ + QVariantList ret; + + if (!index.isValid()) + return ret; + + if (index.row() < 0 || index.row() >= this->m_networks.count()) + return ret; + + const ConnectionProfile *network = this->m_networks[index.row()]; + ret.append(network->nsmethod()); + ret.append(network->nameservers()); + return ret; +} + QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const { QVariant ret; @@ -29,6 +63,10 @@ QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const return network->service(); case StateRole: return network->state(); + case RouteRole: + return readCurrentRouteConfig(index); + case NameServerRole: + return readCurrentNameServerConfig(index); } return ret; @@ -40,6 +78,8 @@ QHash<int, QByteArray> WiredNetworkModel::roleNames() const { roles[SecurityRole] = "security"; roles[ServiceRole] = "service"; roles[StateRole] = "sstate"; + roles[RouteRole] = "sroute"; + roles[NameServerRole] = "nservers"; return roles; } @@ -51,9 +91,20 @@ void WiredNetworkModel::updateProperties(QString service, QJsonObject properties if ((network = getNetwork(service))) { if (properties.contains("ipv4")) { - QString address = properties.value("ipv4").toObject().value("address").toString(); - network->setAddress(address); + QJsonObject ipv4obj = properties.value("ipv4").toObject(); + network->setAddress(ipv4obj.value("address").toString()); + network->setNetmask(ipv4obj.value("netmask").toString()); + network->setGateway(ipv4obj.value("gateway").toString()); + network->setAddrMethod(ipv4obj.value("method").toString()); vroles.push_back(AddressRole); + vroles.push_back(RouteRole); + } + if (properties.contains("nameservers")) { + QString nservers = properties.value("nameservers").toString(); + network->setNameservers(nservers); + (network->addrmethod() == "dhcp")? network->setNSMethod("auto") : + network->setNSMethod("manual"); + vroles.push_back(NameServerRole); } if (properties.contains("state")) { network->setState(properties.value("state").toString()); diff --git a/network/wirednetworkmodel.h b/network/wirednetworkmodel.h index b73fa3f..c8ea92d 100644 --- a/network/wirednetworkmodel.h +++ b/network/wirednetworkmodel.h @@ -13,10 +13,14 @@ class WiredNetworkModel : public AbstractNetworkModel SecurityRole, ServiceRole, StateRole, + RouteRole, + NameServerRole, }; WiredNetworkModel(QObject *parent = Q_NULLPTR); + Q_INVOKABLE QVariantList readCurrentRouteConfig(const QModelIndex &index) const; + Q_INVOKABLE QVariantList readCurrentNameServerConfig(const QModelIndex &index) const; QString getType() const override { return "wired"; } QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; void updateProperties(QString service, QJsonObject properties) override; |