none
IoBuildDeviceIoControlRequest always returns STATUS_INVALID_PARAMETER RRS feed

  • Question

  • Hello,

    I'm currently trying to send IOCTLs to the lower driver. The be sure that the IOCTLs should work I created an application which performed them using DeviceIoControl.

    One of the IOCTLs also worked from within the driver using IoBuildDeviceIoControlRequest , others always return STATUS_INVALID_PARAMETER. The difference between the IOCTL that worked and the others is that the other IOCTLs that didn't work also require input data. It seems that the input data (local variables) are lost during IoCallDriver.

    I'm currently in the StartDevice-Routine and want to use the IOCTLs in order to get device specific data via IoBuildDeviceIoControlRequest.

    Unfortunately I didn't found a (easy to understand) sample where IoBuildDeviceIoControlRequest with both input data and output data. Here is my Code (exemplarily), Init herein is called while processing the IRP_MN_START_DEVICE IOCTL:

    NTSTATUS Init(PDEVICE_OBJECT pFdo)
    {
         NTSTATUS        Status;
         INPUT_DATA      InputData;
         OUTPUT_DATA     OutputData;
    
         /* ... Setting up input/output data ...*/
    
         Do_IOControl(pFdo->pLowerDo, IOCTL_READ, &InputData, sizeof(INPUT_DATA), &OutputData, sizeof(OUTPUT_DATA));
    
        /* ... */
    }
    
    NTSTATUS Do_IOControl(PDEVICE_OBJECT pDevObj, ULONG ControlCode, PVOID pInBuf, ULONG InBufLen, PVOID pOutBuf, ULONG OutBufLen)
    {
        NTSTATUS        Status;
        KEVENT          Event;
        PIRP            pIrp;
        IO_STATUS_BLOCK IoStatus;
        
        KeInitializeEvent(&Event, NotificationEvent, FALSE);
        pIrp = IoBuildDeviceIoControlRequest(ControlCode, pDevObj, pInBuf, InBufLen, pOutBuf, OutBufLen, FALSE, &Event, &IoStatus);
        Status = IoCallDriver(pPCCDev->pOmniDrive, pIrp);
    
        if ((STATUS_PENDING) == Status)
        {
            KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
        }
        else if (!NT_SUCCESS(Status))
        {
            return (Status);
        }
        else
        {
            /* Nothing to do */
        }

        return (NTSTATUS)IoStatus.Status; }

    What is wrong? Thanks in before for help!

    Best regards,
    Willi K.



    • Edited by Willi K Wednesday, December 17, 2014 5:24 PM Completed the Do_IoControl()
    Wednesday, December 17, 2014 5:04 PM

Answers

  • I got it. While viewing some of the sample drivers I've noticed that some functions use the PAGED_CODE macro, while others not. Added this macro to my Do_IoControl() function and it worked.
    • Marked as answer by Willi K Thursday, December 18, 2014 8:23 AM
    Thursday, December 18, 2014 8:23 AM

All replies

  • We need more data, you say the input variables are locals, is there anyway that Do_IOControl will return and allow these to be cleaned up before the IRP completes?  In general we need to see more of the driver.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Wednesday, December 17, 2014 5:14 PM
  • Hello Don Burn,

    thanks for your reply. I'm not sure if I understood your question correctly. As shown in the code sample the Init() function passed its local variables to the Do_IoControl() function, which passes it's function parameters to the IoBuildDeviceIoControlRequest() and then calls IoCallDriver(). There is nothing specail Do_IoControl is doing - I added the remaining code in Do_IoControl() in the sample.
    Wednesday, December 17, 2014 5:25 PM
  • I got it. While viewing some of the sample drivers I've noticed that some functions use the PAGED_CODE macro, while others not. Added this macro to my Do_IoControl() function and it worked.
    • Marked as answer by Willi K Thursday, December 18, 2014 8:23 AM
    Thursday, December 18, 2014 8:23 AM
  • The PAGED_CODE macro is just an assert, you must have changed something else to get it to work.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Thursday, December 18, 2014 1:14 PM