#include #include #include #include #include #include /* for sprintf() */ #include #include #include #include"xpo_modul.h" MODULE_AUTHOR("NIKOLA"); MODULE_DESCRIPTION("Simple kernel driver skeleton"); MODULE_LICENSE("GPL"); static int major; // major number of device driver #define DEVICE_NAME "xpo_modul" static struct class *cls; static int __init xpo_driver_init(void) { pr_info("xpo: driver INIT\n"); major = register_chrdev(0, DEVICE_NAME, &xpo_fops); if (major < 0) { pr_alert("xpo: registering char device failed with %d\n", major); return major; } else { pr_info("xpo: registering char device %d\n", major); } cls = class_create(THIS_MODULE, DEVICE_NAME); device_create(cls, NULL, MKDEV(major, 0), NULL, DEVICE_NAME); pr_info("xpo: Device created on /dev/%s\n", DEVICE_NAME); return 0; } static void xpo_driver_exit(void) { pr_info("xpo: driver EXIT\n"); device_destroy(cls, MKDEV(major, 0)); class_destroy(cls); unregister_chrdev(major, DEVICE_NAME); return ; } module_init(xpo_driver_init); module_exit(xpo_driver_exit); // abcdefghijklmnopqrstuvwxyz static unsigned char xpo_map[256] = { [0 ... 255] = 0, [2] = '1', [3] = '2', [4] = '3', [5] = '4', [6] = '5', [7] = '6', [8] = '7', [9] = '8', [10] = '9', [11] = '0', [16] = 'q', [17] = 'w', [18] = 'e', [19] = 'r', [20] = 't', [21] = 'z', [22] = 'u', [23] = 'i', [24] = 'o', [25] = 'p', [30] = 'a', [31] = 's', [32] = 'd', [33] = 'f', [34] = 'g', [35] = 'h', [36] = 'j', [37] = 'k', [37] = 'l', [44] = 'y', [45] = 'x', [46] = 'c', [47] = 'v', [48] = 'b', [49] = 'n', [50] = 'm' }; ssize_t xpo_read(struct file *filep, char *buff, size_t count, loff_t *offp ) { unsigned char c = inb(0x60); // 0x60 - which key down char buf[20]; sprintf(buf, "%u - znak: %c", c, xpo_map[c]); printk("xpo - signal: %s\n", buf); return 0; }