Hi ,
I have written a small kernel module to learn the basics of it.
=======================================================
#include <linux/module.h>
#include <linux/netdevice.h>
int my_ioctl(struct net_device *dev, struct ifreq *ifr,int cmd);
int my_open(struct net_device *dev);
int my_init(struct net_device *dev)
{
if(dev == NULL)
{
printk("dev = null\n");
}
dev->open = my_open;
dev->do_ioctl = my_ioctl;
printk("my_init() called\n");
return 0;
}
int my_ioctl(struct net_device *dev, struct ifreq *ifr,int cmd)
{
printk("my_ioctl() called witih cmd = %d\n",cmd);
return 0;
}
int my_open(struct net_device *dev)
{
printk("my_open() called\n");
return 1;
}
static struct net_device myDev = {
"kamal\0 ",
0, 0, 0, 0,
0, 0,
0, 0, 0,
NULL, my_init
};
int init_module(void)
{
int err;
printk("init_module() called\n");
if(dev_get_by_name(myDev.name)==NULL)
{
err = register_netdev(&myDev);
if (err) printk("Error Message ::%d\n",err);
}
else
{
printk("Dev Already Exist\n");
}
return 0;
}
void cleanup_module(void)
{
unregister_netdev(&myDev);
printk("cleanup_module() called.\n");
}
====================================================
I am trying to call the my_ioctl() function through SIOCDEVPRIVATE ioctl
command
from user space. My user space program looks like this:
=====================================================
#include <stdio.h>
#include <string.h>
#include<sys/ioctl.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<linux/netdevice.h>
#include<stdlib.h>
#include <errno.h>
#define LA_COMMAND SIOCDEVPRIVATE+2
int main()
{
int s,err;
int Arg=100;
struct ifreq IfReq;
s=socket(AF_INET, SOCK_STREAM, 0);
/* s = socket(AF_INET, SOCK_RAW, 255); */
if(s<0)
{
printf("Unable To Open The Socket\n");
return 0;
}
strcpy(IfReq.ifr_name,"kamal");
IfReq.ifr_data = (void*)&Arg;
err = ioctl(s,LA_COMMAND, &IfReq);
if(err < 0)
{
printf("Error Occured :: %d\n",errno);
perror("");
return 0;
}
}
====================================================
But I am getting the following error after its execution:
#
Error Occured :: 95
Operation not supported
In file /usr/src/linux/net/core/dev.c
static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
{
.
.
.
.
.
.
.
default:
if ((cmd >= SIOCDEVPRIVATE &&
cmd <= SIOCDEVPRIVATE + 15) ||
cmd == SIOCETHTOOL) {
if (dev->do_ioctl) {
if (!netif_device_present(dev))
return -ENODEV;
return dev->do_ioctl(dev, ifr,
cmd);
}
return -EOPNOTSUPP; ==>> error is
returnded from here
}
.
.
}
I found that in default case, dev->do_ioctl is comming NULL and hence
EOPNOTSUPP
error is returned.
can anyone have idea why this error is there ??
-Kamal
Wipro_Disclaimer.txt
Description: Text document
|