From 79553d52eec418bc2476acd8cf6241e28bb8f35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davide=20Tom=C3=A9?= Date: Tue, 8 Sep 2020 15:19:54 +0200 Subject: [PATCH] Fix/fw upd ip config (#1) * adding configurable ip address * wip * changing subnet tested - wip * small fix * fixed use of default ip * EthMaintanier - possible to set a board IP to 10.X.X.X * EthMaintanier - removed debug print --- .../FirmwareUpdater/firmwareupdatercore.cpp | 82 +++++++++++++++++-- .../FirmwareUpdater/firmwareupdatercore.h | 2 + .../ethLoader/ethLoaderLib/EthMaintainer.cpp | 14 ++-- 3 files changed, 80 insertions(+), 18 deletions(-) diff --git a/src/tools/FirmwareUpdater/firmwareupdatercore.cpp b/src/tools/FirmwareUpdater/firmwareupdatercore.cpp index a0f1d5a56b..931113bce4 100755 --- a/src/tools/FirmwareUpdater/firmwareupdatercore.cpp +++ b/src/tools/FirmwareUpdater/firmwareupdatercore.cpp @@ -10,6 +10,42 @@ static void updateProgressCallback(float fraction) self->updateProgress(fraction); } +// 09/2020 davide.tome@iit.it - address and port configurable in firmwareupdater.ini +bool FirmwareUpdaterCore::isValidIpAddress(QString addr) +{ + QStringList ipFields; + + ipFields = addr.split("."); + if(ipFields.count() == 4 && ipFields[3].contains(":")) + { + QString address_,port_; + int ipv0, ipv1, ipv2, ipv3; + + address_ = addr.split(":")[0]; + port_ = ipFields[3].split(":")[1]; + + QRegExp re("\\d*"); // a digit (\d), zero or more times (*) + if (!re.exactMatch(port_)) return false; + for(int k=0; k<4; k++) + { + if (!re.exactMatch(address_.split(".")[k])) return false; + } + + ipv0 = address_.split(".")[0].toInt(); + ipv1 = address_.split(".")[1].toInt(); + ipv2 = address_.split(".")[2].toInt(); + ipv3 = address_.split(".")[3].toInt(); + + if(ipv0 == 10 && 0 < ipv1 < 255 && 0 < ipv2 < 255 && 0 < ipv3 < 255 && 0 < port_.toInt() < 255) + { + hostIPaddress = EO_COMMON_IPV4ADDR(ipv0, ipv1, ipv2, ipv3); + return true; + } + else return false; + } + else return false; +} + FirmwareUpdaterCore::FirmwareUpdaterCore(QObject *parent) : QObject(parent), mutex(QMutex::Recursive) { self = this; @@ -18,17 +54,11 @@ FirmwareUpdaterCore::FirmwareUpdaterCore(QObject *parent) : QObject(parent), mut bool FirmwareUpdaterCore::init(Searchable& config, int port, QString address, int VerbositY) { verbosity = VerbositY; - + mutex.lock(); - if(!gMNT.open()){ - if(verbosity>0) qDebug("Can't open socket, aborting."); - mutex.unlock(); - return false; - } - + setVerbosity(verbosity); - Bottle sensorSetConfig=config.findGroup("DRIVERS").tail(); for (int t=0; t0) qDebug() << type << "-" << line; - bool ok; int num = QString("%1").arg(line).toInt(&ok); if(ok){ @@ -46,7 +75,42 @@ bool FirmwareUpdaterCore::init(Searchable& config, int port, QString address, in }else{ devices.append(QPair(type,line)); } + + + // 09/2020 davide.tome@iit.it - address and port configurable in firmwareupdater.ini + if(type == "ETH") { + + if(isValidIpAddress(line)) + { + port = line.split(":")[1].toInt(); + qDebug() << "IP address FOUND in .ini file, Using :" << line.split(":")[0]; + qDebug() << "Port Number FOUND in .ini file, Using :" << line.split(":")[1]; + } + else + { + int ipv0, ipv1, ipv2, ipv3; + + ipv0 = address.split(".")[0].toInt(); + ipv1 = address.split(".")[1].toInt(); + ipv2 = address.split(".")[2].toInt(); + ipv3 = address.split(".")[3].toInt(); + + hostIPaddress = EO_COMMON_IPV4ADDR(ipv0, ipv1, ipv2, ipv3); + + qDebug() << "Invalid IP address found in .ini file (format is 10.0.X.Y:Z , 0 < X,Y < 255 , Z port number)"; + qDebug() << "Skipped , using defaults!"; + } + } + } + + if(!gMNT.open(hostIPaddress, port)) + { + if(verbosity>0) qDebug("Can't open socket, aborting."); + mutex.unlock(); + return false; + } + mutex.unlock(); return true; } diff --git a/src/tools/FirmwareUpdater/firmwareupdatercore.h b/src/tools/FirmwareUpdater/firmwareupdatercore.h index e704f9d7e6..2eb16d0d89 100644 --- a/src/tools/FirmwareUpdater/firmwareupdatercore.h +++ b/src/tools/FirmwareUpdater/firmwareupdatercore.h @@ -59,6 +59,7 @@ class FirmwareUpdaterCore : public QObject private: bool compile_ip_addresses(const char* addr,unsigned int *remoteAddr,unsigned int *localAddr); + bool isValidIpAddress(QString addr); private: QList < QPair > devices; @@ -71,6 +72,7 @@ class FirmwareUpdaterCore : public QObject int currentId; QList canBoards; int verbosity; + eOipv4addr_t hostIPaddress; signals: void updateProgress(float); diff --git a/src/tools/ethLoader/ethLoaderLib/EthMaintainer.cpp b/src/tools/ethLoader/ethLoaderLib/EthMaintainer.cpp index 3067de982e..788236b9dd 100644 --- a/src/tools/ethLoader/ethLoaderLib/EthMaintainer.cpp +++ b/src/tools/ethLoader/ethLoaderLib/EthMaintainer.cpp @@ -60,6 +60,8 @@ ACE_UINT32 ipv4toace(eOipv4addr_t ipv4) { return ntohl(ipv4); } + + #if defined(WIN32) #else @@ -1932,18 +1934,12 @@ bool EthMaintainer::command_changeaddress(eOipv4addr_t ipv4, eOipv4addr_t ipv4ne stopit = true; } - // we must have 10.0.1.x, where x is not 0 or 255 - if((10 != command.address[0]) || (0 != command.address[1]) || (1 != command.address[2])) + // 09/2020 davide.tome@iit.it - possible to give 10.X.X.X IP address + if(!((10 == command.address[0]) || (0 < command.address[1] < 255) || (0 < command.address[2] < 255) || (0 < command.address[3] < 255))) { stopit = true; } - - if((0 == command.address[3]) || (255 == command.address[3])) - { - stopit = true; - } - - + if(true == stopit) { if(_verbose)