2021-07-22 06:35:24 +08:00
|
|
|
/*
|
2021-08-08 01:24:59 +08:00
|
|
|
* chardev.h - the header file with the ioctl definitions.
|
2021-07-22 06:35:24 +08:00
|
|
|
*
|
2021-08-08 01:24:59 +08:00
|
|
|
* The declarations here have to be in a header file, because they need
|
|
|
|
* to be known both to the kernel module (in chardev.c) and the process
|
|
|
|
* calling ioctl (ioctl.c).
|
2021-07-22 06:35:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CHARDEV_H
|
|
|
|
#define CHARDEV_H
|
|
|
|
|
|
|
|
#include <linux/ioctl.h>
|
|
|
|
|
2021-08-08 01:24:59 +08:00
|
|
|
/* The major device number. We can not rely on dynamic registration
|
|
|
|
* any more, because ioctls need to know it.
|
2021-07-22 06:35:24 +08:00
|
|
|
*/
|
|
|
|
#define MAJOR_NUM 100
|
|
|
|
|
2021-08-08 01:24:59 +08:00
|
|
|
/* Set the message of the device driver */
|
2021-07-22 06:35:24 +08:00
|
|
|
#define IOCTL_SET_MSG _IOW(MAJOR_NUM, 0, char *)
|
2021-08-08 01:24:59 +08:00
|
|
|
/* _IOW means that we are creating an ioctl command number for passing
|
|
|
|
* information from a user process to the kernel module.
|
2021-07-22 06:35:24 +08:00
|
|
|
*
|
2021-08-08 01:24:59 +08:00
|
|
|
* The first arguments, MAJOR_NUM, is the major device number we are using.
|
2021-07-22 06:35:24 +08:00
|
|
|
*
|
2021-08-08 01:24:59 +08:00
|
|
|
* The second argument is the number of the command (there could be several
|
|
|
|
* with different meanings).
|
2021-07-22 06:35:24 +08:00
|
|
|
*
|
2021-08-08 01:24:59 +08:00
|
|
|
* The third argument is the type we want to get from the process to the
|
|
|
|
* kernel.
|
2021-07-22 06:35:24 +08:00
|
|
|
*/
|
|
|
|
|
2021-08-08 01:24:59 +08:00
|
|
|
/* Get the message of the device driver */
|
2021-07-22 06:35:24 +08:00
|
|
|
#define IOCTL_GET_MSG _IOR(MAJOR_NUM, 1, char *)
|
2021-08-08 01:24:59 +08:00
|
|
|
/* This IOCTL is used for output, to get the message of the device driver.
|
|
|
|
* However, we still need the buffer to place the message in to be input,
|
2021-07-22 06:35:24 +08:00
|
|
|
* as it is allocated by the process.
|
|
|
|
*/
|
|
|
|
|
2021-08-08 01:24:59 +08:00
|
|
|
/* Get the n'th byte of the message */
|
2021-07-22 06:35:24 +08:00
|
|
|
#define IOCTL_GET_NTH_BYTE _IOWR(MAJOR_NUM, 2, int)
|
2021-08-08 01:24:59 +08:00
|
|
|
/* The IOCTL is used for both input and output. It receives from the user
|
|
|
|
* a number, n, and returns Message[n].
|
2021-07-22 06:35:24 +08:00
|
|
|
*/
|
|
|
|
|
2021-08-08 01:24:59 +08:00
|
|
|
/* The name of the device file */
|
2021-07-22 06:35:24 +08:00
|
|
|
#define DEVICE_FILE_NAME "char_dev"
|
|
|
|
|
|
|
|
#endif
|