Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019 ~ 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -9,12 +9,14 @@
#include <QMap>
#include <QFile>
#include <QProcess>
#include <QCryptographicHash>

Check warning on line 12 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCryptographicHash> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 12 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QCryptographicHash> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QRegularExpression>

Check warning on line 13 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QRegularExpression> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 13 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QRegularExpression> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 14 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 14 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFileInfo>

Check warning on line 15 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDir>

Check warning on line 16 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 16 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <net/if.h>

Check warning on line 18 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <net/if.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 18 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <net/if.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <sys/ioctl.h>

Check warning on line 19 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sys/ioctl.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 19 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enableutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <sys/ioctl.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <unistd.h>

#define LEAST_NUM 10
Expand Down Expand Up @@ -140,7 +142,7 @@

bool EnableUtils::ioctlOperateNetworkLogicalName(const QString &logicalName, bool enable)
{
if (logicalName.startsWith("wlan") || logicalName.startsWith("wlp")) { // Wireless LAN
if (isWireless(logicalName)) { // Wireless LAN
// 第一步:获取 wiphy 编号
QProcess iwProcess;
iwProcess.start("iw", QStringList() << "dev" << logicalName << "info");
Expand All @@ -157,17 +159,30 @@
QString phyNum = wiphyMatch.captured(1);

// 第二步:获取 rfkill 设备编号
QProcess rfkillListProcess;
rfkillListProcess.start("rfkill", QStringList() << "list");
rfkillListProcess.waitForFinished();
QString rfkillOutput = QString::fromUtf8(rfkillListProcess.readAllStandardOutput());

// 查找对应的 rfkill 编号
QRegularExpression rfkillRe("^(\\d+):.*\\n.*\\n.*phy" + phyNum);
QRegularExpressionMatch rfkillMatch = rfkillRe.match(rfkillOutput);
QString rfkillId;
if (rfkillMatch.hasMatch()) {
rfkillId = rfkillMatch.captured(1);
QString phyPath = QString("/sys/class/ieee80211/phy%1").arg(phyNum);
QDir phyDir(phyPath);
if (!phyDir.exists()) {
qCritical() << "Phy path does not exist:" << phyPath;
return false;
}

// 查找 rfkill 目录
QStringList rfkillDirs = phyDir.entryList(QStringList() << "rfkill*", QDir::Dirs);
if (rfkillDirs.isEmpty()) {
qCritical() << "No rfkill directory found unbder" << phyPath;
return false;
}

// 读取 index 文件
QString rfkillIndexPath = phyPath + "/" + rfkillDirs.first() + "/index";
QFile indexFile(rfkillIndexPath);
if (indexFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
rfkillId = indexFile.readLine().trimmed();
indexFile.close();
} else {
qCritical() << "Failded to read rfkill index from" << rfkillIndexPath;
return false;
}

// 第三步:执行 rfkill block/unblock
Expand All @@ -179,6 +194,8 @@
if (ret != 0) {
qCritical() << "Failed to block/unblock wifi: error code: " << ret;
}
} else {
qCritical() << "Empty rfkill ID";
}

// 第四步:执行 ifconfig up/down
Expand Down Expand Up @@ -252,3 +269,13 @@

return true;
}

bool EnableUtils::isWireless(const QString &logicalName)
{
QFileInfo wirelessInfo(QString("/sys/class/net/%1/wireless").arg(logicalName));
QFileInfo phyInfo(QString("/sys/class/net/%1/phy80211").arg(logicalName));
if (wirelessInfo.exists() || phyInfo.exists())
return true;
else
return false;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019 ~ 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -39,6 +39,9 @@ class EnableUtils
* @return
*/
static bool getMapInfo(const QString &item, QMap<QString, QString> &mapInfo);

private:
static bool isWireless(const QString &logicalName);
};

#endif // ENABLEUTILS_H
Loading