link negotiation, speed, duplex mode for Ethernet devices

main
Aaron Rainbolt 1 year ago
parent 48a0974529
commit a0f4cc10be

@ -15,12 +15,12 @@ QString ConnectionSettingsEngine::targetConnUuidStr = QString();
* meteredConnection: ConnectionSettingsEngine::Metered
* device: QString
* clonedMacAddress: QString
* !mtu: int
* mtu: int
*
* For Ethernet devices only:
* !linkNegotiation: QString
* !linkSpeed: ConnectionSettingsEngine::LinkSpeed
* !duplexMode: QString
* autoLinkNegotiation: ConnectionSettingsEngine::LinkNegotiation
* linkSpeed: ConnectionSettingsEngine::LinkSpeed
* duplexMode: ConnectionSettingsEngine::DuplexMode
*/
ConnectionSettingsEngine::ConnectionSettingsEngine()
@ -84,6 +84,57 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
if (!connWiredSetting.isNull()) {
result.insert("clonedMacAddress", NetworkManager::macAddressAsString(connWiredSetting->clonedMacAddress()));
result.insert("mtu", connWiredSetting->mtu());
if (connWiredSetting->autoNegotiate()) {
result.insert("autoLinkNegotiation", ConnectionSettingsEngine::NegotiationAutomatic);
result.insert("linkSpeed", ConnectionSettingsEngine::SpeedUnknown);
result.insert("duplexMode", ConnectionSettingsEngine::DuplexUnknown);
} else if (connWiredSetting->speed() != 0 && connWiredSetting->duplexType() != NetworkManager::WiredSetting::UnknownDuplexType) {
result.insert("autoLinkNegotiation", ConnectionSettingsEngine::NegotiationManual);
switch (connWiredSetting->speed()) {
case 10:
result.insert("linkSpeed", ConnectionSettingsEngine::Speed10Mbps);
break;
case 100:
result.insert("linkSpeed", ConnectionSettingsEngine::Speed100Mbps);
break;
case 1000:
result.insert("linkSpeed", ConnectionSettingsEngine::Speed1Gbps);
break;
case 2500:
result.insert("linkSpeed", ConnectionSettingsEngine::Speed2_5Gbps);
break;
case 5000:
result.insert("linkSpeed", ConnectionSettingsEngine::Speed5Gbps);
break;
case 10000:
result.insert("linkSpeed", ConnectionSettingsEngine::Speed10Gbps);
break;
case 40000:
result.insert("linkSpeed", ConnectionSettingsEngine::Speed40Gbps);
break;
case 100000:
result.insert("linkSpeed", ConnectionSettingsEngine::Speed100Gbps);
break;
}
switch (connWiredSetting->duplexType()) {
case NetworkManager::WiredSetting::UnknownDuplexType:
result.insert("duplexType", ConnectionSettingsEngine::DuplexUnknown);
break;
case NetworkManager::WiredSetting::Half:
result.insert("duplexType", ConnectionSettingsEngine::DuplexHalf);
break;
case NetworkManager::WiredSetting::Full:
result.insert("duplexType", ConnectionSettingsEngine::DuplexFull);
break;
}
result.insert("duplexMode", connWiredSetting->duplexType());
} else {
result.insert("autoLinkNegotiation", ConnectionSettingsEngine::NegotiationIgnore);
result.insert("linkSpeed", ConnectionSettingsEngine::SpeedUnknown);
result.insert("duplexMode", ConnectionSettingsEngine::DuplexUnknown);
}
} else if (!connWirelessSetting.isNull()) {
result.insert("clonedMacAddress", NetworkManager::macAddressAsString(connWirelessSetting->clonedMacAddress()));
result.insert("mtu", connWirelessSetting->mtu());
@ -155,6 +206,57 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
if (settings["mtu"].isValid()) {
connWiredSetting->setMtu(settings["mtu"].toUInt());
}
if (settings["autoLinkNegotiation"].isValid()) {
if (settings["autoLinkNegotiation"].toInt() == ConnectionSettingsEngine::NegotiationAutomatic) {
connWiredSetting->setAutoNegotiate(true);
connWiredSetting->setSpeed(0);
connWiredSetting->setDuplexType(NetworkManager::WiredSetting::UnknownDuplexType);
} else if (settings["autoLinkNegotiation"].toInt() == ConnectionSettingsEngine::NegotiationManual) {
connWiredSetting->setAutoNegotiate(false);
switch (settings["linkSpeed"].toInt()) {
case ConnectionSettingsEngine::Speed10Mbps:
connWiredSetting->setSpeed(10);
break;
case ConnectionSettingsEngine::Speed100Mbps:
connWiredSetting->setSpeed(100);
break;
case ConnectionSettingsEngine::Speed1Gbps:
connWiredSetting->setSpeed(1000);
break;
case ConnectionSettingsEngine::Speed2_5Gbps:
connWiredSetting->setSpeed(2500);
break;
case ConnectionSettingsEngine::Speed5Gbps:
connWiredSetting->setSpeed(5000);
break;
case ConnectionSettingsEngine::Speed10Gbps:
connWiredSetting->setSpeed(10000);
break;
case ConnectionSettingsEngine::Speed40Gbps:
connWiredSetting->setSpeed(40000);
break;
case ConnectionSettingsEngine::Speed100Gbps:
connWiredSetting->setSpeed(100000);
break;
}
switch (settings["duplexMode"].toInt()) {
case ConnectionSettingsEngine::DuplexUnknown:
connWiredSetting->setDuplexType(NetworkManager::WiredSetting::UnknownDuplexType);
break;
case ConnectionSettingsEngine::DuplexHalf:
connWiredSetting->setDuplexType(NetworkManager::WiredSetting::Half);
break;
case ConnectionSettingsEngine::DuplexFull:
connWiredSetting->setDuplexType(NetworkManager::WiredSetting::Full);
break;
}
} else {
connWiredSetting->setAutoNegotiate(false);
connWiredSetting->setSpeed(0);
connWiredSetting->setDuplexType(NetworkManager::WiredSetting::UnknownDuplexType);
}
}
} else if (!connWirelessSetting.isNull()) {
if (!wipeClonedMacAddress) {
connWirelessSetting->setClonedMacAddress(macBin);

@ -26,6 +26,7 @@ public:
};
enum LinkSpeed {
SpeedUnknown,
Speed10Mbps,
Speed100Mbps,
Speed1Gbps,
@ -36,6 +37,18 @@ public:
Speed100Gbps
};
enum LinkNegotiation {
NegotiationIgnore,
NegotiationAutomatic,
NegotiationManual
};
enum DuplexMode {
DuplexUnknown,
DuplexHalf,
DuplexFull
};
ConnectionSettingsEngine();
static QVariantMap readConnectionSettings(QString connUuidStr);

@ -7,8 +7,10 @@ EthernetSettingsTab::EthernetSettingsTab(QWidget *parent) :
{
ui->setupUi(this);
ui->clonedMacAddressLineEdit->setInputMask("HH:HH:HH:HH:HH:HH;_");
ui->speedComboBox->addItems(QStringList() << tr("10 Mb/s") << tr("100 Mb/s") << tr("1 Gb/s") << tr("2.5 Gb/s") << tr("10 Gb/s") << tr("40 Gb/s") << tr("100 Gb/s"));
ui->speedComboBox->addItems(QStringList() << tr("Unknown") << tr("10 Mb/s") << tr("100 Mb/s") << tr("1 Gb/s") << tr("2.5 Gb/s") << tr("10 Gb/s") << tr("40 Gb/s") << tr("100 Gb/s"));
ui->linkNegotiationComboBox->addItems(QStringList() << tr("Ignore") << tr("Automatic") << tr("Manual"));
ui->duplexComboBox->addItems(QStringList() << tr("Unknown") << tr("Half") << tr("Full"));
connect(ui->linkNegotiationComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EthernetSettingsTab::onLinkNegotiationChanged);
}
EthernetSettingsTab::~EthernetSettingsTab()
@ -24,35 +26,48 @@ QVariantMap EthernetSettingsTab::readSettings()
output.insert("device", QVariant(ui->deviceComboBox->currentText()));
output.insert("clonedMacAddress", QVariant(ui->clonedMacAddressLineEdit->text()));
output.insert("mtu", QVariant(ui->mtuSpinBox->value()));
output.insert("linkNegotiation", QVariant(ui->linkNegotiationComboBox->currentText()));
switch(ui->speedComboBox->currentIndex()) {
output.insert("autoLinkNegotiation", ConnectionSettingsEngine::LinkNegotiation(ui->linkNegotiationComboBox->currentIndex()));
switch (ui->speedComboBox->currentIndex()) {
case 0:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed10Mbps);
output.insert("linkSpeed", ConnectionSettingsEngine::SpeedUnknown);
break;
case 1:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed100Mbps);
output.insert("linkSpeed", ConnectionSettingsEngine::Speed10Mbps);
break;
case 2:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed1Gbps);
output.insert("linkSpeed", ConnectionSettingsEngine::Speed100Mbps);
break;
case 3:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed2_5Gbps);
output.insert("linkSpeed", ConnectionSettingsEngine::Speed1Gbps);
break;
case 4:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed5Gbps);
output.insert("linkSpeed", ConnectionSettingsEngine::Speed2_5Gbps);
break;
case 5:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed10Gbps);
output.insert("linkSpeed", ConnectionSettingsEngine::Speed5Gbps);
break;
case 6:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed40Gbps);
output.insert("linkSpeed", ConnectionSettingsEngine::Speed10Gbps);
break;
case 7:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed40Gbps);
break;
case 8:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed100Gbps);
break;
}
output.insert("speedMbps", QVariant(ui->speedComboBox->currentData()));
output.insert("duplexMode", QVariant(ui->duplexComboBox->currentText()));
switch (ui->duplexComboBox->currentIndex()) {
case 0:
output.insert("duplexMode", ConnectionSettingsEngine::DuplexUnknown);
break;
case 1:
output.insert("duplexMode", ConnectionSettingsEngine::DuplexHalf);
break;
case 2:
output.insert("duplexMode", ConnectionSettingsEngine::DuplexFull);
break;
}
return output;
}
@ -67,38 +82,28 @@ void EthernetSettingsTab::loadSettings(QVariantMap settings)
if (settings["mtu"].isValid()) {
ui->mtuSpinBox->setValue(settings["mtu"].toInt());
}
if (settings["linkNegotiation"].isValid()) {
ui->linkNegotiationComboBox->setCurrentText(settings["linkNegotiation"].toString());
if (settings["autoLinkNegotiation"].isValid()) {
ui->linkNegotiationComboBox->setCurrentIndex(settings["autoLinkNegotiation"].toInt());
onLinkNegotiationChanged(settings["autoLinkNegotiation"].toInt());
}
if (settings["linkSpeed"].isValid()) {
switch(settings["linkSpeed"].toInt()) {
case ConnectionSettingsEngine::Speed10Mbps:
ui->speedComboBox->setCurrentIndex(0);
break;
case ConnectionSettingsEngine::Speed100Mbps:
ui->speedComboBox->setCurrentIndex(1);
break;
case ConnectionSettingsEngine::Speed1Gbps:
ui->speedComboBox->setCurrentIndex(2);
break;
case ConnectionSettingsEngine::Speed2_5Gbps:
ui->speedComboBox->setCurrentIndex(3);
break;
case ConnectionSettingsEngine::Speed5Gbps:
ui->speedComboBox->setCurrentIndex(4);
break;
case ConnectionSettingsEngine::Speed10Gbps:
ui->speedComboBox->setCurrentIndex(5);
break;
case ConnectionSettingsEngine::Speed40Gbps:
ui->speedComboBox->setCurrentIndex(6);
break;
case ConnectionSettingsEngine::Speed100Gbps:
ui->speedComboBox->setCurrentIndex(7);
break;
}
ui->speedComboBox->setCurrentIndex(settings["linkSpeed"].toInt());
}
if (settings["duplexMode"].isValid()) {
ui->duplexComboBox->setCurrentText(settings["duplexMode"].toString());
ui->duplexComboBox->setCurrentIndex(settings["duplexMode"].toInt());
}
}
void EthernetSettingsTab::onLinkNegotiationChanged(int index)
{
switch (index) {
case 0:
case 1:
ui->speedComboBox->setEnabled(false);
ui->duplexComboBox->setEnabled(false);
break;
case 2:
ui->speedComboBox->setEnabled(true);
ui->duplexComboBox->setEnabled(true);
}
}

@ -19,6 +19,9 @@ public:
QVariantMap readSettings();
void loadSettings(QVariantMap settings);
private slots:
void onLinkNegotiationChanged(int index);
private:
Ui::EthernetSettingsTab *ui;
};

Loading…
Cancel
Save