Dear Team,
I have written a sample kernel driver and user space application and tried IOCTL Call to SIOCDEVPRIVATE address which not working and showing below error
Start...
ioctl error -1, err: Operation not supported
Finished...
5.15 kernel version used here.
Same code is working on another device with kernel version 4.19
Could you please get back what might be the issue ? We tried IOR , IOW, IOWR calls also but the same issue ?
kernel space part of where ioctl call has to happen
#define SIOC_CHRIZ SIOCDEVPRIVATE+14
static int chriz_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
printk(KERN_INFO "chriz ioctl: command: %x\n", cmd);
return 0;
}
User space part
#define SIOC_CHRIZ SIOCDEVPRIVATE+14
int main() {
int sock = 0;
int ret = 0;
struct iwreq iwr;
struct ifreq ifr;
printf("Start...\n");
// init net socket
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
printf("socket error\n");
return 1;
}
// fill in interface name
memset(&iwr, 0, sizeof(iwr)); // for wireless
strcpy(iwr.ifr_name, interface_name);
memset(&ifr, 0, sizeof(ifr)); // for ethernet
strcpy(ifr.ifr_name, interface_name);
// do ioctl
ret = ioctl(sock, SIOC_CHRIZ, &ifr);
if (ret < 0) {
printf("ioctl error %d, err: %s\n", ret, strerror(errno));
}
// finished
printf("Finished...\n");
close(sock);
return 0;
}
Hello @RajendraPrasadBhoga ,
Could you please try close(sock) before ret = ioctl(sock, SIOC_CHRIZ, &ifr)
// do ioctl
pclose(sock);
ret = ioctl(sock, SIOC_CHRIZ, &ifr);
if (ret < 0) {
printf("ioctl error %d, err: %s\n", ret, strerror(errno));
}
// finished
printf("Finished...\n");
return 0;
(note the change of close to pclose)
Let me know hot it was!
Best regards.