简体   繁体   English

SIOCGIWFREQ ioctl 返回错误 22 EINVAL - 无效参数,为什么?

[英]SIOCGIWFREQ ioctl returning error 22 EINVAL - Invalid argument, why?

I am struggling to read current frequency channel of Wifi card using Wireless Extension Tools for Linux library with following Qt/C++ method:我正在努力使用以下Qt/C++方法使用Linux 库的无线扩展工具读取 Wifi 卡的当前频率信道:

const UeTypeCurrentFrequencyChannel& UeNetworkManager::ueCurrentFrequencyChannel(const QString& interfaceName)
{
    static UeTypeCurrentFrequencyChannel result=UeTypeCurrentFrequencyChannel();
    iwreq wrq;
    iw_range range;
    int kernelSocket=iw_sockets_open();

    if(iw_get_range_info(kernelSocket,
                         interfaceName.toLocal8Bit().constData(),
                         &range)>=0)
    {
        if(iw_get_ext(kernelSocket,
                      interfaceName.toLocal8Bit().constData(),
                      SIOCGIWFREQ,
                      &wrq)>=0)
        {
            //BUG current frequency and channel is not read, it might be becuase of nonroot credentials - it returns error 22 (EINVAL - Invalid argument), why?
            result.first=iw_freq2float(&(wrq.u.freq));
            result.second=iw_freq_to_channel(result.first.toDouble(),
                                             &range);

            qDebug() << Q_FUNC_INFO
                     << "success - current channel:"
                     << result;
        }
        else
        {
            result.first=QString(interfaceName);
            result.second=QString(tr("current channel read failed."));

            qDebug() << Q_FUNC_INFO
                     << "error (iw_get_ext):"
                     << errno;
        }   // if
    }
    else
    {
        result.first=QString(interfaceName);
        result.second=QString(tr("current channel read failed."));

        qDebug() << Q_FUNC_INFO
                 << "error (iw_get_range_info):"
                 << errno;
    }   // if

    iw_sockets_close(kernelSocket);

    return result;
}   // ueCurrentFrequencyChannel

Now, iw_get_ext always returns -1 and errno is set to value of 22 .现在, iw_get_ext总是返回-1并且errno被设置为22值。 I've taken a look at the errno.h and search for error 22 and I've got following error declaration:我查看了errno.h并搜索了错误22 ,我得到了以下错误声明:
#define EINVAL 22 /* Invalid argument */ . #define EINVAL 22 /* Invalid argument */ .
Why am I getting Invalid argument error while trying to query current frequency channel of network adapter with ioctl ?为什么在尝试使用ioctl查询网络适配器的当前频道时出现Invalid argument错误? I've launched application containing this code as normal user and as root , same result any time:我以普通用户和 root身份启动了包含此代码的应用程序,任何时候结果都是一样的:

static const UeTypeCurrentFrequencyChannel& UeNetworkManager::ueCurrentFrequencyChannel(const QString&) error(iw_get_ext): 22

Why, what am I missing?为什么,我错过了什么?

Addendum #1:附录#1:
If I scan WiFi cards and networks using iwlist from terminal , I get all needed info, regardless if I run it as normal user or root .如果我使用iwlist从终端扫描 WiFi 卡和网络,我会获得所有需要的信息,无论我是作为普通用户还是root运行它。

Addendum #2: The code has been upgraded, iw_get_range_info() works.附录 #2:代码已升级, iw_get_range_info()有效。

Addendum #3: The situation have just got weired;附录#3:情况刚刚变得令人担忧; On random occasions, I get succes:在随机情况下,我会成功:

static const UeTypeCurrentFrequencyChannel& UeNetworkManager::ueCurrentFrequencyChannel(const QString&) success - current channel: QPair(QVariant(double, 2.412e+09),QVariant(int, 1))  

which same as iwlist scan output :iwlist scan output相同:

wlan0     Scan completed :
          Cell 01 - Address: 64:6E:EA:22:21:D4
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)

After some time of programming/testing app, bug reappears, however iwlist scan still works.经过一段时间的编程/测试应用程序,错误再次出现,但iwlist scan仍然有效。 I am using Ubuntu 16.04.1 LTS with kernel Linux workstation 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:42:33 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux .我正在使用Ubuntu 16.04.1 LTS和内核Linux workstation 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:42:33 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Is it maybe possible the problem has to something to do with WiFi card Power Management ?问题是否可能与WiFiPower Management

Look at cfg80211_wext_giwfreq .看看cfg80211_wext_giwfreq That is why you get EINVAL of current channel if your Wi-Fi card is not used any connection mode .这就是为什么如果您的Wi-Fi卡未使用任何连接模式,您将获得当前频道的EINVAL
The command iwlist scan works because Wi-Fi card switches to AP client mode on the scan time.命令iwlist scan 起作用是因为 Wi-Fi 卡在扫描时间切换到AP client mode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM