Removed Rust code, added misc device and irq handle. Began work on correctly formatting print msg and logging files.

Signed-off-by: Jolan Rathelot <jrathelo@student.42nice.fr>
This commit is contained in:
Jolan Rathelot 2024-03-12 13:27:17 +01:00
parent b20836700d
commit 1b685c68cb
12 changed files with 517 additions and 13480 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@
*.mod.order *.mod.order
*.ko *.ko
*.o *.o
*.o.d
*.symvers *.symvers
*.order *.order

8
.idea/copyright/profiles_settings.xml generated Normal file
View File

@ -0,0 +1,8 @@
<component name="CopyrightManager">
<settings>
<LanguageOptions name="ObjectiveC">
<option name="fileTypeOverride" value="3" />
<option name="block" value="false" />
</LanguageOptions>
</settings>
</component>

86
.idea/workspace.xml generated
View File

@ -16,7 +16,9 @@
<configurations /> <configurations />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="2686ebbf-1c6c-4484-bb57-dec59a208d53" name="Changes" comment="" /> <list default="true" id="2686ebbf-1c6c-4484-bb57-dec59a208d53" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -26,7 +28,13 @@
<option name="formatViaClangd" value="false" /> <option name="formatViaClangd" value="false" />
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="PREVIOUS_COMMIT_AUTHORS">
<list>
<option value="Jolan Rathelot &lt;jrathelo@student.42nice.fr&gt;" />
</list>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="SIGN_OFF_COMMIT" value="true" />
</component> </component>
<component name="MacroExpansionManager"> <component name="MacroExpansionManager">
<option name="directoryName" value="5020vg1s" /> <option name="directoryName" value="5020vg1s" />
@ -57,38 +65,40 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;, "RunOnceActivity.cidr.known.project.marker": "true",
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;, "WebServerToolWindowFactoryState": "false",
&quot;cf.first.check.clang-format&quot;: &quot;false&quot;, "cf.first.check.clang-format": "false",
&quot;cidr.known.project.marker&quot;: &quot;true&quot;, "cidr.known.project.marker": "true",
&quot;git-widget-placeholder&quot;: &quot;master&quot;, "git-widget-placeholder": "master",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;org.rust.cargo.project.model.PROJECT_DISCOVERY&quot;: &quot;true&quot;, "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
&quot;org.rust.hideNoCargoProjectNotifications/root/drivers-and-interrupts/src/main.rs&quot;: &quot;true&quot;, "org.rust.hideNoCargoProjectNotifications/root/drivers-and-interrupts/src/fancy_print.rs": "true",
&quot;settings.editor.selected.configurable&quot;: &quot;CMakeSettings&quot;, "org.rust.hideNoCargoProjectNotifications/root/drivers-and-interrupts/src/main.rs": "true",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "settings.editor.selected.configurable": "MakefileSettings",
"structure.view.defaults.are.configured": "true",
"vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RdControllerToolWindowsLayoutState" isNewUi="true"> <component name="RdControllerToolWindowsLayoutState" isNewUi="true">
<layout> <layout>
<window_info id="Space Code Reviews" /> <window_info id="Space Code Reviews" />
<window_info id="Bookmarks" side_tool="true" /> <window_info id="Bookmarks" side_tool="true" />
<window_info id="Merge Requests" /> <window_info id="Merge Requests" />
<window_info id="Commit_Guest" /> <window_info id="Commit_Guest" />
<window_info id="Pull Requests" /> <window_info id="Pull Requests" weight="0.2032358" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.14206561" /> <window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.50054586" visible="true" weight="0.2032358" />
<window_info id="Commit" order="1" weight="0.25" /> <window_info id="Commit" order="1" weight="0.25" />
<window_info id="Structure" order="2" side_tool="true" weight="0.25" /> <window_info active="true" id="Structure" order="2" sideWeight="0.49945414" side_tool="true" visible="true" weight="0.2032358" />
<window_info anchor="bottom" id="CMake" weight="0.22384511" /> <window_info anchor="bottom" id="CMake" weight="0.22384511" />
<window_info anchor="bottom" id="Database Changes" /> <window_info anchor="bottom" id="Database Changes" />
<window_info anchor="bottom" id="TypeScript" /> <window_info anchor="bottom" id="TypeScript" />
@ -97,8 +107,9 @@
<window_info anchor="bottom" id="TODO" /> <window_info anchor="bottom" id="TODO" />
<window_info anchor="bottom" id="File Transfer" /> <window_info anchor="bottom" id="File Transfer" />
<window_info anchor="bottom" id="Vcpkg" /> <window_info anchor="bottom" id="Vcpkg" />
<window_info anchor="bottom" id="Find" weight="0.32982337" />
<window_info anchor="bottom" id="clangd" /> <window_info anchor="bottom" id="clangd" />
<window_info anchor="bottom" id="Version Control" order="0" /> <window_info anchor="bottom" id="Version Control" order="0" weight="0.32982337" />
<window_info anchor="bottom" id="Problems View" order="1" /> <window_info anchor="bottom" id="Problems View" order="1" />
<window_info active="true" anchor="bottom" id="Terminal" order="2" visible="true" weight="0.32982337" /> <window_info active="true" anchor="bottom" id="Terminal" order="2" visible="true" weight="0.32982337" />
<window_info anchor="bottom" id="Services" order="3" weight="0.22384511" /> <window_info anchor="bottom" id="Services" order="3" weight="0.22384511" />
@ -125,7 +136,26 @@
<workItem from="1701724251213" duration="880000" /> <workItem from="1701724251213" duration="880000" />
<workItem from="1701777445625" duration="1698000" /> <workItem from="1701777445625" duration="1698000" />
<workItem from="1709558648771" duration="601000" /> <workItem from="1709558648771" duration="601000" />
<workItem from="1709718885201" duration="8002000" />
<workItem from="1709815509103" duration="4654000" />
<workItem from="1709884751802" duration="13040000" />
<workItem from="1710150741856" duration="422000" />
<workItem from="1710152601411" duration="442000" />
<workItem from="1710153276897" duration="5624000" />
<workItem from="1710237482962" duration="1467000" />
<workItem from="1710239039309" duration="441000" />
<workItem from="1710239561572" duration="2000" />
<workItem from="1710242577588" duration="3883000" />
</task> </task>
<task id="LOCAL-00001" summary="Removed Rust code, added misc device and irq handle. Began work on correctly formatting print msg and logging files.">
<option name="closed" value="true" />
<created>1710246437184</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1710246437184</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -137,6 +167,10 @@
<isAutomaticFoundErrors value="true" /> <isAutomaticFoundErrors value="true" />
<isAutomaticFoundErrors value="true" /> <isAutomaticFoundErrors value="true" />
</component> </component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Removed Rust code, added misc device and irq handle. Began work on correctly formatting print msg and logging files." />
<option name="LAST_COMMIT_MESSAGE" value="Removed Rust code, added misc device and irq handle. Began work on correctly formatting print msg and logging files." />
</component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />
<select /> <select />

