8#include <QRegularExpression>
17 for (
int i = 0; i < 16; ++i) {
29 Q_IPV6ADDR tmp = address.toIPv6Address();
32 for (
int i = 0; i < 16; ++i) {
36 return assembledAddress;
43 for (
int i = 0; i < ba.
size(); ++i) {
59 for (
const QString &macPart : macStringList) {
60 ba[i++] = macPart.
toUInt(
nullptr, 16);
66bool NetworkManager::macAddressIsValid(
const QString &macAddress)
68 const static QRegularExpression macAddressCheck(QStringLiteral(
"([a-fA-F0-9][a-fA-F0-9]:){5}[0-9a-fA-F][0-9a-fA-F]"));
69 return macAddressCheck.match(macAddress).hasMatch();
72bool NetworkManager::macAddressIsValid(
const QByteArray &macAddress)
84 while (i < bFreqs.
size()) {
85 if (bFreqs.
at(i).second <= freq) {
86 channel = bFreqs.
at(i).first;
97 while (i < aFreqs.
size()) {
98 if (aFreqs.
at(i).second <= freq) {
99 channel = aFreqs.
at(i).first;
100 if (aFreqs.
at(i).second == freq) {
112NetworkManager::WirelessSetting::FrequencyBand NetworkManager::findFrequencyBand(
int freq)
115 return WirelessSetting::Bg;
118 return WirelessSetting::A;
121bool NetworkManager::deviceSupportsApCiphers(NetworkManager::WirelessDevice::Capabilities interfaceCaps,
122 NetworkManager::AccessPoint::WpaFlags apCiphers,
123 WirelessSecurityType type)
125 bool havePair =
false;
126 bool haveGroup =
false;
128 if (type == NetworkManager::StaticWep) {
151 if (type != StaticWep) {
160 return (havePair && haveGroup);
164bool NetworkManager::securityIsValid(WirelessSecurityType type,
165 NetworkManager::WirelessDevice::Capabilities interfaceCaps,
168 NetworkManager::AccessPoint::Capabilities apCaps,
169 NetworkManager::AccessPoint::WpaFlags apWpa,
170 NetworkManager::AccessPoint::WpaFlags apRsn)
178 if (type == NoneSecurity) {
181 if ((type == StaticWep)
182 || ((type == DynamicWep) && !adhoc)
183 || ((type == Leap) && !adhoc)) {
217 if (apWpa || apRsn) {
231 if (apWpa || apRsn) {
232 if (!deviceSupportsApCiphers(interfaceCaps, apWpa, StaticWep)) {
233 if (!deviceSupportsApCiphers(interfaceCaps, apRsn, StaticWep)) {
249 if (!apWpa.
testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) {
252 if (!deviceSupportsApCiphers(interfaceCaps, apWpa, DynamicWep)) {
266 if (apWpa.
testFlag(NetworkManager::AccessPoint::KeyMgmtPsk)) {
267 if (apWpa.
testFlag(NetworkManager::AccessPoint::PairTkip)
271 if (apWpa.
testFlag(NetworkManager::AccessPoint::PairCcmp)
288 if (apRsn.
testFlag(NetworkManager::AccessPoint::PairCcmp)
293 if (apRsn.
testFlag(NetworkManager::AccessPoint::KeyMgmtPsk)) {
294 if (apRsn.
testFlag(NetworkManager::AccessPoint::PairTkip)
298 if (apRsn.
testFlag(NetworkManager::AccessPoint::PairCcmp)
315 if (!apWpa.
testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) {
319 if (!deviceSupportsApCiphers(interfaceCaps, apWpa, WpaEap)) {
332 if (!apRsn.
testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) {
336 if (!deviceSupportsApCiphers(interfaceCaps, apRsn, Wpa2Eap)) {
350 if (apRsn.
testFlag(NetworkManager::AccessPoint::PairCcmp)
355 if (apRsn.
testFlag(NetworkManager::AccessPoint::KeyMgmtSAE)) {
356 if (apRsn.
testFlag(NetworkManager::AccessPoint::PairTkip)
360 if (apRsn.
testFlag(NetworkManager::AccessPoint::PairCcmp)
377 if (!apRsn.
testFlag(NetworkManager::AccessPoint::KeyMgmtOWE)
378 && !apRsn.
testFlag(NetworkManager::AccessPoint::KeyMgmtOWETM)) {
390 if (haveAp && !apRsn.
testFlag(NetworkManager::AccessPoint::KeyMgmtEapSuiteB192)) {
402NetworkManager::WirelessSecurityType NetworkManager::findBestWirelessSecurity(NetworkManager::WirelessDevice::Capabilities interfaceCaps,
405 NetworkManager::AccessPoint::Capabilities apCaps,
406 NetworkManager::AccessPoint::WpaFlags apWpa,
407 NetworkManager::AccessPoint::WpaFlags apRsn)
415 NetworkManager::Wpa2Eap,
416 NetworkManager::Wpa2Psk,
417 NetworkManager::WpaEap,
418 NetworkManager::WpaPsk,
419 NetworkManager::StaticWep,
420 NetworkManager::DynamicWep,
421 NetworkManager::Leap,
423 NetworkManager::NoneSecurity};
425 for (NetworkManager::WirelessSecurityType type : types) {
426 if (NetworkManager::securityIsValid(type, interfaceCaps, haveAp, adHoc, apCaps, apWpa, apRsn)) {
430 return NetworkManager::UnknownSecurity;
433bool NetworkManager::wepKeyIsValid(
const QString &key, NetworkManager::WirelessSecuritySetting::WepKeyType type)
439 const int keylen = key.
length();
441 if (type != WirelessSecuritySetting::NotSpecified) {
442 if (type == WirelessSecuritySetting::Hex) {
443 if (keylen == 10 || keylen == 26) {
445 for (
int i = 0; i < keylen; ++i) {
446 if (!(key.
at(i).
isDigit() || (key.
at(i) >=
'A' && key.
at(i) <=
'F') || (key.
at(i) >=
'a' && key.
at(i) <=
'f'))) {
451 }
else if (keylen == 5 || keylen == 13) {
453 for (
int i = 0; i < keylen; ++i) {
462 }
else if (type == WirelessSecuritySetting::Passphrase) {
463 if (!keylen || keylen > 64) {
474bool NetworkManager::wpaPskIsValid(
const QString &psk)
480 const int psklen = psk.
length();
482 if (psklen < 8 || psklen > 64) {
488 for (
int i = 0; i < psklen; ++i) {
498NetworkManager::WirelessSecurityType NetworkManager::securityTypeFromConnectionSetting(
const NetworkManager::ConnectionSettings::Ptr &settings)
500 NetworkManager::WirelessSecuritySetting::Ptr wifiSecuritySetting = settings->setting(Setting::WirelessSecurity).dynamicCast<WirelessSecuritySetting>();
501 if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::Wep) {
503 }
else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::Ieee8021x) {
504 if (wifiSecuritySetting->authAlg() == WirelessSecuritySetting::Leap) {
509 }
else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::WpaPsk) {
510 if (wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Wpa) && !wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Rsn)) {
514 }
else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::WpaEap) {
515 if (wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Wpa) && !wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Rsn)) {
519 }
else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::SAE) {
521 }
else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::WpaEapSuiteB192) {
522 return Wpa3SuiteB192;
532 freqs.
append(QPair<int, int>(1, 2412));
533 freqs.
append(QPair<int, int>(2, 2417));
534 freqs.
append(QPair<int, int>(3, 2422));
535 freqs.
append(QPair<int, int>(4, 2427));
536 freqs.
append(QPair<int, int>(5, 2432));
537 freqs.
append(QPair<int, int>(6, 2437));
538 freqs.
append(QPair<int, int>(7, 2442));
539 freqs.
append(QPair<int, int>(8, 2447));
540 freqs.
append(QPair<int, int>(9, 2452));
541 freqs.
append(QPair<int, int>(10, 2457));
542 freqs.
append(QPair<int, int>(11, 2462));
543 freqs.
append(QPair<int, int>(12, 2467));
544 freqs.
append(QPair<int, int>(13, 2472));
545 freqs.
append(QPair<int, int>(14, 2484));
554 freqs.
append(QPair<int, int>(7, 5035));
555 freqs.
append(QPair<int, int>(8, 5040));
556 freqs.
append(QPair<int, int>(9, 5045));
557 freqs.
append(QPair<int, int>(11, 5055));
558 freqs.
append(QPair<int, int>(12, 5060));
559 freqs.
append(QPair<int, int>(16, 5080));
560 freqs.
append(QPair<int, int>(34, 5170));
561 freqs.
append(QPair<int, int>(36, 5180));
562 freqs.
append(QPair<int, int>(38, 5190));
563 freqs.
append(QPair<int, int>(40, 5200));
564 freqs.
append(QPair<int, int>(42, 5210));
565 freqs.
append(QPair<int, int>(44, 5220));
566 freqs.
append(QPair<int, int>(46, 5230));
567 freqs.
append(QPair<int, int>(48, 5240));
568 freqs.
append(QPair<int, int>(52, 5260));
569 freqs.
append(QPair<int, int>(56, 5280));
570 freqs.
append(QPair<int, int>(60, 5300));
571 freqs.
append(QPair<int, int>(64, 5320));
572 freqs.
append(QPair<int, int>(100, 5500));
573 freqs.
append(QPair<int, int>(104, 5520));
574 freqs.
append(QPair<int, int>(108, 5540));
575 freqs.
append(QPair<int, int>(112, 5560));
576 freqs.
append(QPair<int, int>(116, 5580));
577 freqs.
append(QPair<int, int>(120, 5600));
578 freqs.
append(QPair<int, int>(124, 5620));
579 freqs.
append(QPair<int, int>(128, 5640));
580 freqs.
append(QPair<int, int>(132, 5660));
581 freqs.
append(QPair<int, int>(136, 5680));
582 freqs.
append(QPair<int, int>(140, 5700));
583 freqs.
append(QPair<int, int>(149, 5745));
584 freqs.
append(QPair<int, int>(153, 5765));
585 freqs.
append(QPair<int, int>(157, 5785));
586 freqs.
append(QPair<int, int>(161, 5805));
587 freqs.
append(QPair<int, int>(165, 5825));
588 freqs.
append(QPair<int, int>(183, 4915));
589 freqs.
append(QPair<int, int>(184, 4920));
590 freqs.
append(QPair<int, int>(185, 4925));
591 freqs.
append(QPair<int, int>(187, 4935));
592 freqs.
append(QPair<int, int>(188, 4940));
593 freqs.
append(QPair<int, int>(189, 4945));
594 freqs.
append(QPair<int, int>(192, 4960));
595 freqs.
append(QPair<int, int>(196, 4980));
600QDateTime NetworkManager::clockBootTimeToDateTime(qlonglong clockBootime)
602 clockid_t clk_id = CLOCK_BOOTTIME;
609 r = clock_gettime(clk_id, &tp);
610 if (r == -1 && errno == EINVAL) {
611 clk_id = CLOCK_MONOTONIC;
612 r = clock_gettime(clk_id, &tp);
616 long now_msecs = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
620 if (clockBootime > now_msecs) {
621 qlonglong offset = clockBootime - now_msecs;
624 qlonglong offset = now_msecs - clockBootime;
@ Privacy
Access point supports privacy measures.
@ Rsn
RSN authethication protocol.
@ Ccmp
CCMP encryption cipher.
@ Wep104
104 bit WEP cipher
@ Tkip
TKIP encryption cipher.
@ IBSSRsn
device supports WPA2/RSN in an IBSS network
@ Wpa
WPA authentication protocol.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
NETWORKMANAGERQT_EXPORT int findChannel(int freq)
NETWORKMANAGERQT_EXPORT QByteArray ipv6AddressFromHostAddress(const QHostAddress &address)
NETWORKMANAGERQT_EXPORT QByteArray macAddressFromString(const QString &s)
NETWORKMANAGERQT_EXPORT QString macAddressAsString(const QByteArray &ba)
NETWORKMANAGERQT_EXPORT QHostAddress ipv6AddressAsHostAddress(const QByteArray &address)
void push_back(QByteArrayView str)
void reserve(qsizetype size)
void resize(qsizetype newSize, char c)
qsizetype size() const const
uint toUInt(bool *ok, int base) const const
bool isDigit(char32_t ucs4)
bool isLetterOrNumber(char32_t ucs4)
bool isPrint(char32_t ucs4)
QDateTime currentDateTime()
QDateTime fromMSecsSinceEpoch(qint64 msecs)
qint64 toMSecsSinceEpoch() const const
bool testFlag(Enum flag) const const
int protocol() const const
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
qsizetype size() const const
QString arg(Args &&... args) const const
const QChar at(qsizetype position) const const
bool isEmpty() const const
qsizetype length() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString toUpper() const const
QString join(QChar separator) const const