#ifndef _IOCTL_CHAR_DEVICE_H_ #define _IOCTL_CHAR_DEVICE_H_ #include /** * ioctl constants are defined in this header file for our * char_driver_ioctl driver. * * This file explains how the constants are defined with * the use of inline comments */ /** * Constants have to be globally unique. Though this is not * compulsory, it is necessary. This is because of the simple * reason: we do not want our commands to clash with the commands * in other drivers. we don't want the right command doing to * the wrong driver or vice-versa */ /** * We have to base our constants based on a magic number. */ #define DEMO_IOCTL_MAGIC 'a' /** * Defining constants requires us to decide following values * * 1. type or magic number (type) * 2. sequence number which is eight bits wide. This means * we can have up to 256 ioctl commands (nr) * 3. direction if the arg is involed, whether we are reading * or writing * 4. size(composition) of the argument. * * To arrive at unique numbers easily we use the following macros * _IO(type, nr); -> no data is passed from kernel to user space, just like void function * _IOW(type, nr, dataitem) the fourth item calculated using sizeof -> to read from user to kernel * _IOR(type, nr, dataitem) -> to write to user from kernel * _IOWR(type, nr, dataitem) -> to do both read and write */ #define WR_VALUE _IOW(DEMO_IOCTL_MAGIC, 1, int32_t *) #define RD_VALUE _IOR(DEMO_IOCTL_MAGIC, 2, int32_t *) #endif