26
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/lib/",
"/usr/src/linux-6.7.8-jrathelo/include",
"/usr/src/linux-mainline/arch/x86/include/generated",
"/usr/src/linux-6.4.12-jrathelo/arch/alpha/include",
"/usr/src/linux-6.7.8-jrathelo/arch/x86/include",
"/usr/src/linux-6.7.8-jrathelo/include",
"/usr/src/linux-6.7.8-jrathelo/include",
"/usr/src/linux-6.7.8-jrathelo/include",
"/usr/src/linux-6.7.8-jrathelo/include"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}

2
Kbuild
View File

@ -1,4 +1,4 @@
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
obj-m := driver_and_interrupts.o obj-m := driver_and_interrupts.o
driver_and_interrupts-y := src/lib.o driver_and_interrupts-y := src/main.o src/misc_device_fops.o src/keyboard_logger.o

View File

@ -1,20 +1,23 @@
KDIR ?= /lib/modules/`uname -r`/build KDIR ?= /lib/modules/`uname -r`/build
SRC = src/main.c src/misc_device_fops.c src/keyboard_logger.c
all: driver_and_interrupts.ko all: driver_and_interrupts.ko
driver_and_interrupts.ko: src/lib.rs driver_and_interrupts.ko: $(SRC)
$(MAKE) -C $(KDIR) M=$$PWD LLVM=1 $(MAKE) -C $(KDIR) M=$$PWD LLVM=1
modules_install: install: modprobe
modules_install: driver_and_interrupts.ko
$(MAKE) -C $(KDIR) M=$$PWD LLVM=1 modules_install $(MAKE) -C $(KDIR) M=$$PWD LLVM=1 modules_install
clean: clean:
$(MAKE) -C $(KDIR) M=$$PWD LLVM=1 clean $(MAKE) -C $(KDIR) M=$$PWD LLVM=1 clean
insmod: modprobe: modules_install
insmod driver_and_interrupts.ko modprobe driver_and_interrupts
rmmod: rmmod:
rmmod driver_and_interrupts rmmod driver_and_interrupts
.PHONY: all clean modules_install rmmod insmod .PHONY: all clean modules_install rmmod modprobe install

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
#ifndef DRIVERS_AND_INTERRUPTS_H
#define DRIVERS_AND_INTERRUPTS_H
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/interrupt.h>
ssize_t read_keyboard_misc_device(struct file *file, char __user *buf, size_t count, loff_t *ppos);
irqreturn_t key_logger_isr(int i, void *dummy);
enum state {
PRESSED = true,
RELEASED = false,
};
struct KeyboardCaptureData {
uint64_t code;
char *key_name;
enum state state;
char ascii_value;
};
struct linked_list_node {
struct KeyboardCaptureData data;
struct list_head list;
};
static struct mutex lock;
#ifndef EXTERN
# define EXTERN extern
#endif
extern struct list_head keyboard_log;
void print_keyboard_line(struct KeyboardCaptureData data);
#endif

288
src/keyboard_logger.c Normal file
View File

@ -0,0 +1,288 @@
#include <linux/list.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/time.h>
#include "drivers_and_interrupts.h"
LIST_HEAD(keyboard_log);
const struct KeyboardCaptureData KEY_DICTIONARY[] = {
{ 0x1, "Escape", PRESSED, 0 },
{ 0x2, "1", PRESSED, '1' },
{ 0x3, "2", PRESSED, '2' },
{ 0x4, "3", PRESSED, '3' },
{ 0x5, "4", PRESSED, '4' },
{ 0x6, "5", PRESSED, '5' },
{ 0x7, "6", PRESSED, '6' },
{ 0x8, "7", PRESSED, '7' },
{ 0x9, "8", PRESSED, '8' },
{ 0xa, "9", PRESSED, '9' },
{ 0xb, "0", PRESSED, '0' },
{ 0xc, "-", PRESSED, '-' },
{ 0xd, "=", PRESSED, '=' },
{ 0xe, "Backspace", PRESSED, 0 },
{ 0xf, "Tab", PRESSED, '\t' },
{ 0x10, "Q", PRESSED, 'q' },
{ 0x11, "W", PRESSED, 'w' },
{ 0x12, "E", PRESSED, 'e' },
{ 0x13, "R", PRESSED, 'r' },
{ 0x14, "T", PRESSED, 't' },
{ 0x15, "Y", PRESSED, 'y' },
{ 0x16, "U", PRESSED, 'u' },
{ 0x17, "I", PRESSED, 'i' },
{ 0x18, "O", PRESSED, 'o' },
{ 0x19, "P", PRESSED, 'p' },
{ 0x1a, "[", PRESSED, '[' },
{ 0x1b, "]", PRESSED, ']' },
{ 0x1c, "Enter", PRESSED, '\n' },
{ 0x1d, "Control", PRESSED, 0 },
{ 0x1e, "A", PRESSED, 'a' },
{ 0x1f, "S", PRESSED, 's' },
{ 0x20, "D", PRESSED, 'd' },
{ 0x21, "F", PRESSED, 'f' },
{ 0x22, "G", PRESSED, 'g' },
{ 0x23, "H", PRESSED, 'h' },
{ 0x24, "J", PRESSED, 'j' },
{ 0x25, "K", PRESSED, 'k' },
{ 0x26, "L", PRESSED, 'l' },
{ 0x27, ";", PRESSED, ';' },
{ 0x28, "'", PRESSED, '\'' },
{ 0x29, "`", PRESSED, '`' },
{ 0x2a, "Shift", PRESSED, 0 },
{ 0x2b, "\\", PRESSED, '\\' },
{ 0x2c, "Z", PRESSED, 'z' },
{ 0x2d, "X", PRESSED, 'x' },
{ 0x2e, "C", PRESSED, 'c' },
{ 0x2f, "V", PRESSED, 'v' },
{ 0x30, "B", PRESSED, 'b' },
{ 0x31, "N", PRESSED, 'n' },
{ 0x32, "M", PRESSED, 'm' },
{ 0x33, ",", PRESSED, ',' },
{ 0x34, ".", PRESSED, '.' },
{ 0x35, "/", PRESSED, '/' },
{ 0x36, "Right Shift", PRESSED, 0 },
{ 0x37, "* (Keypad)", PRESSED, '*' },
{ 0x38, "Alt", PRESSED, 0 },
{ 0x39, "Space", PRESSED, ' ' },
{ 0x3a, "CapsLock", PRESSED, 0 },
{ 0x3b, "F1", PRESSED, 0 },
{ 0x3c, "F2", PRESSED, 0 },
{ 0x3d, "F3", PRESSED, 0 },
{ 0x3e, "F4", PRESSED, 0 },
{ 0x3f, "F5", PRESSED, 0 },
{ 0x40, "F6", PRESSED, 0 },
{ 0x41, "F7", PRESSED, 0 },
{ 0x42, "F8", PRESSED, 0 },
{ 0x43, "F9", PRESSED, 0 },
{ 0x44, "F10", PRESSED, 0 },
{ 0x45, "NumberLock", PRESSED, 0 },
{ 0x46, "ScrollLock", PRESSED, 0 },
{ 0x47, "7 (Keypad)", PRESSED, '7' },
{ 0x48, "8 (Keypad)", PRESSED, '8' },
{ 0x49, "9 (Keypad)", PRESSED, '9' },
{ 0x4a, "- (Keypad)", PRESSED, '-' },
{ 0x4b, "4 (Keypad)", PRESSED, '4' },
{ 0x4c, "5 (Keypad)", PRESSED, '5' },
{ 0x4d, "6 (Keypad)", PRESSED, '6' },
{ 0x4e, "+ (Keypad)", PRESSED, '+' },
{ 0x4f, "1 (Keypad)", PRESSED, '1' },
{ 0x50, "2 (Keypad)", PRESSED, '2' },
{ 0x51, "3 (Keypad)", PRESSED, '3' },
{ 0x52, "0 (Keypad)", PRESSED, '0' },
{ 0x53, ". (Keypad)", PRESSED, '.' },
{ 0x57, "F11", PRESSED, 0 },
{ 0x58, "F12", PRESSED, 0 },
{ 0x81, "Escape", RELEASED, 0 },
{ 0x82, "1", RELEASED, '1' },
{ 0x83, "2", RELEASED, '2' },
{ 0x84, "3", RELEASED, '3' },
{ 0x85, "4", RELEASED, '4' },
{ 0x86, "5", RELEASED, '5' },
{ 0x87, "6", RELEASED, '6' },
{ 0x88, "7", RELEASED, '6' },
{ 0x89, "8", RELEASED, '8' },
{ 0x8a, "9", RELEASED, '9' },
{ 0x8b, "0", RELEASED, '0' },
{ 0x8c, "-", RELEASED, '-' },
{ 0x8d, "=", RELEASED, '=' },
{ 0x8e, "Backspace", RELEASED, 0 },
{ 0x8f, "Tab", RELEASED, '\t' },
{ 0x90, "Q", RELEASED, 'q' },
{ 0x91, "W", RELEASED, 'w' },
{ 0x92, "E", RELEASED, 'e' },
{ 0x93, "R", RELEASED, 'r' },
{ 0x94, "T", RELEASED, 't' },
{ 0x95, "Y", RELEASED, 'y' },
{ 0x96, "U", RELEASED, 'u' },
{ 0x97, "I", RELEASED, 'i' },
{ 0x98, "O", RELEASED, 'o' },
{ 0x99, "P", RELEASED, 'p' },
{ 0x9a, "[", RELEASED, '[' },
{ 0x9b, "]", RELEASED, ']' },
{ 0x9c, "Enter", RELEASED, '\n' },
{ 0x9d, "Control", RELEASED, 0 },
{ 0x9e, "A", RELEASED, 'a' },
{ 0x9f, "S", RELEASED, 's' },
{ 0xa0, "D", RELEASED, 'd' },
{ 0xa1, "F", RELEASED, 'f' },
{ 0xa2, "G", RELEASED, 'g' },
{ 0xa3, "H", RELEASED, 'h' },
{ 0xa4, "J", RELEASED, 'j' },
{ 0xa5, "K", RELEASED, 'k' },
{ 0xa6, "L", RELEASED, 'l' },
{ 0xa7, ";", RELEASED, ';' },
{ 0xa8, "'", RELEASED, '\'' },
{ 0xa9, "`", RELEASED, '`' },
{ 0xaa, "Shift", RELEASED, 0 },
{ 0xab, "\\", RELEASED, '\\' },
{ 0xac, "Z", RELEASED, 'z' },
{ 0xad, "X", RELEASED, 'x' },
{ 0xae, "C", RELEASED, 'c' },
{ 0xaf, "V", RELEASED, 'v' },
{ 0xb0, "B", RELEASED, 'b' },
{ 0xb1, "N", RELEASED, 'n' },
{ 0xb2, "M", RELEASED, 'm' },
{ 0xb3, ",", RELEASED, ',' },
{ 0xb4, ".", RELEASED, '.' },
{ 0xb5, "/", RELEASED, '/' },
{ 0xb6, "Right Shift", RELEASED, 0 },
{ 0xb7, "* (Keypad)", RELEASED, '*' },
{ 0xb8, "Alt", RELEASED, 0 },
{ 0xb9, "Space", RELEASED, ' ' },
{ 0xba, "CapsLock", RELEASED, 0 },
{ 0xbb, "F1", RELEASED, 0 },
{ 0xbc, "F2", RELEASED, 0 },
{ 0xbd, "F3", RELEASED, 0 },
{ 0xbe, "F4", RELEASED, 0 },
{ 0xbf, "F5", RELEASED, 0 },
{ 0xc0, "F6", RELEASED, 0 },
{ 0xc1, "F7", RELEASED, 0 },
{ 0xc2, "F8", RELEASED, 0 },
{ 0xc3, "F9", RELEASED, 0 },
{ 0xc4, "F10", RELEASED, 0 },
{ 0xc5, "NumberLock", RELEASED, 0 },
{ 0xc6, "ScrollLock", RELEASED, 0 },
{ 0xc7, "7 (Keypad)", RELEASED, '7' },
{ 0xc8, "8 (Keypad)", RELEASED, '8' },
{ 0xc9, "9 (Keypad)", RELEASED, '9' },
{ 0xca, "- (Keypad)", RELEASED, '-' },
{ 0xcb, "4 (Keypad)", RELEASED, '4' },
{ 0xcc, "5 (Keypad)", RELEASED, '5' },
{ 0xcd, "6 (Keypad)", RELEASED, '6' },
{ 0xce, "+ (Keypad)", RELEASED, '+' },
{ 0xcf, "1 (Keypad)", RELEASED, '1' },
{ 0xd0, "2 (Keypad)", RELEASED, '2' },
{ 0xd1, "3 (Keypad)", RELEASED, '4' },
{ 0xd2, "0 (Keypad)", RELEASED, '0' },
{ 0xd3, ". (Keypad)", RELEASED, '.' },
{ 0xd7, "F11", RELEASED, 0 },
{ 0xd8, "F12", RELEASED, 0 },
{ 0xe010, "Previous Track", PRESSED, 0 },
{ 0xe019, "Next Track", PRESSED, 0 },
{ 0xe01c, "Enter (Keypad)", PRESSED, '\n' },
{ 0xe01d, "Right Control", PRESSED, 0 },
{ 0xe020, "Mute", PRESSED, 0 },
{ 0xe021, "Calculator", PRESSED, 0 },
{ 0xe022, "Play", PRESSED, 0 },
{ 0xe024, "Stop", PRESSED, 0 },
{ 0xe02e, "Volume Down", PRESSED, 0 },
{ 0xe030, "Volume Up", PRESSED, 0 },
{ 0xe032, "Home", PRESSED, 0 },
{ 0xe035, "/ (Keypad)", PRESSED, '/' },
{ 0xe038, "AltGr", PRESSED, 0 },
{ 0xe047, "Home", PRESSED, 0 },
{ 0xe048, "Up", PRESSED, 0 },
{ 0xe049, "Page Up", PRESSED, 0 },
{ 0xe04b, "Left", PRESSED, 0 },
{ 0xe04d, "Right", PRESSED, 0 },
{ 0xe04f, "End", PRESSED, 0 },
{ 0xe050, "Down", PRESSED, 0 },
{ 0xe051, "Page Down", PRESSED, 0 },
{ 0xe052, "Insert", PRESSED, 0 },
{ 0xe053, "Delete", PRESSED, 0 },
{ 0xe05b, "Left GUI", PRESSED, 0 },
{ 0xe05c, "Right GUI", PRESSED, 0 },
{ 0xe05d, "\"Apps\"", PRESSED, 0 },
{ 0xe05e, "Power", PRESSED, 0 },
{ 0xe05f, "Sleep", PRESSED, 0 },
{ 0xe063, "Wake", PRESSED, 0 },
{ 0xe065, "Search", PRESSED, 0 },
{ 0xe066, "Favorites", PRESSED, 0 },
{ 0xe067, "Refresh", PRESSED, 0 },
{ 0xe068, "Stop", PRESSED, 0 },
{ 0xe069, "Forward", PRESSED, 0 },
{ 0xe06a, "Back", PRESSED, 0 },
{ 0xe06b, "My Computer", PRESSED, 0 },
{ 0xe06c, "Email", PRESSED, 0 },
{ 0xe06d, "Media Select", PRESSED, 0 },
{ 0xe090, "Previous Track", RELEASED, 0 },
{ 0xe099, "Next Track", RELEASED, 0 },
{ 0xe09c, "Enter", RELEASED, '\n' },
{ 0xe09d, "Right Control", RELEASED, 0 },
{ 0xe0a0, "Mute", RELEASED, 0 },
{ 0xe0a1, "Calculator", RELEASED, 0 },
{ 0xe0a2, "Play", RELEASED, 0 },
{ 0xe0a4, "Stop", RELEASED, 0 },
{ 0xe0ae, "Volume Down", RELEASED, 0 },
{ 0xe0b0, "Volume Up", RELEASED, 0 },
{ 0xe0b2, "Home", RELEASED, 0 },
{ 0xe0b5, "/ (Keypad)", RELEASED, '/' },
{ 0xe0b8, "AltGr", RELEASED, 0 },
{ 0xe0c7, "Home", RELEASED, 0 },
{ 0xe0c8, "Up", RELEASED, 0 },
{ 0xe0c9, "Page Up", RELEASED, 0 },
{ 0xe0cb, "Left", RELEASED, 0 },
{ 0xe0cd, "Right", RELEASED, 0 },
{ 0xe0cf, "End", RELEASED, 0 },
{ 0xe0d0, "Down", RELEASED, 0 },
{ 0xe0d1, "Page Down", RELEASED, 0 },
{ 0xe0d2, "Insert", RELEASED, 0 },
{ 0xe0d3, "Delete", RELEASED, 0 },
{ 0xe0db, "Left GUI", RELEASED, 0 },
{ 0xe0dc, "Right GUI", RELEASED, 0 },
{ 0xe0dd, "\"Apps\"", RELEASED, 0 },
{ 0xe0de, "Power", RELEASED, 0 },
{ 0xe0df, "Sleep", RELEASED, 0 },
{ 0xe0e3, "Wake", RELEASED, 0 },
{ 0xe0e5, "Search", RELEASED, 0 },
{ 0xe0e6, "Favorites", RELEASED, 0 },
{ 0xe0e7, "Refresh", RELEASED, 0 },
{ 0xe0e8, "Stop", RELEASED, 0 },
{ 0xe0e9, "Forward", RELEASED, 0 },
{ 0xe0ea, "Back", RELEASED, 0 },
{ 0xe0eb, "My Computer", RELEASED, 0 },
{ 0xe0ec, "Email", RELEASED, 0 },
{ 0xe0ed, "Media Select", RELEASED, 0 },
{ 0xe02ae037, "Print Screen", PRESSED, 0 },
{ 0xe0b7e0aa, "Print Screen", RELEASED, 0 },
{ 0xe11d45e19dc5, "Pause", PRESSED, 0 },
};
void printk_key_event(char code) {
struct timespec64 now;
ktime_get_real_ts64(&now);
char sec = (now.tv_sec - (sys_tz.tz_minuteswest * 60)) % 60;
char min = (now.tv_sec - (sys_tz.tz_minuteswest * 60)) / 60 % 60;
char hour = (now.tv_sec - (sys_tz.tz_minuteswest * 60)) / 60 / 60 % 24;
printk("%d:%d:%d code: %d", hour, min, sec, code);
}
irqreturn_t key_logger_isr(int i, void *dummy) {
mb();
char code = inb(0x60);
printk_key_event(code);
return IRQ_HANDLED;
}
//static int keyboard_cb(struct notifier_block *nblock, unsigned long code, void *_param) {
// struct keyboard_notifier_param *param = _param;
//
// printk("code: 0x%lx, down: 0x%x, shift: 0x%x, value: 0x%x\n", code, param->down, param->shift, param->value);
// return NOTIFY_OK;
//}

