diff --git a/Controllers/AsusTUFLaptopController/AsusTUFLaptopDetect_Linux.cpp b/Controllers/AsusTUFLaptopController/AsusTUFLaptopDetect_Linux.cpp index 71e05a2ed..cff1d94a4 100644 --- a/Controllers/AsusTUFLaptopController/AsusTUFLaptopDetect_Linux.cpp +++ b/Controllers/AsusTUFLaptopController/AsusTUFLaptopDetect_Linux.cpp @@ -36,3 +36,5 @@ DetectedControllers DetectAsusTUFLaptopLinuxControllers() } REGISTER_DETECTOR("ASUS TUF Laptop", DetectAsusTUFLaptopLinuxControllers); + +REGISTER_CUSTOM_UDEV_RULE(asus_wmi, "ASUS TUF Laptops (asus-wmi)", "ACTION==\"add\", SUBSYSTEM==\"leds\", KERNEL==\"asus::kbd_backlight\", RUN+=\"/usr/bin/env chmod a+w /sys%p/kbd_rgb_mode\"\nACTION==\"add\", SUBSYSTEM==\"leds\", KERNEL==\"asus::kbd_backlight\", RUN+=\"/usr/bin/env chmod a+w /sys%p/brightness\""); diff --git a/Controllers/FaustusController/RGBController_Faustus_Linux.cpp b/Controllers/FaustusController/RGBController_Faustus_Linux.cpp index 73b6bb632..7bcaf10c6 100644 --- a/Controllers/FaustusController/RGBController_Faustus_Linux.cpp +++ b/Controllers/FaustusController/RGBController_Faustus_Linux.cpp @@ -197,3 +197,5 @@ DetectedControllers DetectFaustusControllers() } REGISTER_DETECTOR("Faustus", DetectFaustusControllers); + +REGISTER_CUSTOM_UDEV_RULE(faustus, "ASUS TUF Laptops (faustus)", "ACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_blue\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_flags\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_green\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_mode\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_red\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_set\"\nACTION==\"add\", SUBSYSTEM==\"platform\", KERNEL==\"faustus\", RUN+=\"/usr/bin/env chmod a+w /sys/bus/platform/devices/%k/kbbl/kbbl_speed\""); diff --git a/Controllers/LogitechController/LogitechControllerDetect.cpp b/Controllers/LogitechController/LogitechControllerDetect.cpp index e4b1504a6..676846ea9 100644 --- a/Controllers/LogitechController/LogitechControllerDetect.cpp +++ b/Controllers/LogitechController/LogitechControllerDetect.cpp @@ -1711,6 +1711,8 @@ REGISTER_HID_DETECTOR_P_ONLY ("Logitech HID++ 2.0", DetectLogitechHIDPP20, 0xFF REGISTER_HID_DETECTOR_IP_ONLY ("Logitech HID++ 2.0", DetectLogitechHIDPP20, 1, 0xFF00); REGISTER_HID_DETECTOR_PU_ONLY ("Logitech HID++ 2.0", DetectLogitechHIDPP20, 0xFFA0, 1); +REGISTER_CUSTOM_UDEV_RULE(logitech_hidpp20, "Logitech HID++ 2.0", "SUBSYSTEM==\"hidraw\", ATTRS{idVendor}==\"046d\", TAG+=\"uaccess\", TAG+=\"Logitech_HID_20\"\nSUBSYSTEM==\"usb\", ATTR{idVendor}==\"046d\", TAG+=\"uaccess\", TAG+=\"Logitech_HID_20\""); + /*-------------------------------------------------------------------------------------------------------------------------------------------------*\ | Keyboards | \*-------------------------------------------------------------------------------------------------------------------------------------------------*/ diff --git a/Controllers/ValveSteamMachineController/ValveSteamMachineControllerDetect_Linux.cpp b/Controllers/ValveSteamMachineController/ValveSteamMachineControllerDetect_Linux.cpp index 6d0a62515..4f8d0a545 100644 --- a/Controllers/ValveSteamMachineController/ValveSteamMachineControllerDetect_Linux.cpp +++ b/Controllers/ValveSteamMachineController/ValveSteamMachineControllerDetect_Linux.cpp @@ -139,4 +139,6 @@ DetectedControllers DetectValveSteamMachineControllers() return(detected_controllers); } -REGISTER_DETECTOR("Valve Steam Machine", DetectValveSteamMachineControllers); \ No newline at end of file +REGISTER_DETECTOR("Valve Steam Machine", DetectValveSteamMachineControllers); + +REGISTER_CUSTOM_UDEV_RULE(valve_steam, "Valve Steam Machine", "SUBSYSTEM==\"leds\", KERNEL==\"valve-leds[0-9]*\", TAG+=\"uaccess\""); \ No newline at end of file diff --git a/DetectionManager.cpp b/DetectionManager.cpp index cc117ff32..131914981 100644 --- a/DetectionManager.cpp +++ b/DetectionManager.cpp @@ -350,6 +350,21 @@ void DetectionManager::RegisterPreDetectionHook(PreDetectionHookFunction hook) pre_detection_hooks.push_back(hook); } +#ifdef __linux__ +/*---------------------------------------------------------*\ +| Custom Udev Rules Registration Function | +\*---------------------------------------------------------*/ +void DetectionManager::RegisterCustomUdevRule(std::string name, std::string rule) +{ + CustomUdevRuleBlock block; + + block.name = name; + block.rule = rule; + + custom_udev_rules.push_back(block); +} +#endif + /*---------------------------------------------------------*\ | Detection Callback Registration Functions | \*---------------------------------------------------------*/ @@ -2168,6 +2183,18 @@ bool DetectionManager::GenerateUdevRules(const std::string& filepath) fprintf(output_file, "\n"); } + /*-----------------------------------------------------*\ + | Write custom udev rules | + \*-----------------------------------------------------*/ + for(const CustomUdevRuleBlock& custom_rule : custom_udev_rules) + { + fprintf(output_file, "#---------------------------------------------------------------#\n"); + fprintf(output_file, "# %s\n", custom_rule.name.c_str()); + fprintf(output_file, "#---------------------------------------------------------------#\n"); + fprintf(output_file, "%s\n", custom_rule.rule.c_str()); + fprintf(output_file, "\n"); + } + fclose(output_file); LOG_INFO("[%s] Successfully generated udev rules file: %s", DETECTIONMANAGER, filepath.c_str()); diff --git a/DetectionManager.h b/DetectionManager.h index 7e515b49d..d11397092 100644 --- a/DetectionManager.h +++ b/DetectionManager.h @@ -105,6 +105,12 @@ typedef struct uint8_t dram_type; } I2CDRAMDeviceDetectorBlock; +typedef struct +{ + std::string name; + std::string rule; +} CustomUdevRuleBlock; + /*---------------------------------------------------------*\ | Detection Callback Type | \*---------------------------------------------------------*/ @@ -177,6 +183,13 @@ public: \*-----------------------------------------------------*/ void RegisterPreDetectionHook(PreDetectionHookFunction hook); +#ifdef __linux__ + /*-----------------------------------------------------*\ + | Custom Udev Rules Registration Function | + *------------------------------------------------------*/ + void RegisterCustomUdevRule(std::string name, std::string rule); +#endif + /*-----------------------------------------------------*\ | Detection Callback Registration Functions | \*-----------------------------------------------------*/ @@ -248,6 +261,10 @@ private: std::vector dynamic_detector_strings; std::vector pre_detection_hooks; +#ifdef __linux__ + std::vector custom_udev_rules; +#endif + #ifdef __linux__ #ifdef __GLIBC__ /*-----------------------------------------------------*\ @@ -459,6 +476,20 @@ public: } }; +class CustomUdevRule +{ +public: + CustomUdevRule(std::string name, std::string rule) + { +#ifdef __linux__ + DetectionManager::get()->RegisterCustomUdevRule(name, rule); +#else + (void)name; + (void)rule; +#endif + } +}; + /*---------------------------------------------------------*\ | Detector Registration Macros | \*---------------------------------------------------------*/ @@ -500,3 +531,5 @@ public: #define REGISTER_DYNAMIC_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage) #define REGISTER_DYNAMIC_HID_DETECTOR_P(name, func, vid, pid, page) HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY) #define REGISTER_DYNAMIC_HID_DETECTOR_PU(name, func, vid, pid, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage) + +#define REGISTER_CUSTOM_UDEV_RULE(id, name, rule) static CustomUdevRule device_detector_obj_##id(name, rule)