From c2ee8c058311b7ce8c463ff46627963a5a865a96 Mon Sep 17 00:00:00 2001 From: icex2 Date: Fri, 19 Mar 2021 12:41:31 +0100 Subject: [PATCH] patch/piuio-exit: Bugfix when using with more usb devices than just piuio If you also have the piubtn connected, it will be opened as well, hitting the open section in the module. It did forward everything correctly, but the warning didn't make any sense because the same device was not opened again. Re-work the code to create a meaningful flow. Also return the open handle if it ever happens that the device gets re-opened without being closed. --- src/main/hook/patch/piuio-exit.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/hook/patch/piuio-exit.c b/src/main/hook/patch/piuio-exit.c index 1ddd8eb..851c13d 100644 --- a/src/main/hook/patch/piuio-exit.c +++ b/src/main/hook/patch/piuio-exit.c @@ -26,20 +26,22 @@ static enum cnh_result patch_piuio_exit_usbhook(struct cnh_usbhook_irp *irp) switch (irp->op) { case CNH_USBHOOK_IRP_OP_OPEN: { - if (_patch_piuio_exit_usb_handle) { - log_warn("Already detected PIUIO previously, ignore re-detection?"); - result = cnh_usbhook_invoke_next(irp); - break; - } - if (irp->open_usb_dev->descriptor.idVendor == PIUIO_DRV_VID && irp->open_usb_dev->descriptor.idProduct == PIUIO_DRV_PID) { - log_info("Detected PIUIO"); - result = cnh_usbhook_invoke_next(irp); + if (_patch_piuio_exit_usb_handle) { + log_warn("Already detected PIUIO previously, ignore re-detection?"); - if (result == CNH_RESULT_SUCCESS) { - _patch_piuio_exit_usb_handle = irp->handle; + irp->handle = _patch_piuio_exit_usb_handle; + result = CNH_RESULT_SUCCESS; + } else { + log_info("Detected PIUIO"); + + result = cnh_usbhook_invoke_next(irp); + + if (result == CNH_RESULT_SUCCESS) { + _patch_piuio_exit_usb_handle = irp->handle; + } } } else { result = cnh_usbhook_invoke_next(irp);