none
Problem with NDISPROT sample binding to adapter RRS feed

  • Question

  • I've been playing around with the NDIS Protocol sample trying to make a service that will connect to the driver and send packets based on a timer.  I'm having some difficulty binding to the adapter... every time I try I'm getting Error 2 which is a File Not Found.

    Here is the code:

            // method to bind an adapter to the a the handle that we have open
            private bool BindAdapter(string adapterID)
            {
                // char array to hold the adapterID string
                char[] ndisAdapter = new char[256];
                // convert the string to a unicode non-localized char array
                int iNameLength = 0, i = 0;
                for (i = 0; i < adapterID.Length; i++)
                {
                    ndisAdapter[i] = adapterID[i];
                    iNameLength++;
                }
                ndisAdapter[i] = '\0';
    
                // uint to hold the number of bytes read from DeviceIoControl
                uint uiBytesReturned;
    
                // do the following in an unsafe context
                unsafe
                {
                    // create a void pointer to ndisAdapter
                    fixed (void* vpNdisAdapter = &ndisAdapter[0])
                    {
    
                        bool temp = DeviceIoControl(this.driverHandle, IOCTL_NDISPROT_OPEN_DEVICE,
                            vpNdisAdapter, (uint)(iNameLength * sizeof(char)), null, 0,
                            &uiBytesReturned, 0);
    
                        if (!temp)
                        {
                            int error = Marshal.GetLastWin32Error();
                            this.writeLog("Last error is: " + error);
                        }
                        // Call the DeviceIoControl API to bind the adapter to the handle
                        return temp;
                    }
                }
            }

    temp is coming back as False each time and I'm then catching and displaying the Error 2.

    The NDISPROT service is running so I'm able to detect the driver but at this point the custom service can no longer proceed so it fails to start.

    I'm on Windows 8.1 using Visual Studio 2013.

    Any help would be greatly appreciated!  I'm new to this driver development so code examples would be great if someone knows the answer.

    Thanks!


    • Edited by Dotren Monday, June 1, 2015 3:00 AM
    Monday, June 1, 2015 2:58 AM

Answers

  • A lot of things can go wrong... if the name isn't correct, or isn't formatted correctly, the kernel driver will return ERROR_FILE_NOT_FOUND.  Try attaching a kernel debugger and setting a breakpoint on ndisprotOpenDevice. See if the name comes through correctly.

    Note that the kernel code is very picky about the case, whitespace, and length of the string you give it.  (See ndisprotLookupDevice)

    • Marked as answer by Dotren Friday, June 5, 2015 7:46 PM
    Tuesday, June 2, 2015 11:02 PM

All replies

  • A lot of things can go wrong... if the name isn't correct, or isn't formatted correctly, the kernel driver will return ERROR_FILE_NOT_FOUND.  Try attaching a kernel debugger and setting a breakpoint on ndisprotOpenDevice. See if the name comes through correctly.

    Note that the kernel code is very picky about the case, whitespace, and length of the string you give it.  (See ndisprotLookupDevice)

    • Marked as answer by Dotren Friday, June 5, 2015 7:46 PM
    Tuesday, June 2, 2015 11:02 PM
  • I'm having a lot of difficulty with learning the remote/kernel debugging and for some reason I'm having problems getting this the NDISPROT driver to install to the remote debugging machine I have set up.

    Regardless, I found another example online that showed the correct format the adapter name needed to be in and it was definitely incorrect (had a bunch of extra characters in the front).  I hardcoded the name without the extra bits and I was able to get past the adapter binding finally.

    Thanks!

    Friday, June 5, 2015 7:47 PM