Skip to content
Advertisement

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:

JavaScript

Now, iw_get_ext always returns -1 and errno is set to value of 22. I’ve taken a look at the errno.h and search for error 22 and I’ve got following error declaration:
#define EINVAL 22 /* Invalid argument */.
Why am I getting Invalid argument error while trying to query current frequency channel of network adapter with ioctl? I’ve launched application containing this code as normal user and as root, same result any time:

JavaScript

Why, what am I missing?

Addendum #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.

Addendum #2: The code has been upgraded, iw_get_range_info() works.

Addendum #3: The situation have just got weired; On random occasions, I get succes:

JavaScript

which same as iwlist scan output:

JavaScript

After some time of programming/testing app, bug reappears, however iwlist scan still works. 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.
Is it maybe possible the problem has to something to do with WiFi card Power Management?

Advertisement

Answer

Look at cfg80211_wext_giwfreq. That is why you get EINVAL of current channel if your Wi-Fi card is not used any connection mode.
The command iwlist scan works because Wi-Fi card switches to AP client mode on the scan time.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement