From c092780bf371d962a98165f1740e9bc0feb242bc Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 17 Jul 2024 17:54:35 +0300 Subject: [PATCH 01/12] Added signing section to the README --- README.md | 4 +++- docs/SIGNING.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 docs/SIGNING.md diff --git a/README.md b/README.md index 4a03d21..c3a91c4 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ And that's basically it ## How to use this driver? You can install it through AUR package, through DKMS or manually. +On SecureBoot enabled systems you will need additional steps for load this driver into the system. See [Signing](docs/SIGNING.md#signing) + ### AUR package There's an [AUR package](https://aur.archlinux.org/packages/universal-ff-dkms-git) for Arch Linux maintained by [@Lawstorant](https://github.com/Lawstorant). @@ -57,7 +59,7 @@ Best for debugging purposes, where you need frequently change codebase/branches 4. Load module into system with `sudo insmod hid-universal-pidff.ko` To unload module: -`sudo rmmod hid_universal_pidff` +`sudo rmmod hid_universal_pidff`' ## How to set up a base parameters? ### MOZA diff --git a/docs/SIGNING.md b/docs/SIGNING.md new file mode 100644 index 0000000..554e27d --- /dev/null +++ b/docs/SIGNING.md @@ -0,0 +1,48 @@ + +# Signing + +## Signing module for SecureBoot +Latest kernels forbid loading custom kernel modules into the system with SecureBoot enabled. + +For SecureBoot enabled system you have a choice: +1. Disable SecureBoot in your UEFI/BIOS +2. Use generated Machine Owner Key from DKMS (supports automatic signing) +3. Create Machine Owner Key and load it into your UEFI/BIOS, and sign kernel module with it. + +### Using DKMS MOK key +MOK private key and certificates are generated the first time DKMS is run. You just need to import it to your system. +``` +# Check if keys are present in default path +ls -al /var/lib/dkms/mok* + +# Enroll keys into system +sudo mokutil --import /var/lib/dkms/mok.pub +``` +You need to reboot your PC after that, you will be greated with blue screen dialog. +Choose "Enroll MOK", then "Continue" and "Yes". After that choose "Reboot system". + +Now DKMS should sign updated modules automatically as they updated. + +[Reference](https://github.com/dell/dkms/blob/master/README.md#module-signing) + +### Manually create MOK key and manually sign kernel module +``` +# This creates Machine Owner Key +openssl req -new -x509 -newkey rsa:2048 -keyout mok.key -outform DER -out mok.pub -nodes -days 36500 -subj "/CN=$hostname kernel module signing key/" + +# This loads it into UEFI +sudo mokutil --import mok.pub +``` + +You need to reboot your PC after that, you will be greated with blue screen dialog +Choose "Enroll MOK", enter your MOK password if exists, then "Continue", "Yes", and then reboot your system. + +After that you can manually sign your built kernel module like so (feel free to adjust paths to keys/certificate/modules): +``` +sudo /usr/src/linux-headers-$(uname -r)/scripts/sign-file sha256 mok.key mok.pub hid-universal-pidff.ko +``` + +Then you should be able to load driver like so: +``` +sudo insmod hid-universal-pidff.ko +``` \ No newline at end of file From d2585bcf170affdb89fbc3100ffc97604b09f7ad Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 17 Jul 2024 17:55:47 +0300 Subject: [PATCH 02/12] Small change to README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3a91c4..c2447f5 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ And that's basically it ## How to use this driver? You can install it through AUR package, through DKMS or manually. -On SecureBoot enabled systems you will need additional steps for load this driver into the system. See [Signing](docs/SIGNING.md#signing) +On SecureBoot enabled systems you will need additional steps for load this driver into the system. See [Signing](docs/SIGNING.md#signing) section. ### AUR package There's an [AUR package](https://aur.archlinux.org/packages/universal-ff-dkms-git) for Arch Linux maintained by [@Lawstorant](https://github.com/Lawstorant). From 3ff83db322762f70a50f6d79b7b92dbf082f0bc0 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 17 Jul 2024 17:56:17 +0300 Subject: [PATCH 03/12] We need to *install* driver, not *use* it --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c2447f5..8408826 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ And that's basically it 2. `Firmware Update` function. Use Windows PC or Windows VM at the moment. 3. Setup through proprietary software. May require [some tweaking](#how-to-set-up-a-base-parameters)) -## How to use this driver? +## How to install this driver? You can install it through AUR package, through DKMS or manually. On SecureBoot enabled systems you will need additional steps for load this driver into the system. See [Signing](docs/SIGNING.md#signing) section. From 34d6d6b2949f4f6613c1da54ffc807fb5f2e32f3 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 17 Jul 2024 18:19:22 +0300 Subject: [PATCH 04/12] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8408826..645efa8 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Best for debugging purposes, where you need frequently change codebase/branches 4. Load module into system with `sudo insmod hid-universal-pidff.ko` To unload module: -`sudo rmmod hid_universal_pidff`' +`sudo rmmod hid_universal_pidff` ## How to set up a base parameters? ### MOZA From b58aee44034be5051b87df6ac7a7466ed9663169 Mon Sep 17 00:00:00 2001 From: Oleg Date: Wed, 17 Jul 2024 18:19:58 +0300 Subject: [PATCH 05/12] Only unsigned modules affected --- docs/SIGNING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/SIGNING.md b/docs/SIGNING.md index 554e27d..47fb0d5 100644 --- a/docs/SIGNING.md +++ b/docs/SIGNING.md @@ -2,7 +2,7 @@ # Signing ## Signing module for SecureBoot -Latest kernels forbid loading custom kernel modules into the system with SecureBoot enabled. +Latest kernels forbid loading unsigned custom kernel modules into the system with SecureBoot enabled. For SecureBoot enabled system you have a choice: 1. Disable SecureBoot in your UEFI/BIOS From 38c629829f380fcfa49d82524de459ae97aadcf0 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 18 Jul 2024 06:11:49 +0300 Subject: [PATCH 06/12] Fix spelling --- docs/SIGNING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/SIGNING.md b/docs/SIGNING.md index 47fb0d5..f3f2764 100644 --- a/docs/SIGNING.md +++ b/docs/SIGNING.md @@ -18,7 +18,7 @@ ls -al /var/lib/dkms/mok* # Enroll keys into system sudo mokutil --import /var/lib/dkms/mok.pub ``` -You need to reboot your PC after that, you will be greated with blue screen dialog. +You need to reboot your PC after that, you will be greeted with blue screen dialog. Choose "Enroll MOK", then "Continue" and "Yes". After that choose "Reboot system". Now DKMS should sign updated modules automatically as they updated. @@ -34,7 +34,7 @@ openssl req -new -x509 -newkey rsa:2048 -keyout mok.key -outform DER -out mok.pu sudo mokutil --import mok.pub ``` -You need to reboot your PC after that, you will be greated with blue screen dialog +You need to reboot your PC after that, you will be greeted with blue screen dialog Choose "Enroll MOK", enter your MOK password if exists, then "Continue", "Yes", and then reboot your system. After that you can manually sign your built kernel module like so (feel free to adjust paths to keys/certificate/modules): From bfbdb9620e61c130f02f29c2670804af13f41b3d Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 19 Jul 2024 11:55:35 +0300 Subject: [PATCH 07/12] Update information about key path --- docs/SIGNING.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/SIGNING.md b/docs/SIGNING.md index f3f2764..65c0b94 100644 --- a/docs/SIGNING.md +++ b/docs/SIGNING.md @@ -11,12 +11,23 @@ For SecureBoot enabled system you have a choice: ### Using DKMS MOK key MOK private key and certificates are generated the first time DKMS is run. You just need to import it to your system. + +The location as well can be changed by setting the appropriate variables in /etc/dkms/framework.conf. For example, to allow usage of the system default Ubuntu update-secureboot-policy set the configuration file as follows: ``` -# Check if keys are present in default path +mok_signing_key="/var/lib/shim-signed/mok/MOK.priv" +mok_certificate="/var/lib/shim-signed/mok/MOK.der" +``` + +``` +# Find where keys are on your distro ls -al /var/lib/dkms/mok* +# OR (on Ubuntu) +ls -al /var/lib/shim-signed/mok/MOK* # Enroll keys into system sudo mokutil --import /var/lib/dkms/mok.pub +# OR (on Ubuntu) +sudo mokutil --import /var/lib/shim-signed/mok/MOK.der ``` You need to reboot your PC after that, you will be greeted with blue screen dialog. Choose "Enroll MOK", then "Continue" and "Yes". After that choose "Reboot system". From 8220bbbfb086f26aab8ac9bb3fa1e4c602583c0c Mon Sep 17 00:00:00 2001 From: Lawstorant Date: Fri, 26 Jul 2024 23:28:57 +0200 Subject: [PATCH 08/12] Rework envelope checks to fix FFB for Moza Only set envelopes when they are needed (any value is != 0). This fixes Moza FFB in games that use Sine effect to emulate constant force. Remove FIX_PERIODIC_ENVELOPE quirk as it's no longer needed --- hid-pidff-wrapper.c | 10 +++++----- hid-pidff.c | 38 +++++++++++++++++--------------------- hid-pidff.h | 14 ++++---------- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/hid-pidff-wrapper.c b/hid-pidff-wrapper.c index 5ebdbda..bc019a9 100644 --- a/hid-pidff-wrapper.c +++ b/hid-pidff-wrapper.c @@ -14,15 +14,15 @@ static const struct hid_device_id pidff_wheel_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3), - .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE }, + .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5), - .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE }, + .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9), - .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE }, + .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12), - .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE }, + .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, { HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21), - .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE }, + .driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION }, { HID_USB_DEVICE(USB_VENDOR_ID_CAMMUS, USB_DEVICE_ID_CAMMUS_C5), .driver_data = PIDFF_QUIRK_NO_DELAY_EFFECT }, { } diff --git a/hid-pidff.c b/hid-pidff.c index 5bb858f..22e4b9b 100644 --- a/hid-pidff.c +++ b/hid-pidff.c @@ -311,6 +311,14 @@ static void pidff_set_envelope_report(struct pidff_device *pidff, static int pidff_needs_set_envelope(struct ff_envelope *envelope, struct ff_envelope *old) { + if (!old) { + return envelope->attack_level != 0 || + envelope->fade_level != 0 || + envelope->attack_length != 0 || + envelope->fade_length != 0; + + } + return envelope->attack_level != old->attack_level || envelope->fade_level != old->fade_level || envelope->attack_length != old->attack_length || @@ -406,8 +414,8 @@ static void pidff_set_periodic_report(struct pidff_device *pidff, // Actually we just can use clamp macro // from include/linux/kernel.h#L59 // But for the debug purposes we're leaving it as is - pidff->set_periodic[PID_PERIOD].value[0] = - pidff_clamp(effect->u.periodic.period, + pidff->set_periodic[PID_PERIOD].value[0] = + pidff_clamp(effect->u.periodic.period, pidff->set_periodic[PID_PERIOD].field); hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC], @@ -643,9 +651,8 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_constant(effect, old)) pidff_set_constant_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.constant.envelope, - &old->u.constant.envelope)) + if (pidff_needs_set_envelope(&effect->u.constant.envelope, + old ? &old->u.periodic.envelope : NULL)) pidff_set_envelope_report(pidff, &effect->u.constant.envelope); break; @@ -683,19 +690,8 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, if (!old || pidff_needs_set_periodic(effect, old)) pidff_set_periodic_report(pidff, effect); - if (pidff->quirks & PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE) - { - effect->u.periodic.envelope.attack_level = - effect->u.periodic.envelope.attack_level == 0 - ? 0x7fff : effect->u.periodic.envelope.attack_level; - - effect->u.periodic.envelope.fade_level = - effect->u.periodic.envelope.fade_level == 0 - ? 0x7fff : effect->u.periodic.envelope.fade_level; - } - if (!old || - pidff_needs_set_envelope(&effect->u.periodic.envelope, - &old->u.periodic.envelope)) + if (pidff_needs_set_envelope(&effect->u.periodic.envelope, + old ? &old->u.periodic.envelope : NULL)) pidff_set_envelope_report(pidff, &effect->u.periodic.envelope); break; @@ -711,9 +707,9 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, pidff_set_effect_report(pidff, effect); if (!old || pidff_needs_set_ramp(effect, old)) pidff_set_ramp_force_report(pidff, effect); - if (!old || - pidff_needs_set_envelope(&effect->u.ramp.envelope, - &old->u.ramp.envelope)) + + if (pidff_needs_set_envelope(&effect->u.ramp.envelope, + old ? &old->u.periodic.envelope : NULL)) pidff_set_envelope_report(pidff, &effect->u.ramp.envelope); break; diff --git a/hid-pidff.h b/hid-pidff.h index 5009cc9..e9b504e 100644 --- a/hid-pidff.h +++ b/hid-pidff.h @@ -4,21 +4,15 @@ /* PIDFF Quirks to solve issues with certain devices */ -/* - * Always set a value > 0 for PERIODIC envelope attack and fade level -*/ -#define PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE BIT(0) - /* * Ignore direction and always set 16384 (0x4000) -*/ -#define PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(1) + */ +#define PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(0) /* * Skip initialization of 0xA7 descriptor (Delay effect) -*/ -#define PIDFF_QUIRK_NO_DELAY_EFFECT BIT(2) - + */ +#define PIDFF_QUIRK_NO_DELAY_EFFECT BIT(1) int hid_pidff_init_quirks(struct hid_device *hid, const struct hid_device_id *id); From 241a25cee9cd56ad83b73495060e6311f603fb84 Mon Sep 17 00:00:00 2001 From: Lawstorant Date: Sat, 27 Jul 2024 00:12:07 +0200 Subject: [PATCH 09/12] Fix AUR package URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 645efa8..1d1f5d4 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ You can install it through AUR package, through DKMS or manually. On SecureBoot enabled systems you will need additional steps for load this driver into the system. See [Signing](docs/SIGNING.md#signing) section. ### AUR package -There's an [AUR package](https://aur.archlinux.org/packages/universal-ff-dkms-git) for Arch Linux maintained by [@Lawstorant](https://github.com/Lawstorant). +There's an [AUR package](https://aur.archlinux.org/packages/universal-pidff-dkms-git) for Arch Linux maintained by [@Lawstorant](https://github.com/Lawstorant). ### DKMS DKMS will install module into system, and will update it every time you update your kernel. Module will persist after reboots. It's the preferrable way to install it on the most distros. From f8e9545f39ba9ec636c1621552a919685455df4b Mon Sep 17 00:00:00 2001 From: Lawstorant Date: Sat, 27 Jul 2024 00:12:07 +0200 Subject: [PATCH 10/12] Fix AUR package URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 645efa8..1d1f5d4 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ You can install it through AUR package, through DKMS or manually. On SecureBoot enabled systems you will need additional steps for load this driver into the system. See [Signing](docs/SIGNING.md#signing) section. ### AUR package -There's an [AUR package](https://aur.archlinux.org/packages/universal-ff-dkms-git) for Arch Linux maintained by [@Lawstorant](https://github.com/Lawstorant). +There's an [AUR package](https://aur.archlinux.org/packages/universal-pidff-dkms-git) for Arch Linux maintained by [@Lawstorant](https://github.com/Lawstorant). ### DKMS DKMS will install module into system, and will update it every time you update your kernel. Module will persist after reboots. It's the preferrable way to install it on the most distros. From bc87313267cb6fb7cbfbbfb43a220dd52bc1bdab Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 8 Aug 2024 03:00:27 +0300 Subject: [PATCH 11/12] Fix alignment on hid-ids.h --- hid-ids.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hid-ids.h b/hid-ids.h index bc39628..8261c48 100644 --- a/hid-ids.h +++ b/hid-ids.h @@ -2,7 +2,7 @@ #ifndef __HID_IDS_H #define __HID_IDS_H -#define USB_VENDOR_ID_MOZA 0x346e +#define USB_VENDOR_ID_MOZA 0x346e #define USB_DEVICE_ID_MOZA_R3 0x0005 #define USB_DEVICE_ID_MOZA_R5 0x0004 #define USB_DEVICE_ID_MOZA_R9 0x0002 From 3d19599175825b659b1b4e9658e1e9884927b571 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 8 Aug 2024 03:02:21 +0300 Subject: [PATCH 12/12] Bump dkms package_version --- dkms.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkms.conf b/dkms.conf index aebd3b5..378a2cf 100644 --- a/dkms.conf +++ b/dkms.conf @@ -1,5 +1,5 @@ PACKAGE_NAME="universal-pidff" -PACKAGE_VERSION="0.0.3" +PACKAGE_VERSION="0.0.6" MAKE[0]="make KVERSION=$kernelver" CLEAN="make clean" BUILT_MODULE_NAME[0]="hid-universal-pidff"