summaryrefslogtreecommitdiffstats
path: root/src/wifi
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@theqtcompany.com>2015-02-09 10:37:24 +0100
committerGatis Paeglis <gatis.paeglis@theqtcompany.com>2015-02-09 13:27:41 +0200
commitb47a30f925ca83a6ffd7b7d1aefba3bebfbcfe79 (patch)
tree5c55a61c32db0f38aa76105bf7898f117558854b /src/wifi
parentcd677b247532305ca67b1459bafe74a19cead7ad (diff)
Pass "-D nl80211,wext" to supplicant by default
nl80211 is the current standard, but not all wireless chip's modules support it, wext is currently deprecated, but still widely supported. Supplicant will choose which of the these kernel interfaces to use for controlling a wireless driver on a specific device. This for example fixes the issue of QtWifi not working properly on a Nitrogen6_Max board with a wifi chip that comes on it by default. Change-Id: I6f24df7126e761bf196ec6ee76918a96d03307a5 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/wifi')
-rw-r--r--src/wifi/qwifielinux.cpp88
1 files changed, 49 insertions, 39 deletions
diff --git a/src/wifi/qwifielinux.cpp b/src/wifi/qwifielinux.cpp
index 0dc3a39..7584335 100644
--- a/src/wifi/qwifielinux.cpp
+++ b/src/wifi/qwifielinux.cpp
@@ -38,7 +38,6 @@ static struct wpa_ctrl *ctrl_conn;
static struct wpa_ctrl *monitor_conn;
// socket pair used to exit from a blocking read
static int exit_sockets[2];
-QByteArray ctrlInterface;
int wifi_connect_on_socket_path(const char *path);
int wifi_ctrl_recv(char *reply, size_t *reply_len);
@@ -46,12 +45,33 @@ int wifi_wait_on_socket(char *buf, size_t buflen);
int wifi_send_command(const char *cmd, char *reply, size_t *reply_len);
void wifi_close_sockets();
+QByteArray controlInterfacePath()
+{
+ QByteArray path;
+ QFile configFile;
+ configFile.setFileName(QLatin1String(SUPP_CONFIG_FILE));
+ if (configFile.open(QFile::ReadOnly)) {
+ while (!configFile.atEnd()) {
+ QByteArray line = configFile.readLine().trimmed();
+ if (line.startsWith("ctrl_interface")) {
+ path = line.mid(16);
+ if (path.isEmpty())
+ qCWarning(B2QT_WIFI) << "ctrl_interface is not set in " << SUPP_CONFIG_FILE;
+ break;
+ }
+ }
+ configFile.close();
+ } else {
+ qCWarning(B2QT_WIFI) << "could not find/read wpa_supplicant configuration file in" << SUPP_CONFIG_FILE;
+ }
+ return path;
+}
+
int q_wifi_start_supplicant()
{
- // #### TODO - if "/etc/wpa_supplicant/driver.$IFACE" exists, read driver name from there
QByteArray ifc = QWifiDevice::wifiInterfaceName();
- QString driver(QStringLiteral("wext"));
QString pidFile = QLatin1String("/var/run/wpa_supplicant." + ifc + ".pid");
+ QString driver(QStringLiteral("nl80211,wext"));
QStringList arg;
arg << QStringLiteral("--start") << QStringLiteral("--quiet") << QStringLiteral("--name");
@@ -64,33 +84,14 @@ int q_wifi_start_supplicant()
QProcess ssDaemon;
ssDaemon.start(QStringLiteral("start-stop-daemon"), arg);
ssDaemon.waitForFinished();
- if (ssDaemon.exitStatus() != QProcess::NormalExit && ssDaemon.exitCode() != 0) {
- qCWarning(B2QT_WIFI) << "failed to start a supplicant process!";
+
+ QByteArray path = controlInterfacePath();
+ if (path.isEmpty())
return -1;
- }
- QFile configFile;
- configFile.setFileName(QLatin1String(SUPP_CONFIG_FILE));
- if (configFile.exists() && configFile.open(QFile::ReadOnly)) {
- ctrlInterface.clear();
- while (!configFile.atEnd()) {
- QByteArray line = configFile.readLine().trimmed();
- if (line.startsWith("ctrl_interface")) {
- ctrlInterface = line.mid(16);
- break;
- }
- }
- configFile.close();
- if (!ctrlInterface.isEmpty()) {
- // if the interface socket exists, then wpa_supplicant was invoked successfully
- if (!QFile(QLatin1String(ctrlInterface + "/" + ifc)).exists())
- return -1;
- } else {
- qCWarning(B2QT_WIFI) << "ctrl_interface is not set in " << SUPP_CONFIG_FILE;
- return -1;
- }
- } else {
- qCWarning(B2QT_WIFI) << "could not find/read wpa_supplicant configuration file in" << SUPP_CONFIG_FILE;
+ // if the interface socket exists then wpa-supplicant was invoked successfully
+ if (!QFile(QLatin1String(path + "/" + ifc)).exists()) {
+ qCWarning(B2QT_WIFI) << "failed to invoke wpa_supplicant!\n" << ssDaemon.readAll();
return -1;
}
// reset sockets used for exiting from hung state
@@ -102,19 +103,28 @@ int q_wifi_stop_supplicant()
{
QByteArray ifc = QWifiDevice::wifiInterfaceName();
QString pidFile = QLatin1String("/var/run/wpa_supplicant." + ifc + ".pid");
- QStringList arg;
- arg << QStringLiteral("--stop") << QStringLiteral("--quiet") << QStringLiteral("--name");
- arg << QStringLiteral("wpa_supplicant") << QStringLiteral("--pidfile") << pidFile;
- QProcess ssDaemon;
- ssDaemon.start(QStringLiteral("start-stop-daemon"), arg);
- ssDaemon.waitForFinished();
- if (ssDaemon.exitStatus() != QProcess::NormalExit && ssDaemon.exitCode() != 0) {
- qCWarning(B2QT_WIFI) << "failed to stop a supplicant process!";
- return -1;
+
+ if (QFile(pidFile).exists()) {
+ QStringList arg;
+ arg << QStringLiteral("--stop") << QStringLiteral("--quiet") << QStringLiteral("--name");
+ arg << QStringLiteral("wpa_supplicant") << QStringLiteral("--pidfile") << pidFile;
+
+ QProcess ssDaemon;
+ ssDaemon.start(QStringLiteral("start-stop-daemon"), arg);
+ ssDaemon.waitForFinished();
+ if (ssDaemon.exitStatus() != QProcess::NormalExit) {
+ qCWarning(B2QT_WIFI) << "failed to stop a supplicant process!\n" << ssDaemon.readAll();;
+ return -1;
+ }
+
+ QByteArray path = controlInterfacePath();
+ if (path.isEmpty())
+ return -1;
+
+ QFile::remove(QLatin1String(path + "/" + ifc));
+ QFile::remove(pidFile);
}
- QFile::remove(QLatin1String(ctrlInterface + "/" + ifc));
- QFile::remove(pidFile);
return 0;
}