none
toaster sample..

    Question

  • hi,

    I am new to the driver development.

    Can you guide that how can we open the registered interface from user mode and send read, write, and IOCTL requests in toaster sample...

    And how can we Implement IOCTL  for 3 types of Methods, Reading & Writing of Virtual IO Ports, Kernel to user notification

    Tuesday, February 28, 2012 8:09 AM

Answers

  • Given I understand your question, you should not need to ADD anything to the toaster example driver. Look at the toaster example APPLICATION and find the CreateFile used to open a handle to the toaster driver(s) and then follow the logic that allows accessing the driver from user level.

    Gary G. Little NanoTelesis Systems, LLC

    Tuesday, February 28, 2012 1:30 PM
  • ummanna wrote:
    >
    >Can anybody help me on this...
    >
    >#define IOCTL_TOASTER_METHOD_IN_DIRECT \
    >CTL_CODE( FILE_DEVICE_BUSENUM, ?????, METHOD_IN_DIRECT, FILE_ANY_ACCESS )
    >
    >which function i can use here   "????"
     
    With the exception of 2 bits at the bottom (METHOD_*) and 2 bits in the
    middle (FILE_*), the numeric value of an IOCTL code has no inherent
    meaning.  It is strictly a private contract between the driver and the
    applications that use it.  You can use whatever numbers you want.
     
    There is a tradition that the top-most 16 bits are a device type and the 12
    bits at bits 13 to 2 are a function code, but that is strictly a (useful)
    software convention, which helps make sure that ioctls sent to the wrong
    driver don't do a lot of damage.  The operating system doesn't actually
    enforce any of that.
     
    So, use whatever you want.  You're the only one that will be using them.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.
    Saturday, March 03, 2012 7:00 PM

All replies

  • I think example is there in the toaster sample. Just search for the SetupDiEnumDeviceInterfaces, CreateFile and DeviceIoControl and I believe you will be able to figure out the things of your own.
    Tuesday, February 28, 2012 11:29 AM
  • Thanks for info...

    but i am not able to figureout where to add handle inside the toaster...and read write functions..

    Tuesday, February 28, 2012 11:40 AM
  • Given I understand your question, you should not need to ADD anything to the toaster example driver. Look at the toaster example APPLICATION and find the CreateFile used to open a handle to the toaster driver(s) and then follow the logic that allows accessing the driver from user level.

    Gary G. Little NanoTelesis Systems, LLC

    Tuesday, February 28, 2012 1:30 PM
  •  Perhaps you need to read a little about function DeviceIoControl. This is the way to send (or receive)  the driver a relatively short buffer of data along with a control code that tells the driver what to do with the buffer. So, if you are the owner of both the driver and the application, you can create an interface to the driver, define some control codes and write a handler to process IRPs. For the sake of clarity, I'll define (This is not a correct definition) IRPs as the way that your driver sees your IOCTL.

    On the application side, you get a handle to the interface you created, you call the driver using DeviveIoControl. Parameters to  DeviveIoControl will be the opened handle, the control code and optionally some data. Note that you can call the same interface (=handle) with many control codes - each will can be differently processed by the driver - this is up to you how you treat them.

    Tuesday, February 28, 2012 1:50 PM
  • toaster does not show you how to touch hardware, you would need a real hw device to do that.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, February 28, 2012 5:25 PM
  • I got how to do that  i tried using DeviceIOControl....

    Thanks for everything...

    Wednesday, February 29, 2012 4:26 AM
  • Can anybody help me on this...

    #define IOCTL_TOASTER_METHOD_IN_DIRECT \


    CTL_CODE( FILE_DEVICE_BUSENUM, ?????, METHOD_IN_DIRECT, FILE_ANY_ACCESS )

    which function i can use here   "????"

    when i am using bRc i am getting

    GetLastError()=1...  for ?????=0X901

    bRc = DeviceIoControl ( file,

    IOCTL_TOASTER_METHOD_NEITHER,

    &InputBuffer,

    (DWORD) strlen ( InputBuffer )+1,

    &OutputBuffer,

    sizeof( OutputBuffer),

    &bytesReturned,

    NULL

    );

    • Edited by Sai C Friday, March 02, 2012 12:43 PM
    Friday, March 02, 2012 11:27 AM
  • You define a FUNCTION value for that field. Did you search for CTL_CODE? There is an amazing amount of documentation in the resulting header file that you will find. Some FUNCTION codes are reserved for the system, and of course you want to be sure yours is unique.

    Gary G. Little NanoTelesis Systems, LLC

    Friday, March 02, 2012 1:47 PM
  • I searched for CTL_CODE but i didn't get which funtion i can use..  can you give the details of function which i can use in my code... 
    Friday, March 02, 2012 4:08 PM
  • How can I when I have no idea what your driver does? Define a function code between 2048 and 4095.

    Gary G. Little NanoTelesis Systems, LLC

    Friday, March 02, 2012 4:29 PM
  • ummanna wrote:
    >
    >Can anybody help me on this...
    >
    >#define IOCTL_TOASTER_METHOD_IN_DIRECT \
    >CTL_CODE( FILE_DEVICE_BUSENUM, ?????, METHOD_IN_DIRECT, FILE_ANY_ACCESS )
    >
    >which function i can use here   "????"
     
    With the exception of 2 bits at the bottom (METHOD_*) and 2 bits in the
    middle (FILE_*), the numeric value of an IOCTL code has no inherent
    meaning.  It is strictly a private contract between the driver and the
    applications that use it.  You can use whatever numbers you want.
     
    There is a tradition that the top-most 16 bits are a device type and the 12
    bits at bits 13 to 2 are a function code, but that is strictly a (useful)
    software convention, which helps make sure that ioctls sent to the wrong
    driver don't do a lot of damage.  The operating system doesn't actually
    enforce any of that.
     
    So, use whatever you want.  You're the only one that will be using them.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.
    Saturday, March 03, 2012 7:00 PM