View Issue Details

IDProjectCategoryView StatusLast Update
0004455Kali LinuxGeneral Bugpublic2018-01-02 13:37
ReporterHades_2017 Assigned Torhertzog  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionwon't fix 
Summary0004455: Input device driver report event error.
Description

I have a input device driver, in the driver, there is a kernel timer function report key event and a kernel message will be printed in this function,the source code shown as bellow, I insert this module into kernel, the kernel message works, but use test apps read the key event, it doesn't work (nothing can be read).

I thiink,the input device node is right, after insmod this driver, event18 will be generated. rmmod this driver, event18 will be auto removed.

/ Driver /
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/timer.h>

#define DEVICE_NAME "InputTest"

static const char *input_name = "inputTest";

static struct input_dev * ipdev;

static struct timer_list timer;
static unsigned int virtual_key = 1;

static void input_test_timer(unsigned long arg)
{
static char value = 0;
value = !value;

mod_timer(&timer, jiffies + HZ);

input_event(ipdev,EV_KEY,virtual_key,value);
input_sync(ipdev);
virtual_key++;
printk("%s:%x\n", __func__,virtual_key);

}

static int input_test_init(void)
{
int err = 0;
ipdev = input_allocate_device();

set_bit(EV_KEY, ipdev->evbit);
ipdev->name = input_name;

input_set_capability(ipdev, EV_KEY, 110);
input_set_capability(ipdev, EV_KEY, 111);
input_set_capability(ipdev, EV_KEY, 112);

err = input_register_device(ipdev);
if(err){
    printk("Input_register_device error: %d\n", err);
    goto fail_alloc_input_device;
}

printk("%s\n", __func__);
input_report_key(ipdev, 1, 0x233);
input_report_key(ipdev, 1, 0x234);
input_report_key(ipdev, 1, 0x235);

init_timer(&timer);
timer.function = input_test_timer;
add_timer(&timer);

return 0;

fail_alloc_input_device:
input_unregister_device(ipdev);
del_timer(&timer);
return err;
}

static void input_test_exit(void)
{
input_report_key(ipdev, 1, 0x233);
input_report_key(ipdev, 1, 0x234);
input_report_key(ipdev, 1, 0x235);
input_unregister_device(ipdev);
del_timer(&timer);
}
MODULE_LICENSE("GPL");
module_init(input_test_init);
module_exit(input_test_exit);

/ test apps /
#include <stdio.h>
#include <linux/input.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
int fd = 0;
int key_value;
int count = 0u;
struct input_event key;

fd = open("/dev/input/event18", O_RDWR);
if(fd < 0){
    printf("Device open failed\n");
return 0;
}

for(;;){
    count = read(fd, &key, sizeof(struct input_event));
    if(EV_KEY == key.type){
    printf("key event:%x,%x\n",key.code,key.value);
}else if(EV_SYN == key.type){
    printf("syn event\n");
}else{
    if(0 != count){
       printf("event%x:%x,%x\n",key.type,key.code,key.value);
    }
}
}

close(fd);
return 0;
}

Steps To Reproduce
  1. insmod above driver module.
  2. use cat /dev/kmsg read kernel message, it works.
  3. use above apps read the input key event, there is nothing can be read.

Activities

Hades_2017

Hades_2017

2018-01-02 13:16

reporter   ~0007768

kernel build: 4.14.0-kali1-amd64

rhertzog

rhertzog

2018-01-02 13:37

administrator   ~0007769

I'm sorry, this is a bug tracker, not a support forum. There's no bug report in your message.

Issue History

Date Modified Username Field Change
2018-01-02 13:15 Hades_2017 New Issue
2018-01-02 13:16 Hades_2017 Note Added: 0007768
2018-01-02 13:37 rhertzog Assigned To => rhertzog
2018-01-02 13:37 rhertzog Status new => closed
2018-01-02 13:37 rhertzog Resolution open => won't fix
2018-01-02 13:37 rhertzog Note Added: 0007769