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.