Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirmwareUpdater - configurable IPs #679

Merged
merged 1 commit into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 73 additions & 9 deletions src/tools/FirmwareUpdater/firmwareupdatercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; t<sensorSetConfig.size(); ++t){
Expand All @@ -38,15 +68,49 @@ bool FirmwareUpdaterCore::init(Searchable& config, int port, QString address, in
QString line = QString("%1").arg(sensorConfig.get(1).asString().c_str());
if(verbosity>0) qDebug() << type << "-" << line;


bool ok;
int num = QString("%1").arg(line).toInt(&ok);
if(ok){
devices.append(QPair<QString,QVariant>(type,num));
}else{
devices.append(QPair<QString,QVariant>(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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/tools/FirmwareUpdater/firmwareupdatercore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString,QVariant> > devices;
Expand All @@ -71,6 +72,7 @@ class FirmwareUpdaterCore : public QObject
int currentId;
QList <sBoard> canBoards;
int verbosity;
eOipv4addr_t hostIPaddress;

signals:
void updateProgress(float);
Expand Down
14 changes: 5 additions & 9 deletions src/tools/ethLoader/ethLoaderLib/EthMaintainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ ACE_UINT32 ipv4toace(eOipv4addr_t ipv4)
{
return ntohl(ipv4);
}


#if defined(WIN32)

#else
Expand Down Expand Up @@ -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)
Expand Down