DEviceiocontrol not calling IRP_MJ_DEVICE_CONTROL

I tried to use DeviceIOControl function to call an IOCTL in IRP_MJ_DEVICE_CONTROL. It is not getting called. In the user application DeviceIOControl return The Parameter not correct error.

Any idea?

You have an invalid param to the DeviceIoControl call that the upper layers
detect so never send it to the driver, a common case is having a null
lpBytesReturned pointer, but it could be a lot of things.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

wrote in message news:xxxxx@ntdev…
>I tried to use DeviceIOControl function to call an IOCTL in
>IRP_MJ_DEVICE_CONTROL. It is not getting called. In the user application
>DeviceIOControl return The Parameter not correct error.
>
> Any idea?
>

Do you have IRP_MJ_CREATE handler? Is it called? Does it return success?

Thomas F. Divine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-301341-
xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, September 25, 2007 9:33 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] DEviceiocontrol not calling IRP_MJ_DEVICE_CONTROL

I tried to use DeviceIOControl function to call an IOCTL in
IRP_MJ_DEVICE_CONTROL. It is not getting called. In the user
application DeviceIOControl return The Parameter not correct error.

Any idea?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I just yanked this out of the DDK sample code general\ioctl\testapp.c.
This is how it should look

bRc = DeviceIoControl ( hDevice,
(DWORD) IOCTL_SIOCTL_METHOD_BUFFERED,
&InputBuffer,
strlen ( InputBuffer )+1,
&OutputBuffer,
sizeof( OutputBuffer),
&bytesReturned,
NULL
);

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: Tuesday, September 25, 2007 6:40 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DEviceiocontrol not calling IRP_MJ_DEVICE_CONTROL

You have an invalid param to the DeviceIoControl call that the upper
layers
detect so never send it to the driver, a common case is having a null
lpBytesReturned pointer, but it could be a lot of things.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

wrote in message news:xxxxx@ntdev…
>I tried to use DeviceIOControl function to call an IOCTL in
>IRP_MJ_DEVICE_CONTROL. It is not getting called. In the user
application
>DeviceIOControl return The Parameter not correct error.
>
> Any idea?
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

This doesn’t tell us anything, even assuming that you are using IOCTL unmodified, which presumably you are not. You need to post your actual code for the application.

Thank you for the response. Please find below my code sample here.

I use the DeviceIOControl as follows

void Ctrl2Hardware::Initial(short pBaseAddress)
{
ASSERT(m_nhDevice != INVALID_HANDLE_VALUE);
unsigned long nOutput = 0;
if(!DeviceIoControl(m_nhDevice,
IOCTL_INITIAL,
&pBaseAddress,
sizeof(short),
NULL,
0,
&nOutput,
NULL )
) {
CString errMessage;
GetLastErrorMessage(errMessage);
TRACE(“Initial : DeviceIoControl returns %s \n”,errMessage);
}
}

My driver sample code is here.

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT pDriverObject,
IN PUNICODE_STRING strRegistryPath
)
{
UNREFERENCED_PARAMETER (strRegistryPath);

DebugPrint ((“Driver Entry\n”));

pDriverObject->MajorFunction[IRP_MJ_CREATE] = SmartPCICreate;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] = SmartPCIClose;
pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = SmartPCIDispatch;
pDriverObject->MajorFunction[IRP_MJ_PNP] = SmartPCIDispatchPnp;
pDriverObject->MajorFunction[IRP_MJ_POWER] = SmartPCIDispatchPower;
pDriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = SmartPCIDispatchSystemControl;
pDriverObject->DriverExtension->AddDevice = SmartPCIAddDevice;
pDriverObject->DriverUnload = SmartPCIUnload;
return STATUS_SUCCESS;
}

TSTATUS
SmartPCIDispatch(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
)
{
PLOCAL_DEVICE_INFO deviceInfo;
PIO_STACK_LOCATION IrpStack;
NTSTATUS status;

unsigned short commandReg, sequenceReg, interruptEnableReg, interruptStatusReg, interruptStatus;
unsigned short address = 0;
unsigned long data = 0;
PVOID inOutBuffer;
ULONG inBufferLength;
ULONG outBufferLength;

PAGED_CODE();
pIrp->IoStatus.Information = 0;
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension; // Get local info struct
DebugPrint ((“Dispatch\n”));
if(!deviceInfo->Started) {
status = STATUS_DEVICE_NOT_READY;
status = SmartPCICompleteRequest(pIrp, status);
return status;
}
commandReg = (unsigned short)deviceInfo->PortBase;
sequenceReg = commandReg + 4;
m_nCommandReg = commandReg;
m_nSequenceReg = sequenceReg;
interruptStatusReg = commandReg + 2;
interruptEnableReg = commandReg + 8;
IrpStack = IoGetCurrentIrpStackLocation(pIrp);
inOutBuffer = pIrp->AssociatedIrp.SystemBuffer;
inBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
outBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
switch (IrpStack->MajorFunction)
{
case IRP_MJ_DEVICE_CONTROL:
// Dispatch on IOCTL
switch (IrpStack->Parameters.DeviceIoControl.IoControlCode)
{


}
}

}

Please help.

Is your SmartPCICreate called?

Thomas F. Divine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-301378-
xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, September 25, 2007 1:51 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] DEviceiocontrol not calling IRP_MJ_DEVICE_CONTROL

Thank you for the response. Please find below my code sample here.

I use the DeviceIOControl as follows

void Ctrl2Hardware::Initial(short pBaseAddress)
{
ASSERT(m_nhDevice != INVALID_HANDLE_VALUE);
unsigned long nOutput = 0;
if(!DeviceIoControl(m_nhDevice,
IOCTL_INITIAL,
&pBaseAddress,
sizeof(short),
NULL,
0,
&nOutput,
NULL )
) {
CString errMessage;
GetLastErrorMessage(errMessage);
TRACE(“Initial : DeviceIoControl returns %s
\n”,errMessage);
}
}

