Index: CRLF.sh =================================================================== diff -u --- CRLF.sh (revision 0) +++ CRLF.sh (revision 2e97d4783dc34f6953c3602e607900bca26443ff) @@ -0,0 +1,3 @@ +#!/bin/sh +grep -nrl $'\r' --include='*.cpp' --include='*.h' --include='*.conf' --include='*.sh' . + Index: sources/wifi/WifiInterface.cpp =================================================================== diff -u -r4947841e8cdd7e72d4fe26e604f7e5061fb86d64 -r2e97d4783dc34f6953c3602e607900bca26443ff --- sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 4947841e8cdd7e72d4fe26e604f7e5061fb86d64) +++ sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 2e97d4783dc34f6953c3602e607900bca26443ff) @@ -256,7 +256,7 @@ LOG_DEBUG(QString("stderr: %1").arg(err)); _scanRunning = false; emit didScanStatusChanged(_scanRunning); - parseWifiScan(out); + parseWifiScanResult(out); LOG_DEBUG("WiFi Scan Finished"); } @@ -283,6 +283,151 @@ } /*! + * \brief Network::parseWifiScanResult + * \details Extract desired information from the WiFi scan output. Sorts by signal stength + * \param vResult - (QString) output collected from QProcess execution + * \return List of the Found SSIDs in a model. + */ +QList WifiInterface::parseWifiScanResult(const QString &vResult) +{ + enum SSIDInfo_Enum { + eSSID , + eBSSID , + eFREQ , + eRATE , + eSIGNAL , + eSECURITY , + eWPA_FLAGS , + eRSN_FLAGS , + eIN_USE , + }; + enum ValueUnit_Enum { + eValue , + eUnit , + eCount , + }; + + struct SSIDInfo { + QString mSSID ; + QString mBSSID ; + QString mFREQ_Max ; + QString mRATE_Max ; + quint16 mSIGNAL_Max ; + QString mSECURITY ; + QString mFLAGS ; // eWPA_FLAGS, eRSN_FLAGS are exclusive + bool mIN_USE = false ; + bool mSupported = true ; + QString toString() { + QStringList fields = QStringList() + << mSSID + << mBSSID + << mFREQ_Max + << mRATE_Max + << QString::number(mSIGNAL_Max) + << mSECURITY + << mFLAGS + << (mSupported ? "T" : "") + << (mIN_USE ? "T" : ""); + return fields.join(','); + } + }; + + QString mResult = vResult; + + SSIDInfo data; + QHash mSSIDInfoList; + + // the Freq, Rate units + QString mSSID; + const QString mFREQ_Unit = " MHz"; + const QString mRATE_Unit = " Mbit/s"; + quint32 mFREQ_Value = 0; + quint32 mRATE_Value = 0; + // Removing the units once from the result to accelerate parsing. (will be added when done) + mResult.remove(mFREQ_Unit); + mResult.remove(mRATE_Unit); + + QStringList lines = mResult.split('\n'); + for ( int row = 0; row < lines.count(); row++ ) { + QStringList fields = lines[row].split(','); + if ( fields[eSSID].trimmed().isEmpty() ) continue; // hidden networks, or an incorrect entry + + QString mWPA_FLAGS; + QString mRSN_FLAGS; + + for ( int index = 0; index < fields.count(); index++ ) { // the list has to be sorted and the script is written that way. + QString field = fields[index].trimmed(); + + if ( row ) { // if is not first row + if ( mSSID == fields[eSSID] ) { // if is the same SSID just update necessary fields + quint32 value = 0; + switch (index) { + case eFREQ : + value = QString("%1").arg(field).toInt(); + if ( mFREQ_Value < value ) { mFREQ_Value = value; } break; + case eRATE : + value = QString("%1").arg(field).toInt(); + if ( mRATE_Value < value ) { mRATE_Value = value; } break; + case eSIGNAL : + value = QString("%1").arg(field).toInt(); + if ( data.mSIGNAL_Max < value ) { data.mSIGNAL_Max = value; } break; + case eIN_USE : data.mIN_USE = field.contains("*"); break; + default: break; + } + } + else { // else add the previous one and continue to the next. + if ( ! mSSID.trimmed().isEmpty() ) { + data.mSSID = mSSID; + data.mFREQ_Max += QString::number(mFREQ_Value) + mFREQ_Unit; + data.mRATE_Max += QString::number(mRATE_Value) + mRATE_Unit; + mSSIDInfoList[mSSID] = data; + qDebug() << data.toString(); + } + // clean up / reset + data.mFREQ_Max = ""; + data.mRATE_Max = ""; + data.mFLAGS = ""; + } + } + + switch (index) { // DO NOT USE default in this switch + case eSSID : mSSID = field; break; + case eBSSID :/* data.mBSSID = field; */ break; // not directly used for now + case eFREQ : mFREQ_Value = QString("%1").arg(field).toInt(); break; + case eRATE : mRATE_Value = QString("%1").arg(field).toInt(); break; + case eSIGNAL : data.mSIGNAL_Max = QString("%1").arg(field).toInt(); break; + case eIN_USE : data.mIN_USE = field.contains("*"); break; + + case eSECURITY : + data.mSECURITY = field; + if ( field.isEmpty() ) { + data.mSupported = false; + } else { + data.mSupported = field.remove(QRegExp("(WPA[23])")).trimmed().isEmpty(); + } + break; + + case eWPA_FLAGS : + if ( field.contains("tkip") ) { mWPA_FLAGS += " TKIP" ; data.mSupported = false; } + if ( field.contains("ccmp") ) { mWPA_FLAGS += " AES" ; } + if ( ! mWPA_FLAGS.isEmpty() ) { data.mFLAGS = mWPA_FLAGS.trimmed(); } + break; + + case eRSN_FLAGS : + if ( field.contains("tkip") ) { mRSN_FLAGS += " TKIP" ; data.mSupported = false; } + if ( field.contains("ccmp") ) { mRSN_FLAGS += " AES" ; } + if ( field.contains("sae" ) ) { mRSN_FLAGS += " SAE" ; } + if ( ! mRSN_FLAGS.isEmpty() ) { data.mFLAGS = mRSN_FLAGS.trimmed(); } + break; + } + } + } + return {}; +} + + + +/*! * \brief Network::parseWifiScan * Extract desired information from the WiFi scan output. Sorts by signal stength * Index: sources/wifi/WifiInterface.h =================================================================== diff -u -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 -r2e97d4783dc34f6953c3602e607900bca26443ff --- sources/wifi/WifiInterface.h (.../WifiInterface.h) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) +++ sources/wifi/WifiInterface.h (.../WifiInterface.h) (revision 2e97d4783dc34f6953c3602e607900bca26443ff) @@ -90,6 +90,7 @@ bool checkScript(QString &vScript, const QString &vShellScript); QString getTextBetweenDelimiters(const QString &vText, const QString &vLeftDelim, const QString &vRightDelim); QList parseWifiScan(const QString &vOutput); + QList parseWifiScanResult(const QString &vResult); QString parseIP(const QString &vOutput); QString parseBroadcast(const QString &vOutput); QString parseSubnetMask(const QString &vOutput);