Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Sending custom IoControl requests to UMDF sensor driver

Thomas_SchumannThomas_Schumann Member - All Emails Posts: 3
edited March 2 in NTDEV
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.
Post edited by Peter_Viscarola_(OSR) on

Comments

  • Thomas_SchumannThomas_Schumann Member - All Emails Posts: 3
    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.
  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,133
    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

    Peter Viscarola
    OSR
    @OSRDrivers

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,133
    (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://docs.microsoft.com/en-us/windows-hardware/drivers/sensors/collecting-and-decoding-wpp-logs&gt;

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

    Peter
    OSR
    @OSRDrivers

    Peter Viscarola
    OSR
    @OSRDrivers

  • Thomas_SchumannThomas_Schumann Member - All Emails Posts: 3
    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 ...
  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,133
    <quote>
    I tried nearly everything ...
    </quote>

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

    <quote>
    Any clou what TRACE GUID to be used
    </quote>

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

    Peter
    OSR
    @OSRDrivers

    Peter Viscarola
    OSR
    @OSRDrivers

  • ChandraTutikaChandraTutika Member Posts: 13

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

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,133

    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.

    Peter Viscarola
    OSR
    @OSRDrivers

This discussion has been closed.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 26 Feb - 1 Mar 2024 Live, Online