Skip to content

Commit

Permalink
Make evdev node classification configurable via ini files
Browse files Browse the repository at this point in the history
The built-in defaults are still used if no configuration
is provided.
  • Loading branch information
spiiroin committed Jan 3, 2013
1 parent c0ec8bf commit 3551a89
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 171 deletions.
54 changes: 25 additions & 29 deletions event-input.c
Expand Up @@ -719,53 +719,48 @@ static void update_switch_states(void)
static int match_event_file(const gchar *const filename,
const gchar *const *const drivers)
{
static char name[256];
char name[256];
int fd = -1;
int i;

/* If we cannot open the file, abort */
if ((fd = open(filename, O_NONBLOCK | O_RDONLY)) == -1) {
mce_log(LL_DEBUG,
"Failed to open `%s', skipping",
filename);
goto EXIT;
}

/* Ignore error */
errno = 0;
/* Get name of the evdev node */
if (ioctl(fd, EVIOCGNAME(sizeof name), name) < 0) {
mce_log(LL_WARN,
"ioctl(EVIOCGNAME) failed on `%s'",
filename);
goto EXIT;
}

for (i = 0; drivers[i] != NULL; i++) {
if (ioctl(fd, EVIOCGNAME(sizeof name), name) >= 0) {
if (!strcmp(name, drivers[i])) {
/* We found our event file */
mce_log(LL_DEBUG,
"`%s' is `%s'",
filename, drivers[i]);
break;
}
} else {
mce_log(LL_WARN,
"ioctl(EVIOCGNAME) failed on `%s'",
filename);
/* Then check from the provided list */
for (int i = 0; drivers[i] != NULL; i++) {
if (!strcmp(name, drivers[i])) {
/* We found our event file */
mce_log(LL_DEBUG,
"`%s' is `%s'",
filename, drivers[i]);
goto SUCCESS;
}
}

/* If the scan terminated with drivers[i] == NULL,
* we didn't find any match
*/
if (drivers[i] == NULL) {
if (close(fd) == -1) {
EXIT:
/* Close the file descriptor */
if( fd != -1 ) {
if(close(fd) == -1) {
mce_log(LL_ERR,
"Failed to close `%s'; %s",
filename, g_strerror(errno));
errno = 0;
}

fd = -1;
goto EXIT;
}
SUCCESS:

EXIT:
return fd;
}

Expand Down Expand Up @@ -810,7 +805,7 @@ static void match_and_register_io_monitor(const gchar *filename)
int fd;

if ((fd = match_event_file(filename,
driver_blacklist)) != -1) {
mce_conf_get_blacklisted_event_drivers())) != -1) {
/* If the driver for the event file is blacklisted, skip it */
if (close(fd) == -1) {
mce_log(LL_ERR,
Expand All @@ -821,7 +816,7 @@ static void match_and_register_io_monitor(const gchar *filename)

fd = -1;
} else if ((fd = match_event_file(filename,
touchscreen_event_drivers)) != -1) {
mce_conf_get_touchscreen_event_drivers())) != -1) {
gconstpointer iomon = NULL;

iomon = mce_register_io_monitor_chunk(fd, filename, MCE_IO_ERROR_POLICY_WARN, G_IO_IN | G_IO_ERR, FALSE, touchscreen_iomon_cb, sizeof (struct input_event));
Expand All @@ -840,7 +835,8 @@ static void match_and_register_io_monitor(const gchar *filename)
} else {
touchscreen_dev_list = g_slist_prepend(touchscreen_dev_list, (gpointer)iomon);
}
} else if ((fd = match_event_file(filename, keyboard_event_drivers)) != -1) {
} else if ((fd = match_event_file(filename,
mce_conf_get_keyboard_event_drivers())) != -1) {
gconstpointer iomon = NULL;

iomon = mce_register_io_monitor_chunk(fd, filename, MCE_IO_ERROR_POLICY_WARN, G_IO_IN | G_IO_ERR, FALSE, keypress_iomon_cb, sizeof (struct input_event));
Expand Down
142 changes: 0 additions & 142 deletions event-input.h
Expand Up @@ -32,148 +32,6 @@
/** Path to the GPIO key disable interface */
#define GPIO_KEY_DISABLE_PATH "/sys/devices/platform/gpio-keys/disabled_keys"

/* XXX:
* We should probably use
* /dev/input/keypad
* /dev/input/gpio-keys
* /dev/input/pwrbutton
* /dev/input/ts
* and add whitelist entries for misc devices instead
*/

/**
* List of drivers that provide touchscreen events
* XXX: If this is made case insensitive,
* we could search for "* touchscreen" instead
*/
static const gchar *const touchscreen_event_drivers[] = {
/** Input layer name for the Atmel mXT touchscreen */
"Atmel mXT Touchscreen",

/** Input layer name for the Atmel QT602240 touchscreen */
"Atmel QT602240 Touchscreen",

/** TSC2005 touchscreen */
"TSC2005 touchscreen",

/** TSC2301 touchscreen */
"TSC2301 touchscreen",

/** ADS784x touchscreen */
"ADS784x touchscreen",

/** No more entries */
NULL
};

/**
* List of drivers that provide keyboard events
*/
static const gchar *const keyboard_event_drivers[] = {
/** Input layer name for the TWL4030 keyboard/keypad */
"TWL4030 Keypad",

/** Legacy input layer name for the TWL4030 keyboard/keypad */
"omap_twl4030keypad",

/** Generic input layer name for keyboard/keypad */
"Internal keyboard",

/** Input layer name for the LM8323 keypad */
"LM8323 keypad",

/** Generic input layer name for keypad */
"Internal keypad",

/** Input layer name for the TSC2301 keypad */
"TSC2301 keypad",

/** Legacy generic input layer name for keypad */
"omap-keypad",

/** Input layer name for standard PC keyboards */
"AT Translated Set 2 keyboard",

/** Input layer name for the power button in various MeeGo devices */
"msic_power_btn",

/** Input layer name for the TWL4030 power button */
"twl4030_pwrbutton",

/** Input layer name for the Triton 2 power button */
"triton2-pwrbutton",

/** Input layer name for the Retu powerbutton */
"retu-pwrbutton",

/** Input layer name for the PC Power button */
"Power Button",

/** Input layer name for the PC Sleep button */
"Sleep Button",

/** Input layer name for the Thinkpad extra buttons */
"Thinkpad Extra Buttons",

/** Input layer name for ACPI virtual keyboard */
"ACPI Virtual Keyboard Device",

/** Input layer name for GPIO-keys */
"gpio-keys",

/** Input layer name for DFL-61/TWL4030 jack sense */
"dfl61-twl4030 Jack",

/** Legacy input layer name for TWL4030 jack sense */
"rx71-twl4030 Jack",

/** Input layer name for PC Lid switch */
"Lid Switch",

/** No more entries */
NULL
};

/**
* List of drivers that we should not monitor
*/
static const gchar *const driver_blacklist[] = {
/** Input layer name for the AMI305 magnetometer */
"ami305 magnetometer",

/** Input layer name for the ST LIS3LV02DL accelerometer */
"ST LIS3LV02DL Accelerometer",

/** Input layer name for the ST LIS302DL accelerometer */
"ST LIS302DL Accelerometer",

/** Input layer name for the TWL4030 vibrator */
"twl4030:vibrator",

/** Input layer name for AV accessory */
"AV Accessory",

/** Input layer name for the video bus */
"Video Bus",

/** Input layer name for the PC speaker */
"PC Speaker",

/** Input layer name for the Intel HDA headphone */
"HDA Intel Headphone",

/** Input layer name for the Intel HDA microphone */
"HDA Intel Mic",

/** Input layer name for the UVC 17ef:4807 webcam in thinkpad X301 */
"UVC Camera (17ef:4807)",

/** Input layer name for the UVC 17ef:480c webcam in thinkpad X201si */
"UVC Camera (17ef:480c)",

/** No more entries */
NULL
};

/**
* Delay between I/O monitoring setups and keypress repeats; 1 second
Expand Down

0 comments on commit 3551a89

Please sign in to comment.