Click here to Skip to main content
15,880,392 members
Articles / Programming Languages / C

Driver Development Part 4: Introduction to device stacks

Rate me:
Please Sign up or sign in to vote.
4.83/5 (48 votes)
27 Mar 200511 min read 239.1K   5.3K   266  
This article will introduce how devices can interact with each other.
/**********************************************************************
 * 
 *  Toby Opferman
 *
 *  Driver Example
 *
 *  This example is for educational purposes only.  I license this source
 *  out for use in learning how to write a device driver.
 *
 *     Driver Public Header File
 **********************************************************************/




#ifndef __PUBLIC_H__
#define __PUBLIC_H__


/* 
 *   IOCTL's are defined by the following bit layout.
 *   [ Common | Device Type | Required Access | Custom | Function Code | Transfer Type ]
 *      31     30         16 15             14    13    12           2  1            0
 * 
 *   Common          - 1 bit.  This is set for user-defined device types.
 *   Device Type     - This is the type of device the IOCTL belongs to.  This can be user defined (Common bit set).  This must match the device type of the device object.
 *   Required Access - FILE_READ_DATA, FILE_WRITE_DATA, etc.  This is the required access for the device.
 *   Custom          - 1 bit.  This is set for user-defined IOCTL's.  This is used in the same manner as "WM_USER".
 *   Function Code   - This is the function code that the system or the user defined (custom bit set)
 *   Transfer Type   - METHOD_IN_DIRECT, METHOD_OUT_DIRECT, METHOD_NEITHER, METHOD_BUFFERED, This the data transfer method to be used.
 *
 */
#define IOCTL_EXAMPLE_SAMPLE_DIRECT_IN_IO    CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_IN_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA) 
#define IOCTL_EXAMPLE_SAMPLE_DIRECT_OUT_IO   CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_OUT_DIRECT,FILE_READ_DATA | FILE_WRITE_DATA) 
#define IOCTL_EXAMPLE_SAMPLE_BUFFERED_IO     CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
#define IOCTL_EXAMPLE_SAMPLE_NEITHER_IO      CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_NEITHER,FILE_READ_DATA | FILE_WRITE_DATA) 

                               

#endif

                      

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer Intel
United States United States
Toby Opferman has worked in just about all aspects of Windows development including applications, services and drivers.

He has also played a variety of roles professionally on a wide range of projects. This has included pure researching roles, architect roles and developer roles. He also was also solely responsible for debugging traps and blue screens for a number of years.

Previously of Citrix Systems he is very experienced in the area of Terminal Services. He currently works on Operating Systems and low level architecture at Intel.

He has started a youtube channel called "Checksum Error" that focuses on software.
https://www.youtube.com/channel/UCMN9q8DbU0dnllWpVRvn7Cw

Comments and Discussions