Sample Header Ad - 728x90

Non-root access to a wifi adapter via ioctl in Linux app - how to grant?

0 votes
0 answers
206 views
I'm trying to debug a Qt5 c app in Ubuntu 20.04 on Odroid board. The app communicates with wifi adapter via ioctl(), eg:
int fd = iw_sockets_open();
struct ifreq ifreq;
//ifreq.ifr_name holds "wlxe894f617ebe6" from "iw dev" output
if (ioctl(fd, SIOCSIFFLAGS, &ifreq) == -1) {
  return FALSE;
}
The problem is that it works only when run as sudo. When I run it from QtCreator, it fails at above ioctl() call returning -1, perror() saying "Operation not permitted". From under sudo it passes and works furhter normally. lsusb names adapter as:
Bus 001 Device 012: ID 148f:5572 Ralink Technology, Corp. RT5572 Wireless Adapter
iw dev gives:
phy#0
        Interface wlxe894f617ebe6
                ifindex 3
                wdev 0x1
                addr e8:94:f6:17:eb:e6
                type managed
                txpower 20.00 dBm
Also, the adapter seems to have no corresponding file in the /dev/ directory. How to grant user access to ioctl() in this case? I tried to grant the access like with other usb devices, adding the line
SUBSYSTEM=="usb", ATTRS{idVendor}=="148f", ATTRS{idProduct}=="5572", MODE="0666"
to /etc/udev/rules.d/50-myusb.rules, but with no result. I thought I should add the user to some group like "wlan" or alike, but can't find any group name which could be related here.
Asked by wowa (1 rep)
Oct 20, 2023, 01:27 PM
Last activity: Oct 20, 2023, 03:25 PM