Specifications

CHAPTER 5. IMPLEMENTATION 51
Generate an abstract input event
Send the abstract input event
Reading data from the event interface returns a structure input event (Chapter 2, §2.1).
The structure’s member type gives information whether the occurred input event was a key-
press or not. A keypress’ type has the value EV KEY. For security reasons, the module only
reports input events of keys which are not blacklisted. Beside others, blacklisted keys are all
alpha numeric keys. This prevents processes from abusing the Input Abstraction Layer to
intercept passwords or other sensitive data. Additionally, the blacklist contains keys which
are not found on keyboards. Such keys encompass buttons of input devices such as mice and
joysticks.
This blacklist is implemented by the following macro:
#define key_blacklisted(code) \
((code < KEY_MAX) && (code > KEY_MIN) ? FALSE : TRUE)
The scancode of the pressed key is stored in code. KEY MIN and KEY MAX limit the range of
scancodes which are not blacklisted. All other keys are blacklisted. The value of KEY MIN is set
to 0x32 and the value of KEY MAX is set to 0x1ff. Thus, the macro key blacklisted() returns
FALSE only in case the value of code being greater than KEY MIN and less than KEY MAX. Oth-
erwise, key blacklisted() returns TRUE. The lower boundary defined by KEY MIN blacklists
all scancodes of alpha numeric keys. The upper boundary KEY MAX blacklists scancodes of keys
and buttons which are found on other input devices than keyboards.
If an input event is not blacklisted, the module continues its processing: an abstract input
event using the data structure IalEvent is created and afterwards sent to the Input Abstraction
Layer’s output interface. The member sender is set to the token of the module (evdev).
The data structure’s member sender is set to the name of the input event interface which
triggered the event. This name is acquired using ioctl(2). The corresponding ioctl request
is EVIOCGNAME. It is defined by the event interface driver and returns the name of a device.
The following example shows how the name of a device (/dev/input/event0) is obtained:
int fd = open("/dev/input/event0", O_RDONLY);
char device_name[128];
if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) == -1) {
strcpy(device_name, "Unknown device");
}
If the ioctl request succeeded, device name now contains the name of the device event0.
Otherwise—if the request failed—the string Unknown device is copied to device name. The
event’s member name is set to a descriptive string obtained by translating the scancode. This
descriptive string is stored in a translation table of the mo dule. To translate a scancode to
its corresponding description, the module’s macro function key to string() is used. The
scancode has to be supplied as parameter. The return value of the function is a pointer to the
descriptive string (char *). At last, the member raw is set to the scancode of the input event.