0
votes

I am creating a driver for a embeeded system. I am using IOCTL function. The device is register correctly and the open and write functions work as expected but IOCTL doesn't.

When I call IOCTL from user space with parameter 0 the my_ioctl function called with ioctl_num = 0 but when I use any other values the my_ioctl kernel function is not being called.

 #define READ_IOCTL                      _IO(UAM_DEV_MAGIC, 0)
 #define WRITE_IOCTL                     _IO(UAM_DEV_MAGIC, 1)
 #define ASK_VALUE                       _IO(UAM_DEV_MAGIC, 2)

When I make a IOCTL call from user space using READ_IOCTL (0), everything work properly. However, when I try WRITE_IOCTL and ASK_VALUE (1 and 2).

If I use the following:

#define READ_IOCTL                      _IO(UAM_DEV_MAGIC, 1)
#define WRITE_IOCTL                     _IO(UAM_DEV_MAGIC, 0)
#define ASK_VALUE                       _IO(UAM_DEV_MAGIC, 2)

Only works WRITE_IOCTL calls from user space. I am using linux 3.16 and PowerPC. Any idea what is wrong?

1
Here is a sample driver. Might be helpful github.com/jeyaramvrp/kernel-module-programming/tree/master/… - Jeyaram
Thank for answering. I have seen the code, but It seems pretty similar to what I have done. It looks like the program doesn´t not reconize the magic number. Any idea why does it work with 0 and not with the 1,2,3,etc? - manolo tunez
Any idea why does it work with 0 and not with the 1,2,3,etc? - probably, your codes conincide with predefined ioctl codes. See man ioctl_list. - Tsyvarev

1 Answers

0
votes

I have found the solution. I was in a kernel of 64 bit. The code in c in user space was in 32 bit. I must compile in 64 bit to be able to work.