summaryrefslogtreecommitdiffstats
path: root/src/networkdiscovery.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/networkdiscovery.cpp')
-rw-r--r--src/networkdiscovery.cpp135
1 files changed, 92 insertions, 43 deletions
diff --git a/src/networkdiscovery.cpp b/src/networkdiscovery.cpp
index da2cb1d..94d1f63 100644
--- a/src/networkdiscovery.cpp
+++ b/src/networkdiscovery.cpp
@@ -73,7 +73,7 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
if (!_server->listen(serverPath)) {
// emit signal to the gui that a critial error occoured
- qDebug() << _tag << "Unable to start server: "
+ qxtLog->debug() << _tag << "Unable to start server: "
<< _server->errorString();
emit
abortBoot("Unable to start server: " + _server->errorString());
@@ -83,8 +83,8 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
// check if the path to the customdhcpcd file is correct
QFileInfo fInfo(_pathToDhcpcdExe);
if (!fInfo.exists()) {
- qDebug() << _tag
- << "could not find customdhcpcd exe. Please check the path to this file.";
+ qxtLog->debug() << _tag
+ << " could not find customdhcpcd exe. Please check the path to this file.";
emit abortBoot(
"could not find customdhcpcd exe. Please check the path to this file.");
return;
@@ -94,21 +94,27 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun()));
if (args != NULL && !args->isEmpty()) {
- qDebug() << _tag << "added additional args";
+ qxtLog->debug() << _tag << "added additional args";
_dhcpcdArguments.append(*args);
}
// start the main work:
if (_autoUp) {
+ qxtLog->debug() << _tag << " call getListOfNetworkInterfacesWithAutoUp ...";
getListOfNetworkInterfacesWithAutoUp();
- _timer = new QTimer(this);
- connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning()));
- _timer->start(1000);
+ qxtLog->debug() << _tag << " ifUpList size: " << _ifUpList.size();
+ qxtLog->debug() << _tag << " ifDownList size: " << _ifDownList.size();
} else {
+ qxtLog->debug() << _tag << " call getListOfNetworkInterfaces ...";
getListOfNetworkInterfaces();
- emit readyForRun();
}
+
+ qxtLog->debug() << _tag << " init timer ...";
+ _timer = new QTimer(this);
+ qxtLog->debug() << _tag << " call checkForIsRunning ...";
+ connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning()));
+ _timer->start(1000);
}
@@ -122,12 +128,13 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
void NetworkDiscovery::slotReadyForRun() {
if (_ifUpList.size() > 0) {
foreach(QString i, _ifUpList) {
+ qxtLog->debug() << _tag << "emit addInterface: " << i;
emit addInterface(i);
}
_numberOfProcesses = _ifUpList.size();
runDHCPCD( _ifUpList);
} else {
- qDebug() << _tag << "list is empty. Have not found usable interface.";
+ qxtLog->debug() << _tag << "list is empty. Have not found usable interface.";
emit
abortBoot("Have not found usable interface");
return;
@@ -204,10 +211,10 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) {
"/etc/",
dns);
- qDebug() << _tag << "set man conf. and check connectivity";
+ qxtLog->debug() << _tag << "set man conf. and check connectivity";
if (!checkConnectivityViaTcp(_serverIp)) {
- qDebug() << _tag << "no connectivity. reset conf.";
+ qxtLog->debug() << _tag << "no connectivity. reset conf.";
interfaceconfiguration * ifc = _ifcMap.value(result["ifname"].toString(), NULL);
if(ifc != NULL) {
dns.clear();
@@ -269,6 +276,13 @@ QString NetworkDiscovery::readLogFile() {
+/**/
+void NetworkDiscovery::tryAgain() {
+
+}
+
+
+
/**
* ================================================================================
********************************* Private Methods ********************************
@@ -289,6 +303,23 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
if (nIList.size() > 0) {
foreach(QNetworkInterface nI, nIList)
{
+ qxtLog->debug() << _tag << "found Interface:" << nI.humanReadableName();
+ if ((nI.flags() & QNetworkInterface::CanBroadcast)) {
+ qxtLog->debug() << _tag << "flags: can broadcast";
+ }
+ if ((nI.flags() & QNetworkInterface::IsLoopBack)) {
+ qxtLog->debug() << _tag << "flags: is LoopBack";
+ }
+ if ((nI.flags() & QNetworkInterface::IsPointToPoint)) {
+ qxtLog->debug() << _tag << "flags: is Point to Point";
+ }
+ if ((nI.flags() & QNetworkInterface::IsRunning)) {
+ qxtLog->debug() << _tag << "flags: is Running";
+ }
+ if ((nI.flags() & QNetworkInterface::IsUp)) {
+ qxtLog->debug() << _tag << "flags: is Up";
+ }
+
if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
|| nI.flags() & QNetworkInterface::IsLoopBack)
|| nI.flags() & QNetworkInterface::IsPointToPoint)
@@ -300,12 +331,15 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
}
else if (!(nI.flags() & QNetworkInterface::IsUp)) {
_networkManager.bringInterfaceUP(nI.humanReadableName());
- qDebug() << _tag << " bring up ..";
+ qxtLog->debug() << _tag << " bring up ..";
+ _ifDownList.append(nI.humanReadableName());
+ }
+ else if (!(nI.flags() & QNetworkInterface::IsRunning)) {
_ifDownList.append(nI.humanReadableName());
}
}
} else {
- qDebug() << _tag << "no interfaces found!";
+ qxtLog->debug() << _tag << "no interfaces found!";
}
}
@@ -321,18 +355,22 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
if (nIList.size() > 0) {
foreach(QNetworkInterface nI, nIList)
{
+ qxtLog->debug() << _tag << "found Interface:" << nI.humanReadableName();
if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
|| nI.flags() & QNetworkInterface::IsLoopBack)
|| nI.flags() & QNetworkInterface::IsPointToPoint)
|| !(nI.flags() & QNetworkInterface::IsUp)
- || !(nI.flags() & QNetworkInterface::IsRunning)
|| checkBlackList(nI.humanReadableName())) {
continue;
}
- _ifUpList.append(nI.humanReadableName());
+ if (!(nI.flags() & QNetworkInterface::IsRunning)) {
+ _ifDownList.append(nI.humanReadableName())
+ } else {
+ _ifUpList.append(nI.humanReadableName());
+ }
}
} else {
- qDebug() << _tag << "no interfaces found!";
+ qxtLog->debug() << _tag << "no interfaces found!";
}
}
@@ -348,7 +386,7 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
*/
bool NetworkDiscovery::checkCarrierState(QString interface) {
- qDebug() << _tag << "check carrier state for interface " << interface;
+ qxtLog->debug() << _tag << "check carrier state for interface " << interface;
QByteArray ba = interface.toAscii();
const char * iface = ba.data();
@@ -365,21 +403,21 @@ bool NetworkDiscovery::checkCarrierState(QString interface) {
int v = value.toInt(pok);
if (*pok) {
if (v == 1) {
- qDebug()
+ qxtLog->debug()
<< "carrier is 1. Cable is plugged. return true";
return true;
} else {
- qDebug()
+ qxtLog->debug()
<< "carrier is 0. Cable is unplugged. return false";
return false;
}
} else {
- qDebug() << _tag << "conversion error";
+ qxtLog->debug() << _tag << "conversion error";
}
}
}
} else {
- qDebug() << _tag << "attrlist is Null";
+ qxtLog->debug() << _tag << "attrlist is Null";
}
sysfs_close_class_device(class_device);
@@ -414,7 +452,7 @@ void NetworkDiscovery::runDHCPCD(QString interface) {
_dhcpcdArguments.append(interface);
QProcess * p = new QProcess(this);
- qDebug() << _tag << _dhcpcdArguments;
+ qxtLog->debug() << _tag << _dhcpcdArguments;
_clientProcessToIfNameMap.insert(p, interface);
p->start(_pathToDhcpcdExe, _dhcpcdArguments);
@@ -451,12 +489,12 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) {
_ifcMap.insert(ifName, ifConf);
// replace default route
- qDebug() << _tag << "replace default route";
+ qxtLog->debug() << _tag << "replace default route";
_networkManager.replaceDefaultRoute(ifName,
ifConf->getGateway(), mss, AF_INET);
if (checkConnectivityViaTcp(_serverIp)) {
- qDebug() << _tag << "internet: check passed! for interface" << ifName;
+ qxtLog->debug() << _tag << "internet: check passed! for interface" << ifName;
emit
updateStatusLabel(ifName, "connection possible");
if (!_userChoice) {
@@ -469,7 +507,7 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) {
}
return true;
} else {
- qDebug() << _tag << "no internet connection with interface" << ifName;
+ qxtLog->debug() << _tag << "no internet connection with interface" << ifName;
emit
updateStatusLabel(ifName, "connection not possible");
return false;
@@ -493,7 +531,7 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
QTcpSocket *tcpSocket = new QTcpSocket(this);
tcpSocket->connectToHost(server, 80);
if (!tcpSocket->waitForConnected(500)) {
- qDebug() << _tag << tcpSocket->errorString();
+ qxtLog->debug() << _tag << tcpSocket->errorString();
return false;
} else {
return true;
@@ -507,7 +545,7 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
* connects the client readyRead signal with the handleNewInput slot.
*/
void NetworkDiscovery::handleNewConnection() {
- qDebug() << _tag << "New Connection arrived";
+ qxtLog->debug() << _tag << "New Connection arrived";
/*QLocalSocket **/
_client = _server ->nextPendingConnection();
@@ -527,7 +565,7 @@ void NetworkDiscovery::handleClientDisconnect() {
QLocalSocket * client = _clients.value(socket);
- qDebug() << _tag << "disconnect client";
+ qxtLog->debug() << _tag << "disconnect client";
handleNewInput(client);
client->deleteLater();
}
@@ -541,12 +579,12 @@ void NetworkDiscovery::handleClientDisconnect() {
* a client
*/
void NetworkDiscovery::handleNewInput(QLocalSocket * client) {
- qDebug() << _tag << "last read before exit";
+ qxtLog->debug() << _tag << "last read before exit";
while (client->canReadLine()) {
QString data(client->readLine());
data = data.trimmed();
- qDebug() << _tag << data;
+ qxtLog->debug() << _tag << data;
QStringList lines = data.split("\n");
for (int i = 0; i < lines.length(); i++) {
@@ -570,7 +608,7 @@ void NetworkDiscovery::handleNewInput() {
client->write("ACK", ACK_SIZE);
client->waitForBytesWritten();
data = data.trimmed();
- //qDebug() << _tag << data;
+ //qxtLog->debug() << _tag << data;
QStringList lines = data.split("\n");
for (int i = 0; i < lines.length(); i++) {
@@ -609,7 +647,7 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
QString msg = logMsg.section(";", 3, 3);
int st = s_state.trimmed().toInt();
int sst = s_subState.trimmed().toInt();
- //qDebug() << _tag << logMsg;
+ //qxtLog->debug() << _tag << logMsg;
if (_ifNameToClient.size() < _numberOfProcesses && !_ifNameToClient.contains(
interface)) {
@@ -621,21 +659,27 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
switch (sst) {
case DHCP_DISCOVER:
emit changeProgressBarValue(interface, 10);
+ qxtLog->debug() << _tag << " " << interface << " send discover";
break;
case DHCP_OFFER:
emit changeProgressBarValue(interface, 20);
+ qxtLog->debug() << _tag << " " << interface << " got offer";
break;
case DHCP_REQUEST:
emit changeProgressBarValue(interface, 30);
+ qxtLog->debug() << _tag << " " << interface << " send request";
break;
case DHCP_ACK:
emit changeProgressBarValue(interface, 40);
+ qxtLog->debug() << _tag << " " << interface << " ack";
break;
case DHCP_NAK:
emit changeProgressBarValue(interface, 40);
+ qxtLog->debug() << _tag << " " << interface << " nak";
break;
case DHCPCD_ARP_TEST:
emit changeProgressBarValue(interface, 50);
+ qxtLog->debug() << _tag << " " << interface << " do arp test";
break;
case DHCP_DECLINE:
emit changeProgressBarValue(interface, 60);
@@ -647,24 +691,28 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
break;
case DHCPCD_CONFIGURE:
emit changeProgressBarValue(interface, 70);
+ qxtLog->debug() << _tag << " " << interface << " do configure interface";
break;
case DHCPCD_WRITE:
emit changeProgressBarValue(interface, 80);
+ qxtLog->debug() << _tag << " " << interface << " write conf file";
break;
case DHCPCD_EXIT:
emit changeProgressBarValue(interface, 100);
+ qxtLog->debug() << _tag << " " << interface << " exiting";
break;
case DHCPCD_LOG:
default:
+ qxtLog->debug() << _tag << " received error:" << msg;
break;
}
break;
case LOG_ERR:
- qDebug() << _tag << "received error:" << msg;
+ qxtLog->debug() << _tag << " received error:" << msg;
break;
default:
- //qDebug() << _tag << logMsg;
+ qxtLog->debug() << _tag << logMsg;
break;
}
}
@@ -704,17 +752,18 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
QProcess* p = qobject_cast<QProcess *> (QObject::sender());
QString ifName = _clientProcessToIfNameMap.value(p, "ifName");
+ _numberOfProcesses = _numberOfProcesses - 1;
if (!_blocked) { //_blocked becomes true, if _userChoice is false and we already found a usable interface
if (ifName.compare("ifName") == 0) {
- qDebug() << _tag << "--- \t [NetworkDiscovery::handleProcessFinished] haven't found process!";
+ qxtLog->debug() << _tag << "--- \t [NetworkDiscovery::handleProcessFinished] haven't found process!";
} else {
- qDebug() << _tag << "process for interface" << ifName << "finished"
- << exitCode << exitStatus;
+ qxtLog->debug() << _tag << " process for interface " << ifName << " finished "
+ << " exit code: " << exitCode << " exit status " << exitStatus;
if (exitCode > 0) {
- qDebug() << _tag << "process exited unexpected";
+ qxtLog->debug() << _tag << "process exited unexpected";
emit updateStatusLabel(ifName, "process exited unexpected");
} else {
- qDebug() << _tag << "process normal exit";
+ qxtLog->debug() << _tag << "process normal exit";
emit changeProgressBarValue(ifName, 100);
emit updateStatusLabel(ifName, "check connectivity");
checkConnectivity(ifName);
@@ -725,13 +774,13 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
if (client != 0) {
handleNewInput(client);
}
- _numberOfProcesses = _numberOfProcesses - 1;
- if (_numberOfProcesses <= 0 && _userChoice) {
+ //_numberOfProcesses = _numberOfProcesses - 1; && _userChoice
+ if (_numberOfProcesses <= 0 ) {
emit allProcessesFinished();
}
}
} else {
- qDebug() << _tag << "already blocked";
+ qxtLog->debug() << _tag << "already blocked";
emit updateStatusLabel(ifName, "finished DHCP");
}
}
@@ -747,7 +796,7 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
void NetworkDiscovery::handleProcessStarted() {
QProcess* p = qobject_cast<QProcess *> (QObject::sender());
QString ifName = _clientProcessToIfNameMap.value(p, "ifName");
- qDebug() << _tag << "process started for interface:" << ifName;
+ qxtLog->debug() << _tag << "process started for interface:" << ifName;
}