Sending custom IoControl requests to UMDF sensor driver

Hello,
I am implementing a Sensor driver using the UMDF Framework.
To control some internal stuff I have registered and implemented the EvtSensorDeviceIoControl callback function on the SENSOR_CONTROLLER_CONFIG structure.
From user mode I use a CreateFile() call to get a handle to my UMDF driver, that returns a valid handle as far as I can see.
But when calling the DeviceIoControl() function on that handle, I always get an error 1168 (0x490) returned “ERROR_NOT_FOUND”.

I’am doing it the same way I did it before on a real kernel mode driver; and that worked well.

What might be the problem in my case.
This is how is implemented:

UserMode:

#define PMS_IOCTL_CODE_BASE 0xB00
#define IOCTL_MSG( code ) CTL_CODE(FILE_DEVICE_UNKNOWN, code, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define PMS_IOCTL_ROTATE IOCTL_MSG( MSG_ROTATION )

// Open the sensor device
m_hSensorDevice = CreateFile(L"\\.\RotationSensor",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);


// do device io control
if (m_hSensorDevice)
{
status = DeviceIoControl(
m_hSensorDevice, // Driver handle
PMS_IOCTL_ROTATE, // Control code
&Orintation, // Pointer to input buffer
sizeof(Orintation), // Size of input buffer
NULL, // Pointer to output buffer
0, // Size of output buffer
&BytesReturned, // Required when lpOverlapped is NULL
NULL // Pointer to OVERLAPPED struct for asynchronous I/O
);

UMDF Driver:

#define PMS_IOCTL_CODE_BASE 0xB00
#define IOCTL_MSG( code ) CTL_CODE(FILE_DEVICE_UNKNOWN, code, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define PMS_IOCTL_ROTATE IOCTL_MSG( MSG_ROTATION )

#define DOS_DEVICE_NAME L"\DosDevices\Global\RotationSensor"
DECLARE_CONST_UNICODE_STRING(dosDeviceName, DOS_DEVICE_NAME);

OnDeviceAdd(…)
{

UNICODE_STRING usDeviceName = dosDeviceName;
Status = WdfDeviceCreateSymbolicLink(Device, &usDeviceName);
if (!NT_SUCCESS(Status))
{
TraceError(“PMS0001 %!FUNC! WdfDeviceCreateSymbolicLink failed %! STATUS!”, Status);
}


//
// Register CLX callback function pointers
//
SENSOR_CONTROLLER_CONFIG_INIT(&SensorConfig);
SensorConfig.DriverIsPowerPolicyOwner = WdfUseDefault;

SensorConfig.EvtSensorStart = OnStart;
SensorConfig.EvtSensorStop = OnStop;
SensorConfig.EvtSensorGetSupportedDataFields = OnGetSupportedDataFields;
SensorConfig.EvtSensorGetDataInterval = OnGetDataInterval;
SensorConfig.EvtSensorSetDataInterval = OnSetDataInterval;
SensorConfig.EvtSensorGetDataFieldProperties = OnGetDataFieldProperties;
SensorConfig.EvtSensorGetDataThresholds = OnGetDataThresholds;
SensorConfig.EvtSensorSetDataThresholds = OnSetDataThresholds;
SensorConfig.EvtSensorGetProperties = OnGetProperties;
SensorConfig.EvtSensorDeviceIoControl = OnIoControl;
SensorConfig.EvtSensorStartHistory = OnStartHistory;
SensorConfig.EvtSensorStopHistory = OnStopHistory;
SensorConfig.EvtSensorClearHistory = OnClearHistory;
SensorConfig.EvtSensorStartHistoryRetrieval = OnStartHistoryRetrieval;
SensorConfig.EvtSensorCancelHistoryRetrieval = OnCancelHistoryRetrieval;
Status = SensorsCxDeviceInitialize(Device, &SensorConfig);



}

NTSTATUS OnIoControl( In SENSOROBJECT SensorInstance, // Sensor object
In WDFREQUEST Request, // WDF request object
In size_t OutputBufferLength, // number of bytes to retrieve from output buffer
In size_t InputBufferLength, // number of bytes to retrieve from input buffer
In ULONG IoControlCode // IOCTL control code
)
{
NTSTATUS Status = STATUS_SUCCESS;
PPMS0001Device pDevice = GetContextFromSensorInstance(SensorInstance);
PVOID buffer;
size_t bufSize;

ORIENTATION_TYPE orientation;

SENSOR_FunctionEnter();

if (InputBufferLength != sizeof(ORIENTATION_TYPE))
{
Status = STATUS_UNSUCCESSFUL;
goto Exit;
}

if (OutputBufferLength != sizeof(ORIENTATION_TYPE))
{
Status = STATUS_SUCCESS;
}

Status = WdfRequestRetrieveInputBuffer(Request, sizeof(ORIENTATION_TYPE), &buffer, &bufSize);

orientation = ORIENTATION_TYPE(*(ORIENTATION_TYPE*)buffer);

switch (IoControlCode)
{
case PMS_IOCTL_ROTATE:
pDevice->SetOrientation(orientation);
break;
default: Status = STATUS_UNSUCCESSFUL;
break;
}

Exit:

SENSOR_FunctionExit(Status);
return Status;
}

Any idea what’s wrong when doing DeviceIoControl on UMDF driver?

Best Regards

Thomas.

Hello,

is there anyone who did this before?
I saw that a thread from 2016 had exactly the same issue, but unfortiently no replys at all.

Regards

Thomas.

Have you enabled verbose logging and dumped the log?

That is ALWAYS, ALWAYS, the first step when you get to the “why doesn’t X work in my WDF driver”. Always. Dump the log.

Peter
OSR
@OSRDrivers

(following-up my own post… which is terrible etiquette, sorry)

I spent some time Googling around, cuz I’m sorta kinda interested in the Sensor CLX. It also appears that there’s tracing specific to the Sensor CLX:

https:

So, I’d try that as well… At least it’ll give you some more data.

Peter
OSR
@OSRDrivers</https:>

Since the OnIoControl callback is implemnted on the SensorClassExtension, i fear that using DeviceIoControl is the wrong way.
But I have not found anything on the ISensor interface that let me send an IOControl request to the sensor.

Any clou what TRACE GUID to be used for tracing the DeviceIoControl function call?
I tried nearly everything …

Does that include, or NOT include, dumping the WDF Trace log as I suggested? Because, you know, you didn’t bother to mention it.

The Sensor CLX one? c88b592b-6090-480f-a839-ca2434de5844

Peter
OSR
@OSRDrivers

@Thomas_Schumann: Did you find a solution for the issue?
I am facing the exact issue at the moment.

I am facing the exact issue at the moment.

AND you are necroposting, which isn’t allowed on this forum.

AND you are apparently expecting somebody who posted to this thread five years ago to answer you today.

thread locked.