My driver sample code is here.

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT pDriverObject,
IN PUNICODE_STRING strRegistryPath
)
{
UNREFERENCED_PARAMETER (strRegistryPath);

DebugPrint ((“Driver Entry\n”));

pDriverObject->MajorFunction[IRP_MJ_CREATE] =
SmartPCICreate;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] =
SmartPCIClose;
pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
SmartPCIDispatch;
pDriverObject->MajorFunction[IRP_MJ_PNP] =
SmartPCIDispatchPnp;
pDriverObject->MajorFunction[IRP_MJ_POWER] =
SmartPCIDispatchPower;
pDriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] =
SmartPCIDispatchSystemControl;
pDriverObject->DriverExtension->AddDevice =
SmartPCIAddDevice;
pDriverObject->DriverUnload =
SmartPCIUnload;
return STATUS_SUCCESS;
}

TSTATUS
SmartPCIDispatch(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
)
{
PLOCAL_DEVICE_INFO deviceInfo;
PIO_STACK_LOCATION IrpStack;
NTSTATUS status;

unsigned short commandReg, sequenceReg, interruptEnableReg,
interruptStatusReg, interruptStatus;
unsigned short address = 0;
unsigned long data = 0;
PVOID inOutBuffer;
ULONG inBufferLength;
ULONG outBufferLength;

PAGED_CODE();
pIrp->IoStatus.Information = 0;
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension;
// Get local info struct
DebugPrint ((“Dispatch\n”));
if(!deviceInfo->Started) {
status = STATUS_DEVICE_NOT_READY;
status = SmartPCICompleteRequest(pIrp, status);
return status;
}
commandReg = (unsigned short)deviceInfo->PortBase;
sequenceReg = commandReg + 4;
m_nCommandReg = commandReg;
m_nSequenceReg = sequenceReg;
interruptStatusReg = commandReg + 2;
interruptEnableReg = commandReg + 8;
IrpStack = IoGetCurrentIrpStackLocation(pIrp);
inOutBuffer = pIrp->AssociatedIrp.SystemBuffer;
inBufferLength = IrpStack-
>Parameters.DeviceIoControl.InputBufferLength;
outBufferLength = IrpStack-
>Parameters.DeviceIoControl.OutputBufferLength;
switch (IrpStack->MajorFunction)
{
case IRP_MJ_DEVICE_CONTROL:
// Dispatch on IOCTL
switch (IrpStack->Parameters.DeviceIoControl.IoControlCode)
{


}
}

}

Please help.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Thomas Divine,

SmartPCICreate is not getting called.

m_pLinkName is \\.\C:\windows\system32\driver\SmartPCI32.sys and the folowing function is returning a HANDLE.

HANDLE Ctrl2Hardware::OpenSYS()
{
// Create a handle to the driver
return CreateFile( m_pLinkName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL );
}

Thank You.

I am sure your link name is crazy.

Examine the working DDK samples.

Thomas F. Divine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-301380-
xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, September 25, 2007 2:39 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] DEviceiocontrol not calling IRP_MJ_DEVICE_CONTROL

Thomas Divine,

SmartPCICreate is not getting called.

m_pLinkName is \\.\C:\windows\system32\driver\SmartPCI32.sys and
the folowing function is returning a HANDLE.

HANDLE Ctrl2Hardware::OpenSYS()
{
// Create a handle to the driver
return CreateFile( m_pLinkName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL );
}

Thank You.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

You are opening the driver file. You need to open the device that the driver
created.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]
On Behalf Of Thomas F. Divine
Sent: Tuesday, September 25, 2007 3:24 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DEviceiocontrol not calling IRP_MJ_DEVICE_CONTROL

I am sure your link name is crazy.

Examine the working DDK samples.

Thomas F. Divine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-301380-
xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, September 25, 2007 2:39 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] DEviceiocontrol not calling IRP_MJ_DEVICE_CONTROL

Thomas Divine,

SmartPCICreate is not getting called.

m_pLinkName is \\.\C:\windows\system32\driver\SmartPCI32.sys
and the folowing function is returning a HANDLE.

HANDLE Ctrl2Hardware::OpenSYS()
{
// Create a handle to the driver
return CreateFile( m_pLinkName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL );
}

Thank You.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

xxxxx@hotmail.com wrote:

SmartPCICreate is not getting called.

m_pLinkName is \\.\C:\windows\system32\driver\SmartPCI32.sys and the folowing function is returning a HANDLE.

That’s not how you open a driver. Your driver has to call
IoCreateSymbolicLink to create a name in the \DosDevices namespace.
THAT’S the name you pass to create file.

Actually, in a matter of speaking, you ARE opening the driver, but
you’re opening the driver binary as a normal file. That’s why the ioctl
fails. The ioctl is going to the file system or disk driver, and they
don’t recognize it.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Arivazhagan Balasubramanian wrote:

m_pLinkName is \\.\C:\windows\system32\driver\SmartPCI32.sys
and the folowing function is returning a HANDLE.

HANDLE Ctrl2Hardware::OpenSYS()
{
// Create a handle to the driver
return CreateFile(m_pLinkName,

Sorry, but I have to admit, that’s just hilarious… I’m filing this one away in the “outsourcing gone awry” file…

As a couple of other have already mentioned, this will not work. It looks like this is new to you. This stuff has an unkind learning curve. In my opinion, you need to take a step back, and experiment with one of the WDK samples first. I guess I would start with IOCTL (under General), and post questions based on that.

Good luck,

mm