summaryrefslogtreecommitdiff
path: root/driver/driver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'driver/driver.cpp')
-rw-r--r--driver/driver.cpp88
1 files changed, 46 insertions, 42 deletions
diff --git a/driver/driver.cpp b/driver/driver.cpp
index 778f3be..a99a70b 100644
--- a/driver/driver.cpp
+++ b/driver/driver.cpp
@@ -1,10 +1,9 @@
#include <rawaccel.hpp>
+#include <rawaccel-io-def.h>
+#include <rawaccel-version.h>
#include "driver.h"
-#define RA_READ CTL_CODE(0x8888, 0x888, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
-#define RA_WRITE CTL_CODE(0x8888, 0x889, METHOD_BUFFERED, FILE_ANY_ACCESS)
-
#ifdef ALLOC_PRAGMA
#pragma alloc_text (INIT, DriverEntry)
#pragma alloc_text (PAGE, EvtDeviceAdd)
@@ -144,70 +143,75 @@ Return Value:
{
NTSTATUS status;
void* buffer;
- size_t size;
UNREFERENCED_PARAMETER(Queue);
-
-
+ UNREFERENCED_PARAMETER(OutputBufferLength);
+ UNREFERENCED_PARAMETER(InputBufferLength);
PAGED_CODE();
DebugPrint(("Ioctl received into filter control object.\n"));
- if (IoControlCode == RA_WRITE && InputBufferLength == sizeof(ra::settings)) {
- LARGE_INTEGER interval;
- interval.QuadPart = static_cast<LONGLONG>(ra::WRITE_DELAY) * -10000;
- KeDelayExecutionThread(KernelMode, FALSE, &interval);
-
+ switch (IoControlCode) {
+ case RA_READ:
+ status = WdfRequestRetrieveOutputBuffer(
+ Request,
+ sizeof(ra::settings),
+ &buffer,
+ NULL
+ );
+ if (!NT_SUCCESS(status)) {
+ DebugPrint(("RetrieveOutputBuffer failed: 0x%x\n", status));
+ }
+ else {
+ *reinterpret_cast<ra::settings*>(buffer) = global.args;
+ }
+ break;
+ case RA_WRITE:
status = WdfRequestRetrieveInputBuffer(
Request,
sizeof(ra::settings),
&buffer,
- &size
+ NULL
);
-
if (!NT_SUCCESS(status)) {
DebugPrint(("RetrieveInputBuffer failed: 0x%x\n", status));
- // status maps to win32 error code 1359: ERROR_INTERNAL_ERROR
- WdfRequestComplete(Request, STATUS_MESSAGE_LOST);
- return;
}
+ else {
+ LARGE_INTEGER interval;
+ interval.QuadPart = static_cast<LONGLONG>(ra::WRITE_DELAY) * -10000;
+ KeDelayExecutionThread(KernelMode, FALSE, &interval);
- ra::settings new_settings = *reinterpret_cast<ra::settings*>(buffer);
+ ra::settings new_settings = *reinterpret_cast<ra::settings*>(buffer);
- if (new_settings.time_min <= 0 || _isnanf(static_cast<float>(new_settings.time_min))) {
- new_settings.time_min = ra::settings{}.time_min;
- }
-
- global.args = new_settings;
- global.modifier = { global.args, global.lookups };
+ if (new_settings.time_min <= 0 || _isnanf(static_cast<float>(new_settings.time_min))) {
+ new_settings.time_min = ra::settings{}.time_min;
+ }
- WdfRequestComplete(Request, STATUS_SUCCESS);
- }
- else if (IoControlCode == RA_READ && OutputBufferLength == sizeof(ra::settings)) {
+ global.args = new_settings;
+ global.modifier = { global.args, global.lookups };
+ }
+ break;
+ case RA_GET_VERSION:
status = WdfRequestRetrieveOutputBuffer(
Request,
- sizeof(ra::settings),
+ sizeof(ra::version_t),
&buffer,
- &size
+ NULL
);
-
if (!NT_SUCCESS(status)) {
DebugPrint(("RetrieveOutputBuffer failed: 0x%x\n", status));
- // status maps to win32 error code 1359: ERROR_INTERNAL_ERROR
- WdfRequestComplete(Request, STATUS_MESSAGE_LOST);
- return;
}
-
- *reinterpret_cast<ra::settings*>(buffer) = global.args;
-
- WdfRequestComplete(Request, STATUS_SUCCESS);
- }
- else {
- DebugPrint(("Received unknown request: in %uB, out %uB\n", InputBufferLength, OutputBufferLength));
- // status maps to win32 error code 1784: ERROR_INVALID_USER_BUFFER
- WdfRequestComplete(Request, STATUS_INVALID_BUFFER_SIZE);
+ else {
+ *reinterpret_cast<ra::version_t*>(buffer) = { RA_VER_MAJOR, RA_VER_MINOR, RA_VER_PATCH };
+ }
+ break;
+ default:
+ status = STATUS_INVALID_DEVICE_REQUEST;
+ break;
}
+ WdfRequestComplete(Request, status);
+
}
#pragma warning(pop) // enable 28118 again
@@ -404,7 +408,7 @@ Error:
WdfObjectDelete(controlDevice);
}
- DebugPrint(("CreateControlDevice failed\n", status));
+ DebugPrint(("CreateControlDevice failed with status code 0x%x\n", status));
}