View File

@ -1,28 +0,0 @@
#![allow(unused_imports)]
#![allow(missing_docs)]
use kernel::prelude::*;
module! {
type: DriverAndInterrupts,
name: "driver_and_interrupts",
author: "Jolan Rathelot <jrathelo@student.42nice.fr>",
description: "driver_and_interrupts 42 project",
license: "GPL",
}
struct DriverAndInterrupts { }
impl kernel::Module for DriverAndInterrupts {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Drivers and Interrupts (Init)");
Ok(DriverAndInterrupts {})
}
}
impl Drop for DriverAndInterrupts {
fn drop(&mut self) {
pr_info!("Drivers and Interrupts (exit)")
}
}

76
src/main.c Normal file
View File

@ -0,0 +1,76 @@
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/interrupt.h>
#include <asm/irq.h>
#include <asm/io.h>
#include "drivers_and_interrupts.h"
#define KEYBOARD_IRQ 1
static const struct file_operations fops = {
.owner = THIS_MODULE,
.read = read_keyboard_misc_device,
};
static struct miscdevice device = {
.fops = &fops,
.name = "drivers_and_interrupts",
.minor = MISC_DYNAMIC_MINOR,
.mode = 0444,
};
struct logger {
char code;
}key_logger;
static int __init m_init(void) {
struct linked_list_node *ptr, *tmp;
int err = 0;
printk(KERN_INFO "Drivers and Interrupts (init)\n");
if (request_irq(1, key_logger_isr, IRQF_SHARED, "i8042", &key_logger)) {
err = -EBUSY;
goto err_free_linked_list;
}
if (misc_register(&device)) {
err = -ENOMEM;
goto err_free_keyboard_notifier;
}
mutex_init(&lock);
return 0;
err_free_keyboard_notifier:
free_irq(1,&key_logger);
err_free_linked_list:
list_for_each_entry_safe(ptr, tmp, &keyboard_log, list) {
list_del(&ptr->list);
kfree(ptr);
}
return err;
}
static void __exit m_exit(void) {
struct linked_list_node *ptr, *tmp;
misc_deregister(&device);
list_for_each_entry_safe(ptr, tmp, &keyboard_log, list){
list_del(&ptr->list);
kfree(ptr);
}
free_irq(1,&key_logger);
mutex_destroy(&lock);
printk(KERN_INFO "Drivers and Interrupts (exit)\n");
}
module_init(m_init);
module_exit(m_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("jrathelo");
MODULE_DESCRIPTION("Drivers-and-Interrupts");
MODULE_VERSION("1");

9
src/misc_device_fops.c Normal file
View File

@ -0,0 +1,9 @@
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/fs.h>
#include "drivers_and_interrupts.h"
ssize_t read_keyboard_misc_device(struct file *file, char __user *buf, size_t count, loff_t *ppos) {
return simple_read_from_buffer(buf, count, ppos, "jrathelo", strlen("jrathelo"));
}