├── .gitignore
├── BasicUSB
├── BasicUSB.sln
├── BasicUSB
│ ├── BasicUSB.inf
│ ├── BasicUSB.vcxproj
│ ├── BasicUSB.vcxproj.filters
│ ├── BasicUSB.vcxproj.user
│ ├── basicusb.cpp
│ ├── basicusb.h
│ ├── basicusb_ioctl.h
│ └── cpp.hint
├── BasicUSBTest
│ ├── BasicUSBTest.vcxproj
│ ├── BasicUSBTest.vcxproj.filters
│ ├── BasicUSBTest.vcxproj.user
│ └── basicusbtest.c
└── README.md
├── CDFilter
├── CDFilter.sln
├── CDFilter
│ ├── CDFilter.cpp
│ ├── CDFilter.h
│ ├── CDFilter.inf
│ ├── CDFilter.vcxproj
│ ├── CDFilter.vcxproj.filters
│ └── CDFilter.vcxproj.user
└── README.md
├── Docs_and_Misc
├── WDF Lab Exercises.pdf
└── empty.iso
├── Nothing_KMDF
├── Inc
│ └── nothing_ioctl.h
├── Nothing_KMDF Test
│ ├── Nothing_KMDF Test.vcxproj
│ ├── Nothing_KMDF Test.vcxproj.filters
│ ├── Nothing_KMDF Test.vcxproj.user
│ └── nothingtest.cpp
├── Nothing_KMDF.sln
├── Nothing_KMDF
│ ├── Nothing.cpp
│ ├── Nothing_KMDF.inf
│ ├── Nothing_KMDF.vcxproj
│ ├── Nothing_KMDF.vcxproj.filters
│ ├── Nothing_KMDF.vcxproj.user
│ └── nothing.h
└── README.md
├── README.md
└── Solutions
├── 2
├── 2A
│ └── Nothing.cpp
└── 2B
│ ├── Nothing.cpp
│ └── nothing.h
├── 3
├── 3A
│ ├── Nothing.cpp
│ └── nothing.h
└── 3B
│ ├── Nothing.cpp
│ └── nothing.h
├── 4
├── 4B
│ ├── CDFilter.cpp
│ └── CDFilter.h
└── 4C
│ ├── CDFilter.cpp
│ └── CDFilter.h
├── 5
├── 5A
│ ├── basicusb.cpp
│ └── basicusb.h
├── 5B
│ ├── basicusb.cpp
│ ├── basicusb.h
│ └── basicusb_ioctl.h
├── 5C
│ ├── basicusb.cpp
│ ├── basicusb.h
│ └── basicusb_ioctl.h
└── BasicUsb Test
│ └── basicusbtest.c
├── 6
└── 6a
│ ├── Nothing.cpp
│ └── nothing.h
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | BasicUSB/.vs
2 | BasicUSB/BasicUSB/x64
3 | BasicUSB/BasicUSBTest/x64
4 | BasicUSB/x64
5 | Nothing_KMDF/.vs
6 | Nothing_KMDF/Nothing_KMDF/x64
7 | Nothing_KMDF/Nothing_KMDF Test/x64
8 | Nothing_KMDF/x64
9 | BasicUSB/BasicUSB/Debug
10 | BasicUSB/BasicUSB/Release
11 | BasicUSB/BasicUSBTest/Debug
12 | BasicUSB/BasicUSBTest/Release
13 | BasicUSB/Debug
14 | BasicUSB/Release
15 | CDFilter/.vs
16 | CDFilter/CDFilter/Debug
17 | CDFilter/CDFilter/Release
18 | CDFilter/CDFilter/x64
19 | CDFilter/Debug
20 | CDFilter/Release
21 | CDFilter/x64
22 | Nothing_KMDF/Debug
23 | Nothing_KMDF/Release
24 | Nothing_KMDF/Nothing_KMDF/Debug
25 | Nothing_KMDF/Nothing_KMDF/Release
26 | Nothing_KMDF/Nothing_KMDF Test/Debug
27 | Nothing_KMDF/Nothing_KMDF Test/Release
28 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSB.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.6.33815.320
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BasicUSB", "BasicUSB\BasicUSB.vcxproj", "{B1848C51-CD5E-4F20-879C-3C3A38E0EC22}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BasicUSBTest", "BasicUSBTest\BasicUSBTest.vcxproj", "{C8161130-5531-4169-B6E2-F0D2C2756E62}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|x64 = Debug|x64
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {B1848C51-CD5E-4F20-879C-3C3A38E0EC22}.Debug|x64.ActiveCfg = Debug|x64
17 | {B1848C51-CD5E-4F20-879C-3C3A38E0EC22}.Debug|x64.Build.0 = Debug|x64
18 | {B1848C51-CD5E-4F20-879C-3C3A38E0EC22}.Release|x64.ActiveCfg = Release|x64
19 | {B1848C51-CD5E-4F20-879C-3C3A38E0EC22}.Release|x64.Build.0 = Release|x64
20 | {B1848C51-CD5E-4F20-879C-3C3A38E0EC22}.Release|x64.Deploy.0 = Release|x64
21 | {C8161130-5531-4169-B6E2-F0D2C2756E62}.Debug|x64.ActiveCfg = Debug|x64
22 | {C8161130-5531-4169-B6E2-F0D2C2756E62}.Debug|x64.Build.0 = Debug|x64
23 | {C8161130-5531-4169-B6E2-F0D2C2756E62}.Release|x64.ActiveCfg = Release|x64
24 | {C8161130-5531-4169-B6E2-F0D2C2756E62}.Release|x64.Build.0 = Release|x64
25 | EndGlobalSection
26 | GlobalSection(SolutionProperties) = preSolution
27 | HideSolutionNode = FALSE
28 | EndGlobalSection
29 | GlobalSection(ExtensibilityGlobals) = postSolution
30 | SolutionGuid = {1AAA00C1-EF00-4F97-B309-6394EE53443B}
31 | EndGlobalSection
32 | EndGlobal
33 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSB/BasicUSB.inf:
--------------------------------------------------------------------------------
1 | ;
2 | ; BasicUsb.inf
3 | ;
4 |
5 | [Version]
6 | Signature="$WINDOWS NT$"
7 | Class=OsrNothingClass
8 | ClassGuid={37E1E5FF-C046-4AA9-81EE-D379F14E61F1} ; OSR Example class
9 | Provider=%ManufacturerName%
10 | CatalogFile=BasicUsb.cat
11 | DriverVer= ; TODO: set DriverVer in stampinf property pages
12 |
13 | [DestinationDirs]
14 | DefaultDestDir = 12
15 |
16 | ; ================= Class section =====================
17 |
18 | [ClassInstall32]
19 | Addreg=SampleClassReg
20 |
21 | [SampleClassReg]
22 | HKR,,,0,%ClassName%
23 | HKR,,Icon,,-5
24 |
25 | [SourceDisksNames]
26 | 1 = %DiskName%,,,""
27 |
28 | [SourceDisksFiles]
29 | BasicUsb.sys = 1,,
30 |
31 | ;*****************************************
32 | ; Install Section
33 | ;*****************************************
34 |
35 | [Manufacturer]
36 | %ManufacturerName%=Standard,NT$ARCH$
37 |
38 | [Standard.NT$ARCH$]
39 | %BasicUsb.DeviceDesc%=BasicUsb_Device, USB\Vid_0547&Pid_1002
40 |
41 | [BasicUsb_Device.NT]
42 | CopyFiles=Drivers_Dir
43 |
44 | [Drivers_Dir]
45 | BasicUsb.sys
46 |
47 | ;-------------- Service installation
48 | [BasicUsb_Device.NT.Services]
49 | AddService = BasicUsb,%SPSVCINST_ASSOCSERVICE%, BasicUsb_Service_Inst
50 |
51 | ;
52 | ; **** Converting this driver to UMDF???
53 | ;
54 | ; If so, don't forget to add UmdfDispatcher=NativeUSB
55 | ; to the BasicUsb.Wdf section. If you don't do this
56 | ; the call to WdfUsbTargetDeviceCreateWithParameters
57 | ; in EvtDevicePrepareHardware will fail.
58 | ;
59 |
60 | ; -------------- BasicUsb driver install sections
61 | [BasicUsb_Service_Inst]
62 | DisplayName = %BasicUsb.SVCDESC%
63 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER
64 | StartType = 3 ; SERVICE_DEMAND_START
65 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL
66 | ServiceBinary = %12%\BasicUsb.sys
67 | LoadOrderGroup = Extended Base
68 |
69 | [Strings]
70 | SPSVCINST_ASSOCSERVICE= 0x00000002
71 | ManufacturerName="OSR Open Systems Resources, Inc."
72 | ClassName="OSR Example Devices"
73 | DiskName = "BasicUsb Installation Disk"
74 | BasicUsb.DeviceDesc = "BasicUsb Device"
75 | BasicUsb.SVCDESC = "BasicUsb Service"
76 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSB/BasicUSB.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {B1848C51-CD5E-4F20-879C-3C3A38E0EC22}
23 | {1bc93793-694f-48fe-9372-81e2b05556fd}
24 | v4.5
25 | 12.0
26 | Debug
27 | Win32
28 | BasicUSB
29 |
30 |
31 |
32 | Windows10
33 | true
34 | WindowsKernelModeDriver10.0
35 | Driver
36 | KMDF
37 | Desktop
38 |
39 |
40 | Windows10
41 | false
42 | WindowsKernelModeDriver10.0
43 | Driver
44 | KMDF
45 | Desktop
46 |
47 |
48 | Windows10
49 | true
50 | WindowsKernelModeDriver10.0
51 | Driver
52 | KMDF
53 | Desktop
54 |
55 |
56 | Windows10
57 | false
58 | WindowsKernelModeDriver10.0
59 | Driver
60 | KMDF
61 | Desktop
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | DbgengKernelDebugger
73 | false
74 |
75 |
76 | DbgengKernelDebugger
77 | false
78 |
79 |
80 | DbgengKernelDebugger
81 | false
82 |
83 |
84 | DbgengKernelDebugger
85 | false
86 |
87 |
88 |
89 | Level3
90 |
91 |
92 | SHA256
93 |
94 |
95 |
96 |
97 | Level3
98 |
99 |
100 | SHA256
101 |
102 |
103 |
104 |
105 | Level3
106 |
107 |
108 | SHA256
109 |
110 |
111 |
112 |
113 | Level3
114 |
115 |
116 | SHA256
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSB/BasicUSB.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 | {8E41214B-6785-4CFE-B992-037D68949A14}
18 | inf;inv;inx;mof;mc;
19 |
20 |
21 |
22 |
23 | Driver Files
24 |
25 |
26 |
27 |
28 | Source Files
29 |
30 |
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSB/BasicUSB.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSB/basicusb.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | #define BUILDING_IN_KERNEL_MODE _KERNEL_MODE
41 |
42 | #ifndef BUILDING_IN_KERNEL_MODE
43 |
44 | //
45 | // Building the driver using UMDF
46 | //
47 | #include
48 | #include
49 |
50 | #define ASSERT( exp ) \
51 | ((!(exp)) ? \
52 | (RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ),FALSE) : \
53 | TRUE)
54 |
55 | #define KeGetCurrentIrql() (PASSIVE_LEVEL)
56 |
57 | #else
58 |
59 | //
60 | // Building the driver using KMDF
61 | //
62 | #include
63 | #include
64 | #include
65 |
66 | #endif
67 |
68 | #include
69 | #include
70 |
71 | //
72 | // Generate our device interface GUID
73 | //
74 | #include // required for GUID definitions
75 | DEFINE_GUID (GUID_DEVINTERFACE_BASICUSB,
76 | 0x79963ae7, 0x45de, 0x4a31, 0x8f, 0x34, 0xf0, 0xe8, 0x90, 0xb, 0xc2, 0x18);
77 |
78 | #include "BASICUSB_IOCTL.h"
79 |
80 | //
81 | // BasicUsb device context structure
82 | //
83 | // WDF will associate this structure with each "BasicUsb" device that
84 | // this driver creates.
85 | //
86 | typedef struct _BASICUSB_DEVICE_CONTEXT {
87 |
88 | //
89 | // Our USB I/O target
90 | //
91 | WDFUSBDEVICE UsbDeviceTarget;
92 |
93 | //
94 | // Our bulk OUT pipe
95 | //
96 | WDFUSBPIPE BulkOutPipe;
97 |
98 | //
99 | // Our interrupt IN pipe
100 | //
101 | WDFUSBPIPE InterruptInPipe;
102 |
103 | } BASICUSB_DEVICE_CONTEXT, * PBASICUSB_DEVICE_CONTEXT;
104 |
105 | //
106 | // The various vendor commands for our device.
107 | //
108 | constexpr UCHAR USBFX2LK_READ_7SEGMENT_DISPLAY = 0xD4;
109 | constexpr UCHAR USBFX2LK_READ_SWITCHES = 0xD6;
110 | constexpr UCHAR USBFX2LK_READ_BARGRAPH_DISPLAY = 0xD7;
111 | constexpr UCHAR USBFX2LK_SET_BARGRAPH_DISPLAY = 0xD8;
112 | constexpr UCHAR USBFX2LK_IS_HIGH_SPEED = 0xD9;
113 | constexpr UCHAR USBFX2LK_REENUMERATE = 0xDA;
114 | constexpr UCHAR USBFX2LK_SET_7SEGMENT_DISPLAY = 0xDB;
115 |
116 | //
117 | // Accessor structure
118 | //
119 | // Given a WDFDEVICE handle, we'll use the following function to return
120 | // a pointer to our device's context area.
121 | //
122 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(BASICUSB_DEVICE_CONTEXT, BasicUsbGetContextFromDevice)
123 |
124 | //
125 | // Forward declarations
126 | //
127 | extern "C" {
128 | DRIVER_INITIALIZE DriverEntry;
129 | }
130 | EVT_WDF_DRIVER_DEVICE_ADD BasicUsbEvtDeviceAdd;
131 | EVT_WDF_IO_QUEUE_IO_READ BasicUsbEvtRead;
132 | EVT_WDF_IO_QUEUE_IO_WRITE BasicUsbEvtWrite;
133 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL BasicUsbEvtDeviceControl;
134 | EVT_WDF_DEVICE_PREPARE_HARDWARE BasicUsbEvtDevicePrepareHardware;
135 |
136 | EVT_WDF_DEVICE_D0_ENTRY BasicUsbEvtDeviceD0Entry;
137 |
138 | EVT_WDF_DEVICE_D0_EXIT BasicUsbEvtDeviceD0Exit;
139 |
140 |
141 | EVT_WDF_USB_READER_COMPLETION_ROUTINE BasicUsbInterruptPipeReadComplete;
142 |
143 | EVT_WDF_REQUEST_COMPLETION_ROUTINE BasicUsbEvtRequestWriteCompletionRoutine;
144 |
145 | NTSTATUS
146 | BasicUsbDoSetBarGraph(_In_ PBASICUSB_DEVICE_CONTEXT DevContext,
147 | _In_ WDFREQUEST Request,
148 | _Out_ PULONG_PTR BytesWritten);
149 |
150 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSB/basicusb_ioctl.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | // ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | // CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | // CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
28 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | // POSSIBILITY OF SUCH DAMAGE
30 | //
31 |
32 | //
33 | // This header file contains all declarations shared between driver and user
34 | // applications.
35 | //
36 |
37 | #ifndef __BASICUSB_IOCTL_H__
38 | #define __BASICUSB_IOCTL_H__ (1)
39 |
40 | //
41 | // The following value is arbitrarily chosen from the space defined by Microsoft
42 | // as being "for non-Microsoft use"
43 | //
44 | #define FILE_DEVICE_BASICUSB 0xCF53
45 |
46 | //
47 | // Device control codes - values between 2048 and 4095 arbitrarily chosen
48 | //
49 | #define IOCTL_OSR_BASICUSB_SET_BAR_GRAPH CTL_CODE(FILE_DEVICE_BASICUSB,\
50 | 2049, \
51 | METHOD_BUFFERED, \
52 | FILE_WRITE_ACCESS)
53 |
54 |
55 | #endif /* __BASICUSB_IOCTL_H__ */
56 |
57 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSB/cpp.hint:
--------------------------------------------------------------------------------
1 | // Hint files help the Visual Studio IDE interpret Visual C++ identifiers
2 | // such as names of functions and macros.
3 | // For more information see https://go.microsoft.com/fwlink/?linkid=865984
4 | #define WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(_contexttype, _castingfunction) WDF_DECLARE_TYPE_AND_GLOBALS( _contexttype, WDF_GET_CONTEXT_TYPE_INFO(_contexttype), NULL, WDF_TYPE_DEFAULT_SECTION_NAME) WDF_DECLARE_CASTING_FUNCTION(_contexttype, _castingfunction)
5 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSBTest/BasicUSBTest.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | {C8161130-5531-4169-B6E2-F0D2C2756E62}
29 | Win32Proj
30 | BasicUSBTest
31 | 10.0
32 |
33 |
34 |
35 | Application
36 | true
37 | v143
38 | Unicode
39 | false
40 |
41 |
42 | Application
43 | false
44 | v143
45 | true
46 | Unicode
47 | false
48 |
49 |
50 | Application
51 | true
52 | v143
53 | Unicode
54 | false
55 |
56 |
57 | Application
58 | false
59 | v143
60 | true
61 | Unicode
62 | false
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | true
84 | $(ProjectDir)\..\BasicUSB;$(IncludePath)
85 |
86 |
87 | true
88 | $(ProjectDir)\..\BasicUSB;$(IncludePath)
89 |
90 |
91 | false
92 | $(ProjectDir)\..\BasicUSB;$(IncludePath)
93 |
94 |
95 | false
96 | $(ProjectDir)\..\BasicUSB;$(IncludePath)
97 |
98 |
99 |
100 |
101 |
102 | Level3
103 | Disabled
104 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
105 | MultiThreadedDebug
106 |
107 |
108 | Console
109 | true
110 |
111 |
112 |
113 |
114 |
115 |
116 | Level3
117 | Disabled
118 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
119 | MultiThreadedDebug
120 |
121 |
122 | Console
123 | true
124 |
125 |
126 |
127 |
128 | Level3
129 |
130 |
131 | MaxSpeed
132 | true
133 | true
134 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
135 | MultiThreaded
136 |
137 |
138 | Console
139 | true
140 | true
141 | true
142 |
143 |
144 |
145 |
146 | Level3
147 |
148 |
149 | MaxSpeed
150 | true
151 | true
152 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
153 | MultiThreaded
154 |
155 |
156 | Console
157 | true
158 | true
159 | true
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSBTest/BasicUSBTest.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSBTest/BasicUSBTest.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/BasicUSB/BasicUSBTest/basicusbtest.c:
--------------------------------------------------------------------------------
1 | //
2 | // basicusbtest.c
3 | //
4 | // Win32 console mode program to fire up requests to the
5 | // BASICUSB driver.
6 | //
7 | // This code is purely functional, and is definitely not designed to be any
8 | // sort of example.
9 | //
10 | #define _CRT_SECURE_NO_WARNINGS
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | //
17 | // Simple test application to demonstrate the BasicUSB driver
18 | //
19 |
20 | int
21 | __cdecl
22 | main(ULONG argc, LPSTR *argv)
23 | {
24 | HANDLE deviceHandle;
25 | DWORD code;
26 | ULONG index;
27 | UCHAR writeBuffer[512];
28 | UCHAR readBuffer[512];
29 | DWORD function;
30 | UCHAR barGraph;
31 |
32 | //
33 | // Init the write and read buffers with known data
34 | //
35 | memset(readBuffer, 0xAA, sizeof(readBuffer));
36 |
37 | memset(writeBuffer, 0xEE, sizeof(writeBuffer));
38 |
39 | //
40 | // Open the sample PCI device
41 | //
42 | deviceHandle = CreateFile(L"\\\\.\\BASICUSB",
43 | GENERIC_READ|GENERIC_WRITE,
44 | 0,
45 | 0,
46 | OPEN_EXISTING,
47 | 0,
48 | 0);
49 |
50 | //
51 | // If this call fails, check to figure out what the error is and report it.
52 | //
53 | if (deviceHandle == INVALID_HANDLE_VALUE) {
54 |
55 | code = GetLastError();
56 |
57 | printf("CreateFile failed with error 0x%lx\n", code);
58 |
59 | return(code);
60 | }
61 |
62 | //
63 | // Infinitely print out the list of choices, ask for input, process
64 | // the request
65 | //
66 | while(TRUE) {
67 |
68 | printf ("\nBASICUSB TEST -- functions:\n\n");
69 | printf ("\t1. Send a sync READ\n");
70 | printf ("\t2. Send a sync WRITE\n");
71 | printf ("\t3. Send SET_BAR_GRAPH IOCTL - All On\n");
72 | printf ("\t4. Send SET_BAR_GRAPH IOCTL - All Off\n");
73 | printf ("\n\t0. Exit\n");
74 | printf ("\n\tSelection: ");
75 | #pragma warning(suppress: 6031)
76 | scanf ("%x", &function); // NOLINT(cert-err34-c)
77 |
78 | switch(function) {
79 |
80 | case 1:
81 | //
82 | // Send a read
83 | //
84 | if ( !ReadFile(deviceHandle,
85 | readBuffer,
86 | sizeof(readBuffer),
87 | &index,
88 | NULL)) {
89 |
90 | code = GetLastError();
91 |
92 | printf("ReadFile failed with error 0x%lx\n", code);
93 |
94 | return(code);
95 | }
96 | printf("Bytes Read = %ld.\n", index);
97 | break;
98 |
99 | case 2:
100 | //
101 | // Send a write
102 | //
103 | if (!WriteFile(deviceHandle,
104 | writeBuffer,
105 | sizeof(writeBuffer),
106 | &index,
107 | NULL)) {
108 |
109 | code = GetLastError();
110 |
111 | printf("WriteFile failed with error 0x%lx\n", code);
112 |
113 | return(code);
114 | }
115 | printf("Bytes Written = %ld.\n", index);
116 | break;
117 |
118 | case 3:
119 | barGraph = 0xFF;
120 |
121 | if (!DeviceIoControl(deviceHandle,
122 | IOCTL_OSR_BASICUSB_SET_BAR_GRAPH,
123 | &barGraph,
124 | sizeof(UCHAR),
125 | NULL,
126 | 0,
127 | &index,
128 | NULL)) {
129 |
130 | code = GetLastError();
131 |
132 | printf("DeviceIoControl failed with error 0x%lx\n", code);
133 | return(code);
134 |
135 | }
136 |
137 | printf("IOCTL worked!\n");
138 | break;
139 | case 4:
140 | barGraph = 0;
141 |
142 | if (!DeviceIoControl(deviceHandle,
143 | IOCTL_OSR_BASICUSB_SET_BAR_GRAPH,
144 | &barGraph,
145 | sizeof(UCHAR),
146 | NULL,
147 | 0,
148 | &index,
149 | NULL)) {
150 |
151 | code = GetLastError();
152 |
153 | printf("DeviceIoControl failed with error 0x%lx\n", code);
154 | return(code);
155 |
156 | }
157 | printf("IOCTL worked!\n");
158 | break;
159 | case 0:
160 |
161 | //
162 | // zero is get out!
163 | //
164 | return(0);
165 |
166 | default:
167 | break;
168 |
169 | }
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/BasicUSB/README.md:
--------------------------------------------------------------------------------
1 | # Basic USB Driver #
2 | The Basic USB Driver is a KMDF USB driver that has all but the minimum functionality stripped out. It is written to support the OSR USB FX2 Learning Kit Device:
3 |
4 | [https://store.osr.com/product/osr-usb-fx2-learning-kit-v2/](https://store.osr.com/product/osr-usb-fx2-learning-kit-v2/)
5 |
6 | ## Building the Sample
7 | The provided solution builds with Visual Studio 2015 and the Windows 10 1607 Driver Kit.
8 |
9 | ## Installation ##
10 | The driver installs using the following command:
11 |
12 | devcon.exe update basicusb.inf USB\Vid_0547&Pid_1002
13 |
14 | The devcon utility can be found in the Tools subdirectory of the Windows Driver Kit installation
--------------------------------------------------------------------------------
/CDFilter/CDFilter.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.6.33815.320
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CDFilter", "CDFilter\CDFilter.vcxproj", "{D2087FC8-07D5-4D2C-8386-15FA250BD3CD}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {D2087FC8-07D5-4D2C-8386-15FA250BD3CD}.Debug|x64.ActiveCfg = Debug|x64
15 | {D2087FC8-07D5-4D2C-8386-15FA250BD3CD}.Debug|x64.Build.0 = Debug|x64
16 | {D2087FC8-07D5-4D2C-8386-15FA250BD3CD}.Debug|x64.Deploy.0 = Debug|x64
17 | {D2087FC8-07D5-4D2C-8386-15FA250BD3CD}.Release|x64.ActiveCfg = Release|x64
18 | {D2087FC8-07D5-4D2C-8386-15FA250BD3CD}.Release|x64.Build.0 = Release|x64
19 | {D2087FC8-07D5-4D2C-8386-15FA250BD3CD}.Release|x64.Deploy.0 = Release|x64
20 | EndGlobalSection
21 | GlobalSection(SolutionProperties) = preSolution
22 | HideSolutionNode = FALSE
23 | EndGlobalSection
24 | GlobalSection(ExtensibilityGlobals) = postSolution
25 | SolutionGuid = {892F605C-01DC-4E48-9EA7-EE7A34835927}
26 | EndGlobalSection
27 | EndGlobal
28 |
--------------------------------------------------------------------------------
/CDFilter/CDFilter/CDFilter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2023 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #include "CDFilter.h"
40 |
41 | ///////////////////////////////////////////////////////////////////////////////
42 | //
43 | // DriverEntry
44 | //
45 | // This routine is called by Windows when the driver is first loaded. It
46 | // is the responsibility of this routine to create the WDFDRIVER
47 | //
48 | // INPUTS:
49 | //
50 | // DriverObject - Address of the DRIVER_OBJECT created by Windows for this
51 | // driver.
52 | //
53 | // RegistryPath - UNICODE_STRING which represents this driver's key in the
54 | // Registry.
55 | //
56 | // OUTPUTS:
57 | //
58 | // None.
59 | //
60 | // RETURNS:
61 | //
62 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
63 | // load.
64 | //
65 | // IRQL:
66 | //
67 | // This routine is called at IRQL == PASSIVE_LEVEL.
68 | //
69 | // NOTES:
70 | //
71 | //
72 | ///////////////////////////////////////////////////////////////////////////////
73 | NTSTATUS
74 | DriverEntry(PDRIVER_OBJECT DriverObject,
75 | PUNICODE_STRING RegistryPath)
76 | {
77 | WDF_DRIVER_CONFIG driverConfig;
78 | NTSTATUS status;
79 |
80 | #if DBG
81 | DbgPrint("CDFilter: OSR CDFILTER Filter Driver...Compiled %s %s\n",
82 | __DATE__,
83 | __TIME__);
84 | #endif
85 |
86 | //
87 | // Initialize our driver config structure, specifying our
88 | // EvtDeviceAdd Event Processing Callback.
89 | //
90 | WDF_DRIVER_CONFIG_INIT(&driverConfig,
91 | CDFilterEvtDeviceAdd);
92 |
93 | //
94 | // Create the framework driver object...
95 | //
96 | status = WdfDriverCreate(DriverObject,
97 | RegistryPath,
98 | WDF_NO_OBJECT_ATTRIBUTES,
99 | &driverConfig,
100 | WDF_NO_HANDLE);
101 |
102 | if (!NT_SUCCESS(status)) {
103 | #if DBG
104 | DbgPrint("WdfDriverCreate failed - 0x%x\n",
105 | status);
106 | #endif
107 | }
108 |
109 | return status;
110 | }
111 |
112 | ///////////////////////////////////////////////////////////////////////////////
113 | //
114 | // CDFilterEvtDeviceAdd
115 | //
116 | // This routine is called by the framework when a device of
117 | // the type we filter is found in the system.
118 | //
119 | // INPUTS:
120 | //
121 | // DriverObject - Our WDFDRIVER object
122 | //
123 | // DeviceInit - The device initialization structure we'll
124 | // be using to create our WDFDEVICE
125 | //
126 | // OUTPUTS:
127 | //
128 | // None.
129 | //
130 | // RETURNS:
131 | //
132 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
133 | // load.
134 | //
135 | // IRQL:
136 | //
137 | // This routine is called at IRQL == PASSIVE_LEVEL.
138 | //
139 | // NOTES:
140 | //
141 | //
142 | ///////////////////////////////////////////////////////////////////////////////
143 | NTSTATUS
144 | CDFilterEvtDeviceAdd(WDFDRIVER Driver,
145 | PWDFDEVICE_INIT DeviceInit)
146 | {
147 | NTSTATUS status;
148 | WDF_OBJECT_ATTRIBUTES objAtttributes;
149 | WDFDEVICE wdfDevice;
150 | PFILTER_DEVICE_CONTEXT filterContext;
151 |
152 | UNREFERENCED_PARAMETER(Driver);
153 |
154 | #if DBG
155 | DbgPrint("CDFilter: Adding device...\n");
156 | #endif
157 |
158 | //
159 | // Indicate that we're creating a FILTER device. This will cause
160 | // KMDF to attach us correctly to the device stack, to automagically
161 | // set us to NOT be the Power Policy Owner and to auto-forward any
162 | // requests we don't explicitly handle down to our Local I/O Target.
163 | //
164 | WdfFdoInitSetFilter(DeviceInit);
165 |
166 | //
167 | // Setup our device attributes to have our context type
168 | //
169 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objAtttributes,
170 | FILTER_DEVICE_CONTEXT);
171 |
172 | //
173 | // And create our WDF device
174 | //
175 | status = WdfDeviceCreate(&DeviceInit,
176 | &objAtttributes,
177 | &wdfDevice);
178 |
179 | if (!NT_SUCCESS(status)) {
180 | #if DBG
181 | DbgPrint("WdfDeviceCreate failed - 0x%x\n",
182 | status);
183 | #endif
184 | goto Done;
185 | }
186 |
187 | filterContext = CDFilterGetDeviceContext(wdfDevice);
188 |
189 | filterContext->WdfDevice = wdfDevice;
190 |
191 | status = STATUS_SUCCESS;
192 |
193 | Done:
194 |
195 | return status;
196 | }
197 |
--------------------------------------------------------------------------------
/CDFilter/CDFilter/CDFilter.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | //
45 | // Our per device context
46 | //
47 | typedef struct _FILTER_DEVICE_CONTEXT {
48 |
49 | WDFDEVICE WdfDevice;
50 |
51 | WDFIOTARGET LocalTarget;
52 |
53 | } FILTER_DEVICE_CONTEXT, *PFILTER_DEVICE_CONTEXT;
54 |
55 |
56 | //
57 | // Context accessor function
58 | //
59 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FILTER_DEVICE_CONTEXT,
60 | CDFilterGetDeviceContext)
61 |
62 | extern "C" {
63 | DRIVER_INITIALIZE DriverEntry;
64 | }
65 |
66 | EVT_WDF_DRIVER_DEVICE_ADD CDFilterEvtDeviceAdd;
67 |
--------------------------------------------------------------------------------
/CDFilter/CDFilter/CDFilter.inf:
--------------------------------------------------------------------------------
1 | ;
2 | ; Installation file for a CDROM Upper Filter. For KMDF Filters
3 | ; it is assumed that the Framework is already installed and present
4 | ;
5 | ; Copyright (c) OSR Open Systems Resources, Inc.
6 | [Version]
7 | Signature = "$Windows NT$"
8 | Class = CDROM
9 | ClassGUID = {4d36e965-e325-11ce-bfc1-08002be10318}
10 | Provider = %Provider%
11 | DriverVer = 10/14/2013,1.0.0.0
12 | CatalogFile = CDFilter.cat
13 |
14 | ;
15 | ; General installation section
16 | ;
17 |
18 | [DefaultInstall.NTAMD64]
19 | CopyFiles = @CDFilter.sys
20 | Addreg = CDFilter.AddReg
21 |
22 | [DestinationDirs]
23 | DefaultDestDir = 12
24 |
25 | [CDFilter.AddReg]
26 | HKLM, System\CurrentControlSet\Control\Class\{4d36e965-e325-11ce-bfc1-08002be10318}, UpperFilters, 0x00010008, %DriverName%
27 |
28 |
29 | ;
30 | ; Service installation section
31 | ;
32 |
33 | [DefaultInstall.NTAMD64.Services]
34 | AddService = CDFilter, , CDFilter.Service.Install
35 |
36 | [CDFilter.Service.Install]
37 | DisplayName = %ServiceName%
38 | Description = %ServiceDescription%
39 | ServiceBinary = %12%\%DriverName%.sys ;%windir%\system32\drivers\
40 | ServiceType = 1 ;SERVICE_KERNEL_DRIVER
41 | StartType = 3 ;SERVICE_DEMAND_START
42 | ErrorControl = 1 ;SERVICE_ERROR_NORMAL
43 | AddReg = KMDFVerifierAddReg
44 |
45 |
46 | [KMDFVerifierAddReg]
47 | HKR, Parameters\Wdf,VerifierOn,0x00010001,0
48 | HKR, Parameters\Wdf,VerboseOn,0x00010001,0
49 | HKR, Parameters\Wdf,DbgBreakOnError,0x00010001,0
50 |
51 |
52 | [SourceDisksFiles]
53 | CDFilter.sys=1
54 |
55 | [SourceDisksNames]
56 | 1 = %DiskId1%
57 |
58 | ;
59 | ; Localizable Strings
60 | ;
61 |
62 | [Strings]
63 | Provider = "OSR Open Systems Resources, Inc."
64 | ServiceDescription = "Example CDROM Upper Filter"
65 | ServiceName = "CDFilter"
66 | DriverName = "CDFilter"
67 | DiskId1 = "Example CDROM Upper Filter Installation Disk"
68 |
--------------------------------------------------------------------------------
/CDFilter/CDFilter/CDFilter.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {D2087FC8-07D5-4D2C-8386-15FA250BD3CD}
23 | {1bc93793-694f-48fe-9372-81e2b05556fd}
24 | v4.5
25 | 12.0
26 | Debug
27 | Win32
28 | CDFilter
29 |
30 |
31 |
32 | Windows10
33 | true
34 | WindowsKernelModeDriver10.0
35 | Driver
36 | KMDF
37 | Desktop
38 |
39 |
40 | Windows10
41 | false
42 | WindowsKernelModeDriver10.0
43 | Driver
44 | KMDF
45 | Desktop
46 |
47 |
48 | Windows10
49 | true
50 | WindowsKernelModeDriver10.0
51 | Driver
52 | KMDF
53 | Desktop
54 |
55 |
56 | Windows10
57 | false
58 | WindowsKernelModeDriver10.0
59 | Driver
60 | KMDF
61 | Desktop
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | DbgengKernelDebugger
73 | false
74 |
75 |
76 | DbgengKernelDebugger
77 | false
78 |
79 |
80 | DbgengKernelDebugger
81 | false
82 |
83 |
84 | DbgengKernelDebugger
85 | false
86 |
87 |
88 |
89 | Level3
90 |
91 |
92 | SHA256
93 |
94 |
95 |
96 |
97 | Level3
98 |
99 |
100 | SHA256
101 |
102 |
103 |
104 |
105 | Level3
106 |
107 |
108 | SHA256
109 |
110 |
111 |
112 |
113 | Level3
114 |
115 |
116 | SHA256
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/CDFilter/CDFilter/CDFilter.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 | {8E41214B-6785-4CFE-B992-037D68949A14}
18 | inf;inv;inx;mof;mc;
19 |
20 |
21 |
22 |
23 | Driver Files
24 |
25 |
26 |
27 |
28 | Source Files
29 |
30 |
31 |
32 |
33 | Header Files
34 |
35 |
36 |
--------------------------------------------------------------------------------
/CDFilter/CDFilter/CDFilter.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CDFilter/README.md:
--------------------------------------------------------------------------------
1 | # KMDF CD-ROM Filter #
2 | This is a skeletal KMDF filter driver with a provided INF to install over the CD-ROM class.
3 |
4 | ## Building the Sample
5 | The provided solution builds with Visual Studio 2015 and the Windows 10 1607 Driver Kit.
6 |
7 | ## Installation ##
8 | To install the filter, right click the provided INF and select Install.
--------------------------------------------------------------------------------
/Docs_and_Misc/WDF Lab Exercises.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OSRDrivers/WDF-I/189166af8658f2ca9864fa2598c172e44135c4bd/Docs_and_Misc/WDF Lab Exercises.pdf
--------------------------------------------------------------------------------
/Docs_and_Misc/empty.iso:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OSRDrivers/WDF-I/189166af8658f2ca9864fa2598c172e44135c4bd/Docs_and_Misc/empty.iso
--------------------------------------------------------------------------------
/Nothing_KMDF/Inc/nothing_ioctl.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | // ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | // CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | // CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
28 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | // POSSIBILITY OF SUCH DAMAGE
30 | //
31 | #pragma once
32 |
33 |
34 | //
35 | // Generate our device interface GUID
36 | //
37 | #include // required for GUID definitions
38 | DEFINE_GUID(GUID_DEVINTERFACE_NOTHING,
39 | 0x79963ae7, 0x45de, 0x4a31, 0x8f, 0x34, 0xf0, 0xe8, 0x90, 0xb, 0xc2, 0x17);
40 |
41 |
42 | //
43 | // The following value is arbitrarily chosen from the space defined by Microsoft
44 | // as being "for non-Microsoft use"
45 | //
46 | #define FILE_DEVICE_NOTHING 0xCF53
47 |
48 | //
49 | // Device control codes - values between 2048 and 4095 arbitrarily chosen
50 | //
51 | #define IOCTL_OSR_NOTHING CTL_CODE(FILE_DEVICE_NOTHING, 2049, METHOD_BUFFERED, FILE_ANY_ACCESS)
52 |
53 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF Test/Nothing_KMDF Test.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {55640215-9CDA-40BC-925F-5FEE7287739D}
23 | Win32Proj
24 | Nothing_KMDFTest
25 | 10.0
26 |
27 |
28 |
29 | Application
30 | true
31 | v143
32 | Unicode
33 |
34 |
35 | Application
36 | false
37 | v143
38 | true
39 | Unicode
40 |
41 |
42 | Application
43 | true
44 | v143
45 | Unicode
46 |
47 |
48 | Application
49 | false
50 | v143
51 | true
52 | Unicode
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | true
74 | $(WindowsSDK_IncludePath);$(VC_IncludePath);$(ProjectDir)\..\Inc
75 | nothingtest
76 |
77 |
78 | true
79 | $(WindowsSDK_IncludePath);$(VC_IncludePath);$(ProjectDir)\..\Inc
80 | nothingtest
81 | false
82 |
83 |
84 | false
85 | $(WindowsSDK_IncludePath);$(VC_IncludePath);$(ProjectDir)\..\Inc
86 | nothingtest
87 |
88 |
89 | false
90 | $(WindowsSDK_IncludePath);$(VC_IncludePath);$(ProjectDir)\..\Inc
91 | nothingtest
92 |
93 |
94 |
95 |
96 |
97 | Level3
98 | Disabled
99 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
100 | MultiThreadedDebug
101 |
102 |
103 | Console
104 | true
105 | Setupapi.lib;%(AdditionalDependencies)
106 |
107 |
108 |
109 |
110 |
111 |
112 | Level3
113 | Disabled
114 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
115 | MultiThreadedDebug
116 |
117 |
118 | Console
119 | true
120 | Setupapi.lib;%(AdditionalDependencies)
121 |
122 |
123 |
124 |
125 | Level3
126 |
127 |
128 | MaxSpeed
129 | true
130 | true
131 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
132 | MultiThreaded
133 |
134 |
135 | Console
136 | true
137 | true
138 | true
139 | Setupapi.lib;%(AdditionalDependencies)
140 |
141 |
142 |
143 |
144 | Level3
145 |
146 |
147 | MaxSpeed
148 | true
149 | true
150 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
151 | MultiThreaded
152 |
153 |
154 | Console
155 | true
156 | true
157 | true
158 | Setupapi.lib;%(AdditionalDependencies)
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF Test/Nothing_KMDF Test.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF Test/Nothing_KMDF Test.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF Test/nothingtest.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // NOTHINGTEST.CPP
3 | //
4 | // Test utility for the OSR Nothing driver, which was created for our WDF seminar.
5 | //
6 | // This code is purely functional, and is definitely not designed to be any
7 | // sort of example.
8 | //
9 | #define _CRT_SECURE_NO_WARNINGS
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | HANDLE
17 | OpenNothingDeviceViaInterface(
18 | VOID);
19 |
20 | //
21 | // Simple test application to demonstrate the Nothing driver
22 | //
23 |
24 | int
25 | __cdecl
26 | main(ULONG argc,
27 | LPSTR* argv)
28 | {
29 | HANDLE deviceHandle;
30 | DWORD code;
31 | UCHAR writeBuffer[4096];
32 | UCHAR readBuffer[9096];
33 | DWORD bytesRead;
34 | DWORD index;
35 | DWORD function;
36 |
37 | UNREFERENCED_PARAMETER(argv);
38 |
39 | //
40 | // Init the write and read buffers with known data
41 | //
42 | memset(readBuffer,
43 | 0xAA,
44 | sizeof(readBuffer));
45 |
46 | memset(writeBuffer,
47 | 0xEE,
48 | sizeof(writeBuffer));
49 |
50 | //
51 | // Check to see if the user wants to open the device via the
52 | // interface
53 | //
54 | if (argc == 2) {
55 |
56 | //
57 | // An argument specified (we're lazy, we don't care what it is)
58 | // try to open via the interface
59 | //
60 | deviceHandle = OpenNothingDeviceViaInterface();
61 |
62 | } else {
63 |
64 | printf("Opening Nothing device via its name. Specify -i to open via "
65 | "Device Interface\n\n");
66 |
67 | //
68 | // Open the nothing device by name
69 | //
70 | deviceHandle = CreateFile(L"\\\\.\\NOTHING",
71 | GENERIC_READ | GENERIC_WRITE,
72 | 0,
73 | nullptr,
74 | OPEN_EXISTING,
75 | 0,
76 | nullptr);
77 | }
78 |
79 | //
80 | // If this call fails, check to figure out what the error is and report it.
81 | //
82 | if (deviceHandle == INVALID_HANDLE_VALUE) {
83 |
84 | code = GetLastError();
85 |
86 | printf("CreateFile failed with error 0x%lx\n",
87 | code);
88 |
89 | return (code);
90 | }
91 |
92 | //
93 | // Infinitely print out the list of choices, ask for input, process
94 | // the request
95 | //
96 | while (TRUE) {
97 |
98 | printf("\nNOTHING TEST -- functions:\n\n");
99 | printf("\t1. Send a READ\n");
100 | printf("\t2. Send a WRITE\n");
101 | printf("\t3. Print READ buffer\n");
102 | printf("\t4. Print WRITE buffer\n");
103 | printf("\t5. Send NOTHING IOCTL\n");
104 | printf("\n\t0. Exit\n");
105 | printf("\n\tSelection: ");
106 |
107 | #pragma warning(suppress: 6031)
108 | scanf("%lx",
109 | &function); // NOLINT(cert-err34-c)
110 |
111 | switch (function) {
112 |
113 | case 1:
114 | //
115 | // Send a read
116 | //
117 | if (!ReadFile(deviceHandle,
118 | readBuffer,
119 | sizeof(readBuffer),
120 | &bytesRead,
121 | nullptr)) {
122 |
123 | code = GetLastError();
124 |
125 | printf("ReadFile failed with error 0x%lx\n",
126 | code);
127 |
128 | return (code);
129 | }
130 |
131 | printf("Read Success! Bytes Read = %lu.\n",
132 | bytesRead);
133 |
134 | break;
135 |
136 | case 2:
137 | //
138 | // Send a write
139 | //
140 | if (!WriteFile(deviceHandle,
141 | writeBuffer,
142 | sizeof(writeBuffer),
143 | &bytesRead,
144 | nullptr)) {
145 |
146 | code = GetLastError();
147 |
148 | printf("WriteFile failed with error 0x%lx\n",
149 | code);
150 |
151 | return (code);
152 | }
153 |
154 | printf("Write Success! Bytes Written = %lu.\n",
155 | bytesRead);
156 |
157 | break;
158 |
159 | case 3:
160 | //
161 | // Show read buffer
162 | //
163 | printf("Printing first 32 bytes of READ buffer\n");
164 |
165 | for (index = 0; index < 32; index++) {
166 |
167 | printf("0x%0x,",
168 | readBuffer[index]);
169 | }
170 |
171 | break;
172 |
173 | case 4:
174 | //
175 | // Show WRITE buffer
176 | //
177 | printf("Printing first 32 bytes of WRITE buffer\n");
178 |
179 | for (index = 0; index < 32; index++) {
180 |
181 | printf("0x%0x,",
182 | writeBuffer[index]);
183 | }
184 |
185 | break;
186 |
187 | case 5:
188 | //
189 | // Test the IOCTL interface
190 | //
191 | if (!DeviceIoControl(deviceHandle,
192 | (DWORD)IOCTL_OSR_NOTHING,
193 | nullptr,
194 | 0,
195 | nullptr,
196 | 0,
197 | &bytesRead,
198 | nullptr)) {
199 |
200 | code = GetLastError();
201 |
202 | printf("DeviceIoControl failed with error 0x%lx\n",
203 | code);
204 |
205 | return (code);
206 | }
207 |
208 | printf("DeviceIoControl Success! Bytes Read = %lu.\n",
209 | bytesRead);
210 |
211 | break;
212 |
213 | case 0:
214 |
215 | //
216 | // zero is get out!
217 | //
218 | return (0);
219 |
220 | default:
221 | break;
222 |
223 | }
224 | }
225 | }
226 |
227 |
228 | HANDLE
229 | OpenNothingDeviceViaInterface()
230 | {
231 | CONFIGRET configReturn;
232 | DWORD lasterror;
233 | WCHAR deviceName[MAX_DEVICE_ID_LEN];
234 | HANDLE handleToReturn = INVALID_HANDLE_VALUE;
235 |
236 | //
237 | // Get the device interface -- we only expose one
238 | //
239 | deviceName[0] = UNICODE_NULL;
240 |
241 | configReturn = CM_Get_Device_Interface_List((LPGUID)&GUID_DEVINTERFACE_NOTHING,
242 | nullptr,
243 | deviceName,
244 | _countof(deviceName),
245 | CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
246 | if (configReturn != CR_SUCCESS) {
247 |
248 | lasterror = GetLastError();
249 |
250 | printf("CM_Get_Device_Interface_List fail: %lx\n",
251 | lasterror);
252 |
253 | goto Exit;
254 | }
255 |
256 | //
257 | // Make sure there's an actual name there
258 | //
259 | if (deviceName[0] == UNICODE_NULL) {
260 | lasterror = ERROR_NOT_FOUND;
261 | printf("CreateFile fail: %lx\n",
262 | lasterror);
263 | goto Exit;
264 | }
265 |
266 | //
267 | // Open the device
268 | //
269 | handleToReturn = CreateFile(deviceName,
270 | GENERIC_WRITE | GENERIC_READ,
271 | 0,
272 | nullptr,
273 | OPEN_EXISTING,
274 | 0,
275 | nullptr);
276 |
277 | if (handleToReturn == INVALID_HANDLE_VALUE) {
278 | lasterror = GetLastError();
279 | printf("CreateFile fail: %lx\n",
280 | lasterror);
281 | }
282 |
283 | Exit:
284 |
285 | //
286 | // Return a handle to the device
287 | //
288 | return handleToReturn;
289 | }
290 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.6.33815.320
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nothing_KMDF", "Nothing_KMDF\Nothing_KMDF.vcxproj", "{F08060C0-0618-4C0A-AC82-FFFE0B3E7220}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nothing_KMDF Test", "Nothing_KMDF Test\Nothing_KMDF Test.vcxproj", "{55640215-9CDA-40BC-925F-5FEE7287739D}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|x64 = Debug|x64
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {F08060C0-0618-4C0A-AC82-FFFE0B3E7220}.Debug|x64.ActiveCfg = Debug|x64
17 | {F08060C0-0618-4C0A-AC82-FFFE0B3E7220}.Debug|x64.Build.0 = Debug|x64
18 | {F08060C0-0618-4C0A-AC82-FFFE0B3E7220}.Debug|x64.Deploy.0 = Debug|x64
19 | {F08060C0-0618-4C0A-AC82-FFFE0B3E7220}.Release|x64.ActiveCfg = Release|x64
20 | {F08060C0-0618-4C0A-AC82-FFFE0B3E7220}.Release|x64.Build.0 = Release|x64
21 | {F08060C0-0618-4C0A-AC82-FFFE0B3E7220}.Release|x64.Deploy.0 = Release|x64
22 | {55640215-9CDA-40BC-925F-5FEE7287739D}.Debug|x64.ActiveCfg = Debug|x64
23 | {55640215-9CDA-40BC-925F-5FEE7287739D}.Debug|x64.Build.0 = Debug|x64
24 | {55640215-9CDA-40BC-925F-5FEE7287739D}.Release|x64.ActiveCfg = Release|x64
25 | {55640215-9CDA-40BC-925F-5FEE7287739D}.Release|x64.Build.0 = Release|x64
26 | EndGlobalSection
27 | GlobalSection(SolutionProperties) = preSolution
28 | HideSolutionNode = FALSE
29 | EndGlobalSection
30 | GlobalSection(ExtensibilityGlobals) = postSolution
31 | SolutionGuid = {4A338168-FDCD-400A-8DC5-942AED884C39}
32 | EndGlobalSection
33 | EndGlobal
34 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF/Nothing.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2023 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #include "nothing.h"
40 |
41 | ///////////////////////////////////////////////////////////////////////////////
42 | //
43 | // DriverEntry
44 | //
45 | // This routine is called by Windows when the driver is first loaded. It
46 | // is the responsibility of this routine to create the WDFDRIVER
47 | //
48 | // INPUTS:
49 | //
50 | // DriverObject - Address of the DRIVER_OBJECT created by Windows for this
51 | // driver.
52 | //
53 | // RegistryPath - UNICODE_STRING which represents this driver's key in the
54 | // Registry.
55 | //
56 | // OUTPUTS:
57 | //
58 | // None.
59 | //
60 | // RETURNS:
61 | //
62 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
63 | // load.
64 | //
65 | // IRQL:
66 | //
67 | // This routine is called at IRQL == PASSIVE_LEVEL.
68 | //
69 | // NOTES:
70 | //
71 | //
72 | ///////////////////////////////////////////////////////////////////////////////
73 | NTSTATUS
74 | DriverEntry(PDRIVER_OBJECT DriverObject,
75 | PUNICODE_STRING RegistryPath)
76 | {
77 | WDF_DRIVER_CONFIG driverConfig;
78 | NTSTATUS status;
79 |
80 | #if DBG
81 | DbgPrint("\nOSR Nothing Driver -- Compiled %s %s\n",
82 | __DATE__,
83 | __TIME__);
84 | #endif
85 |
86 | //
87 | // Provide pointer to our EvtDeviceAdd event processing callback
88 | // function
89 | //
90 | WDF_DRIVER_CONFIG_INIT(&driverConfig,
91 | NothingEvtDeviceAdd);
92 |
93 | //
94 | // Create our WDFDriver instance
95 | //
96 | status = WdfDriverCreate(DriverObject,
97 | RegistryPath,
98 | WDF_NO_OBJECT_ATTRIBUTES,
99 | &driverConfig,
100 | WDF_NO_HANDLE);
101 |
102 | if (!NT_SUCCESS(status)) {
103 | #if DBG
104 | DbgPrint("WdfDriverCreate failed 0x%0x\n",
105 | status);
106 | #endif
107 | }
108 |
109 | return (status);
110 | }
111 |
112 | ///////////////////////////////////////////////////////////////////////////////
113 | //
114 | // NothingEvtDeviceAdd
115 | //
116 | // This routine is called by the framework when a device of
117 | // the type we support is found in the system.
118 | //
119 | // INPUTS:
120 | //
121 | // DriverObject - Our WDFDRIVER object
122 | //
123 | // DeviceInit - The device initialization structure we'll
124 | // be using to create our WDFDEVICE
125 | //
126 | // OUTPUTS:
127 | //
128 | // None.
129 | //
130 | // RETURNS:
131 | //
132 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
133 | // load.
134 | //
135 | // IRQL:
136 | //
137 | // This routine is called at IRQL == PASSIVE_LEVEL.
138 | //
139 | // NOTES:
140 | //
141 | //
142 | ///////////////////////////////////////////////////////////////////////////////
143 | NTSTATUS
144 | NothingEvtDeviceAdd(WDFDRIVER Driver,
145 | PWDFDEVICE_INIT DeviceInit)
146 | {
147 | NTSTATUS status;
148 | WDF_OBJECT_ATTRIBUTES objAttributes;
149 | WDFDEVICE device;
150 | WDF_IO_QUEUE_CONFIG queueConfig;
151 |
152 | #ifdef _KERNEL_MODE
153 |
154 | DECLARE_CONST_UNICODE_STRING(userDeviceName,
155 | L"\\DosDevices\\Nothing");
156 | #else
157 |
158 | DECLARE_CONST_UNICODE_STRING(userDeviceName,
159 | L"\\DosDevices\\Global\\Nothing");
160 | #endif
161 |
162 | UNREFERENCED_PARAMETER(Driver);
163 |
164 | //
165 | // Life is nice and simple in this driver...
166 | //
167 | // We don't need ANY PnP/Power Event Processing callbacks. There's no
168 | // hardware, thus we don't need EvtPrepareHardware or EvtReleaseHardware
169 | // There's no power state to handle so we don't need EvtD0Entry or EvtD0Exit.
170 | //
171 |
172 | //
173 | // Prepare for WDFDEVICE creation
174 | //
175 |
176 | WDF_OBJECT_ATTRIBUTES_INIT(&objAttributes);
177 |
178 | //
179 | // Specify our device context
180 | //
181 | WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&objAttributes,
182 | NOTHING_DEVICE_CONTEXT);
183 |
184 | //
185 | // Create our device object
186 | //
187 | status = WdfDeviceCreate(&DeviceInit,
188 | &objAttributes,
189 | &device);
190 |
191 | if (!NT_SUCCESS(status)) {
192 | #if DBG
193 | DbgPrint("WdfDeviceCreate failed 0x%0x\n",
194 | status);
195 | #endif
196 | goto Done;
197 | }
198 |
199 | //
200 | // Create a symbolic link to our Device Object. This allows apps
201 | // to open our device by name. Note that we use a constant name,
202 | // so this driver will support only a single instance of our device.
203 | //
204 | status = WdfDeviceCreateSymbolicLink(device,
205 | &userDeviceName);
206 |
207 | if (!NT_SUCCESS(status)) {
208 | #if DBG
209 | DbgPrint("WdfDeviceCreateSymbolicLink failed 0x%0x\n",
210 | status);
211 | #endif
212 | goto Done;
213 | }
214 |
215 | //
216 | // Configure our Queue of incoming requests
217 | //
218 | // We use only the default Queue, and we set it for sequential processing.
219 | // This means that the driver will only receive one request at a time
220 | // from the Queue, and will not get another request until it completes
221 | // the previous one.
222 | //
223 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig,
224 | WdfIoQueueDispatchSequential);
225 |
226 | //
227 | // Define our I/O Event Processing callbacks
228 | //
229 | // We handle, read, write, and device control (IOCTL) requests.
230 | //
231 | // WDF will automagically handle Create and Close requests for us and will
232 | // complete any other request types with STATUS_INVALID_DEVICE_REQUEST.
233 | //
234 | queueConfig.EvtIoRead = NothingEvtRead;
235 | queueConfig.EvtIoWrite = NothingEvtWrite;
236 | queueConfig.EvtIoDeviceControl = NothingEvtDeviceControl;
237 |
238 | //
239 | // Because this is a queue for a software-only device, indicate
240 | // that the queue doesn't need to be power managed.
241 | //
242 | queueConfig.PowerManaged = WdfFalse;
243 |
244 | status = WdfIoQueueCreate(device,
245 | &queueConfig,
246 | WDF_NO_OBJECT_ATTRIBUTES,
247 | WDF_NO_HANDLE);
248 |
249 | if (!NT_SUCCESS(status)) {
250 | #if DBG
251 | DbgPrint("WdfIoQueueCreate for default queue failed 0x%0x\n",
252 | status);
253 | #endif
254 | goto Done;
255 | }
256 |
257 | status = STATUS_SUCCESS;
258 |
259 | Done:
260 |
261 | return (status);
262 | }
263 |
264 | ///////////////////////////////////////////////////////////////////////////////
265 | //
266 | // NothingEvtRead
267 | //
268 | // This routine is called by the Framework when there is a
269 | // read request for us to process
270 | //
271 | // INPUTS:
272 | //
273 | // Queue - Our default queue
274 | //
275 | // Request - A read request
276 | //
277 | // Length - The length of the read operation
278 | //
279 | // OUTPUTS:
280 | //
281 | // None.
282 | //
283 | // RETURNS:
284 | //
285 | // None.
286 | //
287 | // IRQL:
288 | //
289 | // This routine is called at IRQL <= DISPATCH_LEVEL
290 | //
291 | // NOTES:
292 | //
293 | //
294 | ///////////////////////////////////////////////////////////////////////////////
295 | VOID
296 | NothingEvtRead(WDFQUEUE Queue,
297 | WDFREQUEST Request,
298 | size_t Length)
299 | {
300 | PNOTHING_DEVICE_CONTEXT devContext;
301 |
302 | UNREFERENCED_PARAMETER(Length);
303 |
304 | #if DBG
305 | DbgPrint("NothingEvtRead\n");
306 | #endif
307 |
308 | //
309 | // Get a pointer to our device extension, just to show how it's done.
310 | // (get the WDFDEVICE from the WDFQUEUE, and the extension from the device)
311 | //
312 | devContext = NothingGetContextFromDevice(
313 | WdfIoQueueGetDevice(Queue));
314 |
315 | //
316 | // Nothing to do...
317 | // We're returning zero bytes, so fill that into the information field
318 | //
319 | WdfRequestCompleteWithInformation(Request,
320 | STATUS_SUCCESS,
321 | 0);
322 | }
323 |
324 | ///////////////////////////////////////////////////////////////////////////////
325 | //
326 | // NothingEvtWrite
327 | //
328 | // This routine is called by the Framework when there is a
329 | // write request for us to process
330 | //
331 | // INPUTS:
332 | //
333 | // Queue - Our default queue
334 | //
335 | // Request - A write request
336 | //
337 | // Length - The length of the write operation
338 | //
339 | // OUTPUTS:
340 | //
341 | // None.
342 | //
343 | // RETURNS:
344 | //
345 | // None.
346 | //
347 | // IRQL:
348 | //
349 | // This routine is called at IRQL <= DISPATCH_LEVEL
350 | //
351 | // NOTES:
352 | //
353 | //
354 | ///////////////////////////////////////////////////////////////////////////////
355 | VOID
356 | NothingEvtWrite(WDFQUEUE Queue,
357 | WDFREQUEST Request,
358 | size_t Length)
359 | {
360 | UNREFERENCED_PARAMETER(Queue);
361 |
362 | #if DBG
363 | DbgPrint("NothingEvtWrite\n");
364 | #endif
365 |
366 | //
367 | // Nothing to do...
368 | //
369 | WdfRequestCompleteWithInformation(Request,
370 | STATUS_SUCCESS,
371 | Length);
372 | }
373 |
374 | ///////////////////////////////////////////////////////////////////////////////
375 | //
376 | // NothingEvtDeviceControl
377 | //
378 | // This routine is called by the Framework when there is a
379 | // device control request for us to process
380 | //
381 | // INPUTS:
382 | //
383 | // Queue - Our default queue
384 | //
385 | // Request - A device control request
386 | //
387 | // OutputBufferLength - The length of the output buffer
388 | //
389 | // InputBufferLength - The length of the input buffer
390 | //
391 | // IoControlCode - The operation being performed
392 | //
393 | // OUTPUTS:
394 | //
395 | // None.
396 | //
397 | // RETURNS:
398 | //
399 | // None.
400 | //
401 | // IRQL:
402 | //
403 | // This routine is called at IRQL <= DISPATCH_LEVEL
404 | //
405 | // NOTES:
406 | //
407 | //
408 | ///////////////////////////////////////////////////////////////////////////////
409 | VOID
410 | NothingEvtDeviceControl(WDFQUEUE Queue,
411 | WDFREQUEST Request,
412 | size_t OutputBufferLength,
413 | size_t InputBufferLength,
414 | ULONG IoControlCode)
415 | {
416 | UNREFERENCED_PARAMETER(IoControlCode);
417 | UNREFERENCED_PARAMETER(InputBufferLength);
418 | UNREFERENCED_PARAMETER(OutputBufferLength);
419 | UNREFERENCED_PARAMETER(Queue);
420 |
421 | #if DBG
422 | DbgPrint("NothingEvtDeviceControl\n");
423 | #endif
424 |
425 | //
426 | // Nothing to do...
427 | // In this case, we return an info field of zero
428 | //
429 | WdfRequestCompleteWithInformation(Request,
430 | STATUS_SUCCESS,
431 | 0);
432 | }
433 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF/Nothing_KMDF.inf:
--------------------------------------------------------------------------------
1 | ;
2 | ; Nothing_KMDF.inf
3 | ;
4 |
5 | [Version]
6 | Signature="$WINDOWS NT$"
7 | Class=OsrNothingClass
8 | ClassGuid={37E1E5FF-C046-4AA9-81EE-D379F14E61F1} ; OSR Example class
9 | Provider=%ManufacturerName%
10 | CatalogFile=Nothing_KMDF.cat
11 | DriverVer= ; TODO: set DriverVer in stampinf property pages
12 |
13 | [DestinationDirs]
14 | DefaultDestDir = 12
15 |
16 | ; ================= Class section =====================
17 | [ClassInstall32]
18 | Addreg=OsrNothingClass
19 |
20 | [OsrNothingClass]
21 | HKR,,,0,%ClassName%
22 | HKR,,Icon,,-5
23 |
24 | [SourceDisksNames]
25 | 1 = %DiskName%,,,""
26 |
27 | [SourceDisksFiles]
28 | Nothing_KMDF.sys = 1,,
29 |
30 | ;*****************************************
31 | ; Install Section
32 | ;*****************************************
33 |
34 | [Manufacturer]
35 | %ManufacturerName%=Standard,NT$ARCH$
36 |
37 | [Standard.NT$ARCH$]
38 | %Nothing_KMDF.DeviceDesc%=Nothing_KMDF_Device, Root\Nothing
39 |
40 | [Nothing_KMDF_Device.NT]
41 | CopyFiles=Drivers_Dir
42 |
43 | [Drivers_Dir]
44 | Nothing_KMDF.sys
45 |
46 | ;-------------- Service installation
47 | [Nothing_KMDF_Device.NT.Services]
48 | AddService = Nothing_KMDF,%SPSVCINST_ASSOCSERVICE%, Nothing_KMDF_Service_Inst
49 |
50 | ; -------------- Nothing_KMDF driver install sections
51 | [Nothing_KMDF_Service_Inst]
52 | DisplayName = %Nothing_KMDF.SVCDESC%
53 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER
54 | StartType = 3 ; SERVICE_DEMAND_START
55 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL
56 | ServiceBinary = %12%\Nothing_KMDF.sys
57 | AddReg = KMDFVerifierAddReg
58 |
59 | [KMDFVerifierAddReg]
60 | HKR, Parameters\Wdf,VerifierOn,0x00010001,1
61 | HKR, Parameters\Wdf,VerboseOn,0x00010001,1
62 | HKR, Parameters\Wdf,DbgBreakOnError,0x00010001,1
63 |
64 | [Strings]
65 | SPSVCINST_ASSOCSERVICE= 0x00000002
66 | ManufacturerName="OSR Open Systems Resources, Inc."
67 | ClassName="OSR Example Devices"
68 | DiskName = "Nothing_KMDF Installation Disk"
69 | Nothing_KMDF.DeviceDesc = "OSR's Nothing_KMDF Device"
70 | Nothing_KMDF.SVCDESC = "OSR's Nothing_KMDF Service"
71 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF/Nothing_KMDF.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {F08060C0-0618-4C0A-AC82-FFFE0B3E7220}
23 | {1bc93793-694f-48fe-9372-81e2b05556fd}
24 | v4.5
25 | 12.0
26 | Debug
27 | Win32
28 | Nothing_KMDF
29 |
30 |
31 |
32 | Windows10
33 | true
34 | WindowsKernelModeDriver10.0
35 | Driver
36 | KMDF
37 | Desktop
38 |
39 |
40 | Windows10
41 | false
42 | WindowsKernelModeDriver10.0
43 | Driver
44 | KMDF
45 | Desktop
46 |
47 |
48 | Windows10
49 | true
50 | WindowsKernelModeDriver10.0
51 | Driver
52 | KMDF
53 | Desktop
54 |
55 |
56 | Windows10
57 | false
58 | WindowsKernelModeDriver10.0
59 | Driver
60 | KMDF
61 | Desktop
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | DbgengKernelDebugger
73 | $(ProjectDir);$(IncludePath);$(ProjectDir)\..\inc
74 | false
75 |
76 |
77 | DbgengKernelDebugger
78 | $(ProjectDir);$(IncludePath);$(ProjectDir)\..\inc
79 | false
80 |
81 |
82 | DbgengKernelDebugger
83 | $(ProjectDir);$(IncludePath);$(ProjectDir)\..\inc
84 | false
85 |
86 |
87 | DbgengKernelDebugger
88 | $(ProjectDir);$(IncludePath);$(ProjectDir)\..\inc
89 | false
90 |
91 |
92 |
93 | Level3
94 |
95 |
96 | SHA256
97 |
98 |
99 |
100 |
101 | Level3
102 |
103 |
104 | SHA256
105 |
106 |
107 |
108 |
109 | Level3
110 |
111 |
112 | SHA256
113 |
114 |
115 |
116 |
117 | Level3
118 |
119 |
120 | SHA256
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF/Nothing_KMDF.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 | {8E41214B-6785-4CFE-B992-037D68949A14}
18 | inf;inv;inx;mof;mc;
19 |
20 |
21 |
22 |
23 | Driver Files
24 |
25 |
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 |
35 |
36 | Source Files
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF/Nothing_KMDF.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Nothing_KMDF/Nothing_KMDF/nothing.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | //
41 | // We define our own symbol to indicate whether we're doing a KMDF or UMDF
42 | // build, because ReSharper sometimes gets confused when using pre-processor
43 | // symbols that are only defined on the command-line. This fixes that.
44 | //
45 | #define BUILDING_IN_KERNEL_MODE _KERNEL_MODE
46 |
47 | #ifndef BUILDING_IN_KERNEL_MODE
48 |
49 | //
50 | // Building the driver using UMDF
51 | //
52 | #include
53 |
54 | #else
55 |
56 | //
57 | // Building the driver using KMDF
58 | //
59 | #include
60 |
61 | #endif
62 |
63 | #include
64 |
65 | #include "NOTHING_IOCTL.h"
66 |
67 | //
68 | // Nothing device context structure
69 | //
70 | // KMDF will associate this structure with each "Nothing" device that
71 | // this driver creates.
72 | //
73 | typedef struct _NOTHING_DEVICE_CONTEXT {
74 |
75 | ULONG Nothing;
76 |
77 | } NOTHING_DEVICE_CONTEXT, *PNOTHING_DEVICE_CONTEXT;
78 |
79 | //
80 | // Accessor structure
81 | //
82 | // Given a WDFDEVICE handle, we'll use the following function to return
83 | // a pointer to our device's context area.
84 | //
85 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(NOTHING_DEVICE_CONTEXT,
86 | NothingGetContextFromDevice)
87 |
88 | //
89 | // Forward declarations
90 | //
91 | extern "C" {
92 | DRIVER_INITIALIZE DriverEntry;
93 | }
94 | EVT_WDF_DRIVER_DEVICE_ADD NothingEvtDeviceAdd;
95 | EVT_WDF_IO_QUEUE_IO_READ NothingEvtRead;
96 | EVT_WDF_IO_QUEUE_IO_WRITE NothingEvtWrite;
97 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL NothingEvtDeviceControl;
98 |
--------------------------------------------------------------------------------
/Nothing_KMDF/README.md:
--------------------------------------------------------------------------------
1 | # KMDF Nothing Driver #
2 | The Nothing Driver is OSR's classic "do nothing" example. It is a Root Enumerated device driver that supports both read and write operations with the provided test application.
3 |
4 | ## Building the Sample
5 | The provided solution builds with Visual Studio 2015 and the Windows 10 1607 Driver Kit.
6 |
7 | ## Installation ##
8 | The driver installs using the following command:
9 |
10 | devcon.exe install nothing_kmdf.inf root\Nothing
11 |
12 | The devcon utility can be found in the Tools subdirectory of the Windows Driver Kit installation
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Driver samples for Writing WDF Drivers I: Core Concepts #
2 | These are the starting samples that we use for exercises during our 5-day lecture and lab:
3 |
4 | [https://www.osr.com/seminars/wdf-drivers/](https://www.osr.com/seminars/wdf-drivers/)
5 |
6 | The focus of these samples is simplicity. For a lab environment, we strive to provide stripped down samples that provide the minimum amount of functionality possible. They are strictly meant as a learning exercise and do not necessarily represent best practices for production code.
7 |
8 | You will find detailed instructions for the lab exercises in the [lab exercise handout](https://github.com/OSRDrivers/WDF-I/blob/master/Docs_and_Misc/WDF%20Lab%20Exercises.pdf) that is in the \Docs_and_Misc directory of this repo.
9 |
--------------------------------------------------------------------------------
/Solutions/2/2A/Nothing.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #include "nothing.h"
40 |
41 | ///////////////////////////////////////////////////////////////////////////////
42 | //
43 | // DriverEntry
44 | //
45 | // This routine is called by Windows when the driver is first loaded. It
46 | // is the responsibility of this routine to create the WDFDRIVER
47 | //
48 | // INPUTS:
49 | //
50 | // DriverObject - Address of the DRIVER_OBJECT created by Windows for this
51 | // driver.
52 | //
53 | // RegistryPath - UNICODE_STRING which represents this driver's key in the
54 | // Registry.
55 | //
56 | // OUTPUTS:
57 | //
58 | // None.
59 | //
60 | // RETURNS:
61 | //
62 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
63 | // load.
64 | //
65 | // IRQL:
66 | //
67 | // This routine is called at IRQL == PASSIVE_LEVEL.
68 | //
69 | // NOTES:
70 | //
71 | //
72 | ///////////////////////////////////////////////////////////////////////////////
73 | NTSTATUS
74 | DriverEntry(PDRIVER_OBJECT DriverObject,
75 | PUNICODE_STRING RegistryPath)
76 | {
77 | WDF_DRIVER_CONFIG driverConfig;
78 | NTSTATUS status;
79 |
80 | #if DBG
81 | DbgPrint("\nOSR Nothing Driver -- Compiled %s %s\n",
82 | __DATE__,
83 | __TIME__);
84 | #endif
85 |
86 | //
87 | // Provide pointer to our EvtDeviceAdd event processing callback
88 | // function
89 | //
90 | WDF_DRIVER_CONFIG_INIT(&driverConfig,
91 | NothingEvtDeviceAdd);
92 |
93 | //
94 | // Create our WDFDriver instance
95 | //
96 | status = WdfDriverCreate(DriverObject,
97 | RegistryPath,
98 | WDF_NO_OBJECT_ATTRIBUTES,
99 | &driverConfig,
100 | WDF_NO_HANDLE);
101 |
102 | if (!NT_SUCCESS(status)) {
103 | #if DBG
104 | DbgPrint("WdfDriverCreate failed 0x%0x\n",
105 | status);
106 | #endif
107 | }
108 |
109 | return (status);
110 | }
111 |
112 | ///////////////////////////////////////////////////////////////////////////////
113 | //
114 | // NothingEvtDeviceAdd
115 | //
116 | // This routine is called by the framework when a device of
117 | // the type we support is found in the system.
118 | //
119 | // INPUTS:
120 | //
121 | // DriverObject - Our WDFDRIVER object
122 | //
123 | // DeviceInit - The device initialization structure we'll
124 | // be using to create our WDFDEVICE
125 | //
126 | // OUTPUTS:
127 | //
128 | // None.
129 | //
130 | // RETURNS:
131 | //
132 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
133 | // load.
134 | //
135 | // IRQL:
136 | //
137 | // This routine is called at IRQL == PASSIVE_LEVEL.
138 | //
139 | // NOTES:
140 | //
141 | //
142 | ///////////////////////////////////////////////////////////////////////////////
143 | NTSTATUS
144 | NothingEvtDeviceAdd(WDFDRIVER Driver,
145 | PWDFDEVICE_INIT DeviceInit)
146 | {
147 | NTSTATUS status;
148 | WDF_OBJECT_ATTRIBUTES objAttributes;
149 | WDFDEVICE device;
150 | WDF_IO_QUEUE_CONFIG queueConfig;
151 |
152 | DECLARE_CONST_UNICODE_STRING(userDeviceName,
153 | L"\\DosDevices\\Nothing");
154 |
155 | UNREFERENCED_PARAMETER(Driver);
156 |
157 | //
158 | // Life is nice and simple in this driver...
159 | //
160 | // We don't need ANY PnP/Power Event Processing callbacks. There's no
161 | // hardware, thus we don't need EvtPrepareHardware or EvtReleaseHardware
162 | // There's no power state to handle so we don't need EvtD0Entry or EvtD0Exit.
163 | //
164 |
165 | //
166 | // Prepare for WDFDEVICE creation
167 | //
168 |
169 | WDF_OBJECT_ATTRIBUTES_INIT(&objAttributes);
170 |
171 | //
172 | // Specify our device context
173 | //
174 | WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&objAttributes,
175 | NOTHING_DEVICE_CONTEXT);
176 |
177 | //
178 | // Create our device object
179 | //
180 | status = WdfDeviceCreate(&DeviceInit,
181 | &objAttributes,
182 | &device);
183 |
184 | if (!NT_SUCCESS(status)) {
185 | #if DBG
186 | DbgPrint("WdfDeviceCreate failed 0x%0x\n",
187 | status);
188 | #endif
189 | goto Done;
190 | }
191 |
192 | //
193 | // Create a symbolic link to our Device Object. This allows apps
194 | // to open our device by name. Note that we use a constant name,
195 | // so this driver will support only a single instance of our device.
196 | //
197 | status = WdfDeviceCreateSymbolicLink(device,
198 | &userDeviceName);
199 |
200 | if (!NT_SUCCESS(status)) {
201 | #if DBG
202 | DbgPrint("WdfDeviceCreateSymbolicLink failed 0x%0x\n",
203 | status);
204 | #endif
205 | goto Done;
206 | }
207 |
208 | //
209 | // ALSO create a device interface for the device
210 | // This allows usage of the SetupApiXxxx functions to locate
211 | // the device
212 | //
213 | status = WdfDeviceCreateDeviceInterface(device,
214 | &GUID_DEVINTERFACE_NOTHING,
215 | NULL);
216 |
217 | if (!NT_SUCCESS(status)) {
218 | #if DBG
219 | DbgPrint("WdfDeviceCreateDeviceInterface failed 0x%0x\n", status);
220 | #endif
221 | return(status);
222 | }
223 |
224 | //
225 | // Configure our Queue of incoming requests
226 | //
227 | // We use only the default Queue, and we set it for sequential processing.
228 | // This means that the driver will only receive one request at a time
229 | // from the Queue, and will not get another request until it completes
230 | // the previous one.
231 | //
232 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig,
233 | WdfIoQueueDispatchSequential);
234 |
235 | //
236 | // Declare our I/O Event Processing callbacks
237 | //
238 | // We handle, read, write, and device control requests.
239 | //
240 | // WDF will automagically handle Create and Close requests for us and will
241 | // will complete any other request types with STATUS_INVALID_DEVICE_REQUEST.
242 | //
243 | queueConfig.EvtIoRead = NothingEvtRead;
244 | queueConfig.EvtIoWrite = NothingEvtWrite;
245 | queueConfig.EvtIoDeviceControl = NothingEvtDeviceControl;
246 |
247 | //
248 | // Because this is a queue for a software-only device, indicate
249 | // that the queue doesn't need to be power managed.
250 | //
251 | queueConfig.PowerManaged = WdfFalse;
252 |
253 | status = WdfIoQueueCreate(device,
254 | &queueConfig,
255 | WDF_NO_OBJECT_ATTRIBUTES,
256 | WDF_NO_HANDLE);
257 |
258 | if (!NT_SUCCESS(status)) {
259 | #if DBG
260 | DbgPrint("WdfIoQueueCreate for default queue failed 0x%0x\n",
261 | status);
262 | #endif
263 | goto Done;
264 | }
265 |
266 | status = STATUS_SUCCESS;
267 |
268 | Done:
269 |
270 | return (status);
271 | }
272 |
273 | ///////////////////////////////////////////////////////////////////////////////
274 | //
275 | // NothingEvtRead
276 | //
277 | // This routine is called by the framework when there is a
278 | // read request for us to process
279 | //
280 | // INPUTS:
281 | //
282 | // Queue - Our default queue
283 | //
284 | // Request - A read request
285 | //
286 | // Length - The length of the read operation
287 | //
288 | // OUTPUTS:
289 | //
290 | // None.
291 | //
292 | // RETURNS:
293 | //
294 | // None.
295 | //
296 | // IRQL:
297 | //
298 | // This routine is called at IRQL <= DISPATCH_LEVEL
299 | //
300 | // NOTES:
301 | //
302 | //
303 | ///////////////////////////////////////////////////////////////////////////////
304 | VOID
305 | NothingEvtRead(WDFQUEUE Queue,
306 | WDFREQUEST Request,
307 | size_t Length)
308 | {
309 | PNOTHING_DEVICE_CONTEXT devContext;
310 |
311 | UNREFERENCED_PARAMETER(Length);
312 |
313 | #if DBG
314 | DbgPrint("NothingEvtRead\n");
315 | #endif
316 |
317 | //
318 | // Get a pointer to our device extension, just to show how it's done.
319 | // (get the WDFDEVICE from the WDFQUEUE, and the extension from the device)
320 | //
321 | devContext = NothingGetContextFromDevice(
322 | WdfIoQueueGetDevice(Queue));
323 |
324 | //
325 | // Nothing to do...
326 | // We're returning zero bytes, so fill that into the information field
327 | //
328 | WdfRequestCompleteWithInformation(Request,
329 | STATUS_SUCCESS,
330 | 0);
331 | }
332 |
333 | ///////////////////////////////////////////////////////////////////////////////
334 | //
335 | // NothingEvtWrite
336 | //
337 | // This routine is called by the framework when there is a
338 | // write request for us to process
339 | //
340 | // INPUTS:
341 | //
342 | // Queue - Our default queue
343 | //
344 | // Request - A write request
345 | //
346 | // Length - The length of the write operation
347 | //
348 | // OUTPUTS:
349 | //
350 | // None.
351 | //
352 | // RETURNS:
353 | //
354 | // None.
355 | //
356 | // IRQL:
357 | //
358 | // This routine is called at IRQL <= DISPATCH_LEVEL
359 | //
360 | // NOTES:
361 | //
362 | //
363 | ///////////////////////////////////////////////////////////////////////////////
364 | VOID
365 | NothingEvtWrite(WDFQUEUE Queue,
366 | WDFREQUEST Request,
367 | size_t Length)
368 | {
369 | UNREFERENCED_PARAMETER(Queue);
370 |
371 | #if DBG
372 | DbgPrint("NothingEvtWrite\n");
373 | #endif
374 |
375 | //
376 | // Nothing to do...
377 | //
378 | WdfRequestCompleteWithInformation(Request,
379 | STATUS_SUCCESS,
380 | Length);
381 | }
382 |
383 | ///////////////////////////////////////////////////////////////////////////////
384 | //
385 | // NothingEvtDeviceControl
386 | //
387 | // This routine is called by the framework when there is a
388 | // device control request for us to process
389 | //
390 | // INPUTS:
391 | //
392 | // Queue - Our default queue
393 | //
394 | // Request - A device control request
395 | //
396 | // OutputBufferLength - The length of the output buffer
397 | //
398 | // InputBufferLength - The length of the input buffer
399 | //
400 | // IoControlCode - The operation being performed
401 | //
402 | // OUTPUTS:
403 | //
404 | // None.
405 | //
406 | // RETURNS:
407 | //
408 | // None.
409 | //
410 | // IRQL:
411 | //
412 | // This routine is called at IRQL == PASSIVE_LEVEL, due to
413 | // our PASSIVE_LEVEL execution level contraint
414 | //
415 | // NOTES:
416 | //
417 | //
418 | ///////////////////////////////////////////////////////////////////////////////
419 | VOID
420 | NothingEvtDeviceControl(WDFQUEUE Queue,
421 | WDFREQUEST Request,
422 | size_t OutputBufferLength,
423 | size_t InputBufferLength,
424 | ULONG IoControlCode)
425 | {
426 | UNREFERENCED_PARAMETER(IoControlCode);
427 | UNREFERENCED_PARAMETER(InputBufferLength);
428 | UNREFERENCED_PARAMETER(OutputBufferLength);
429 | UNREFERENCED_PARAMETER(Queue);
430 |
431 | #if DBG
432 | DbgPrint("NothingEvtDeviceControl\n");
433 | #endif
434 |
435 | //
436 | // Nothing to do...
437 | // In this case, we return an info field of zero
438 | //
439 | WdfRequestCompleteWithInformation(Request,
440 | STATUS_SUCCESS,
441 | 0);
442 | }
443 |
--------------------------------------------------------------------------------
/Solutions/2/2B/Nothing.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #include "nothing.h"
40 |
41 | ///////////////////////////////////////////////////////////////////////////////
42 | //
43 | // DriverEntry
44 | //
45 | // This routine is called by Windows when the driver is first loaded. It
46 | // is the responsibility of this routine to create the WDFDRIVER
47 | //
48 | // INPUTS:
49 | //
50 | // DriverObject - Address of the DRIVER_OBJECT created by Windows for this
51 | // driver.
52 | //
53 | // RegistryPath - UNICODE_STRING which represents this driver's key in the
54 | // Registry.
55 | //
56 | // OUTPUTS:
57 | //
58 | // None.
59 | //
60 | // RETURNS:
61 | //
62 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
63 | // load.
64 | //
65 | // IRQL:
66 | //
67 | // This routine is called at IRQL == PASSIVE_LEVEL.
68 | //
69 | // NOTES:
70 | //
71 | //
72 | ///////////////////////////////////////////////////////////////////////////////
73 | NTSTATUS
74 | DriverEntry(PDRIVER_OBJECT DriverObject,
75 | PUNICODE_STRING RegistryPath)
76 | {
77 | WDF_DRIVER_CONFIG driverConfig;
78 | NTSTATUS status;
79 |
80 | #if DBG
81 | DbgPrint("\nOSR Nothing Driver -- Compiled %s %s\n",
82 | __DATE__,
83 | __TIME__);
84 | #endif
85 |
86 | //
87 | // Provide pointer to our EvtDeviceAdd event processing callback
88 | // function
89 | //
90 | WDF_DRIVER_CONFIG_INIT(&driverConfig,
91 | NothingEvtDeviceAdd);
92 |
93 | //
94 | // Create our WDFDriver instance
95 | //
96 | status = WdfDriverCreate(DriverObject,
97 | RegistryPath,
98 | WDF_NO_OBJECT_ATTRIBUTES,
99 | &driverConfig,
100 | WDF_NO_HANDLE);
101 |
102 | if (!NT_SUCCESS(status)) {
103 | #if DBG
104 | DbgPrint("WdfDriverCreate failed 0x%0x\n",
105 | status);
106 | #endif
107 | }
108 |
109 | return (status);
110 | }
111 |
112 | ///////////////////////////////////////////////////////////////////////////////
113 | //
114 | // NothingEvtDeviceAdd
115 | //
116 | // This routine is called by the framework when a device of
117 | // the type we support is found in the system.
118 | //
119 | // INPUTS:
120 | //
121 | // DriverObject - Our WDFDRIVER object
122 | //
123 | // DeviceInit - The device initialization structure we'll
124 | // be using to create our WDFDEVICE
125 | //
126 | // OUTPUTS:
127 | //
128 | // None.
129 | //
130 | // RETURNS:
131 | //
132 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
133 | // load.
134 | //
135 | // IRQL:
136 | //
137 | // This routine is called at IRQL == PASSIVE_LEVEL.
138 | //
139 | // NOTES:
140 | //
141 | //
142 | ///////////////////////////////////////////////////////////////////////////////
143 | NTSTATUS
144 | NothingEvtDeviceAdd(WDFDRIVER Driver,
145 | PWDFDEVICE_INIT DeviceInit)
146 | {
147 | NTSTATUS status;
148 | WDF_OBJECT_ATTRIBUTES objAttributes;
149 | WDFDEVICE device;
150 | WDF_IO_QUEUE_CONFIG queueConfig;
151 | WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
152 |
153 | DECLARE_CONST_UNICODE_STRING(userDeviceName,
154 | L"\\DosDevices\\Nothing");
155 |
156 | UNREFERENCED_PARAMETER(Driver);
157 |
158 | //
159 | // Life is nice and simple in this driver...
160 | //
161 | // We don't need ANY PnP/Power Event Processing callbacks. There's no
162 | // hardware, thus we don't need EvtPrepareHardware or EvtReleaseHardware
163 | // There's no power state to handle so we don't need EvtD0Entry or EvtD0Exit.
164 | //
165 | // However, for this exercise we'll be adding D0Entry and D0Exit callbacks
166 | // for fun.
167 | //
168 |
169 |
170 | //
171 | // Prepare for WDFDEVICE creation
172 | //
173 |
174 | WDF_OBJECT_ATTRIBUTES_INIT(&objAttributes);
175 |
176 | //
177 | // Specify our device context
178 | //
179 | WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&objAttributes,
180 | NOTHING_DEVICE_CONTEXT);
181 |
182 |
183 | //
184 | // We're adding D0Entry/D0Exit callbacks, so we need to
185 | // initialize out PnP power event callbacks structure.
186 | //
187 | WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
188 |
189 | //
190 | // Fill in the D0Entry callback.
191 | //
192 | pnpPowerCallbacks.EvtDeviceD0Entry = NothingEvtDeviceD0Entry;
193 |
194 | //
195 | // Fill in the D0Exit callback
196 | //
197 | pnpPowerCallbacks.EvtDeviceD0Exit = NothingEvtDeviceD0Exit;
198 |
199 | //
200 | // Update the DeviceInit structure to contain the new callbacks.
201 | //
202 | WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit,
203 | &pnpPowerCallbacks);
204 |
205 | //
206 | // Create our device object
207 | //
208 | status = WdfDeviceCreate(&DeviceInit,
209 | &objAttributes,
210 | &device);
211 |
212 | if (!NT_SUCCESS(status)) {
213 | #if DBG
214 | DbgPrint("WdfDeviceCreate failed 0x%0x\n",
215 | status);
216 | #endif
217 | goto Done;
218 | }
219 |
220 | //
221 | // Create a symbolic link to our Device Object. This allows apps
222 | // to open our device by name. Note that we use a constant name,
223 | // so this driver will support only a single instance of our device.
224 | //
225 | status = WdfDeviceCreateSymbolicLink(device,
226 | &userDeviceName);
227 |
228 | if (!NT_SUCCESS(status)) {
229 | #if DBG
230 | DbgPrint("WdfDeviceCreateSymbolicLink failed 0x%0x\n",
231 | status);
232 | #endif
233 | goto Done;
234 | }
235 |
236 | //
237 | // ALSO create a device interface for the device
238 | // This allows usage of the SetupApiXxxx functions to locate
239 | // the device
240 | //
241 | status = WdfDeviceCreateDeviceInterface(device,
242 | &GUID_DEVINTERFACE_NOTHING,
243 | NULL);
244 |
245 | if (!NT_SUCCESS(status)) {
246 | #if DBG
247 | DbgPrint("WdfDeviceCreateDeviceInterface failed 0x%0x\n", status);
248 | #endif
249 | return(status);
250 | }
251 |
252 | //
253 | // Configure our Queue of incoming requests
254 | //
255 | // We use only the default Queue, and we set it for sequential processing.
256 | // This means that the driver will only receive one request at a time
257 | // from the Queue, and will not get another request until it completes
258 | // the previous one.
259 | //
260 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig,
261 | WdfIoQueueDispatchSequential);
262 |
263 | //
264 | // Declare our I/O Event Processing callbacks
265 | //
266 | // We handle, read, write, and device control requests.
267 | //
268 | // WDF will automagically handle Create and Close requests for us and will
269 | // will complete any other request types with STATUS_INVALID_DEVICE_REQUEST.
270 | //
271 | queueConfig.EvtIoRead = NothingEvtRead;
272 | queueConfig.EvtIoWrite = NothingEvtWrite;
273 | queueConfig.EvtIoDeviceControl = NothingEvtDeviceControl;
274 |
275 | //
276 | // Because this is a queue for a software-only device, indicate
277 | // that the queue doesn't need to be power managed.
278 | //
279 | queueConfig.PowerManaged = WdfFalse;
280 |
281 | status = WdfIoQueueCreate(device,
282 | &queueConfig,
283 | WDF_NO_OBJECT_ATTRIBUTES,
284 | WDF_NO_HANDLE);
285 |
286 | if (!NT_SUCCESS(status)) {
287 | #if DBG
288 | DbgPrint("WdfIoQueueCreate for default queue failed 0x%0x\n",
289 | status);
290 | #endif
291 | goto Done;
292 | }
293 |
294 | status = STATUS_SUCCESS;
295 |
296 | Done:
297 |
298 | return (status);
299 | }
300 |
301 | ///////////////////////////////////////////////////////////////////////////////
302 | //
303 | // NothingEvtDeviceD0Entry
304 | //
305 | // This routine is called by the framework when a device of
306 | // the type we support is entering the D0 state
307 | //
308 | // INPUTS:
309 | //
310 | // Device - One of our WDFDEVICE objects
311 | //
312 | // PreviousState - The D-State we're entering D0 from
313 | //
314 | // OUTPUTS:
315 | //
316 | // None.
317 | //
318 | // RETURNS:
319 | //
320 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
321 | // load.
322 | //
323 | // IRQL:
324 | //
325 | // This routine is called at IRQL == PASSIVE_LEVEL.
326 | //
327 | // NOTES:
328 | //
329 | //
330 | ///////////////////////////////////////////////////////////////////////////////
331 | NTSTATUS
332 | NothingEvtDeviceD0Entry(
333 | IN WDFDEVICE Device,
334 | IN WDF_POWER_DEVICE_STATE PreviousState
335 | ) {
336 |
337 | UNREFERENCED_PARAMETER(Device);
338 |
339 | #if DBG
340 | DbgPrint("NothingEvtDeviceD0Entry - Entering D0 from state %s (%d)\n",
341 | NothingPowerDeviceStateToString(PreviousState),
342 | PreviousState);
343 | #endif
344 |
345 | return STATUS_SUCCESS;
346 | }
347 |
348 |
349 | ///////////////////////////////////////////////////////////////////////////////
350 | //
351 | // NothingEvtDeviceD0Exit
352 | //
353 | // This routine is called by the framework when a device of
354 | // the type we support is leaving the D0 state
355 | //
356 | // INPUTS:
357 | //
358 | // Device - One of our WDFDEVICE objects
359 | //
360 | // TargetState - The D-State we're entering
361 | //
362 | // OUTPUTS:
363 | //
364 | // None.
365 | //
366 | // RETURNS:
367 | //
368 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
369 | // load.
370 | //
371 | // IRQL:
372 | //
373 | // This routine is called at IRQL == PASSIVE_LEVEL.
374 | //
375 | // NOTES:
376 | //
377 | //
378 | ///////////////////////////////////////////////////////////////////////////////
379 | NTSTATUS
380 | NothingEvtDeviceD0Exit(
381 | IN WDFDEVICE Device,
382 | IN WDF_POWER_DEVICE_STATE TargetState
383 | ) {
384 |
385 |
386 | UNREFERENCED_PARAMETER(Device);
387 |
388 | #if DBG
389 | DbgPrint("NothingEvtDeviceD0Exit - Entering state %s (%d)\n",
390 | NothingPowerDeviceStateToString(TargetState),
391 | TargetState);
392 | #endif
393 |
394 | return STATUS_SUCCESS;
395 | }
396 |
397 |
398 | ///////////////////////////////////////////////////////////////////////////////
399 | //
400 | // NothingEvtRead
401 | //
402 | // This routine is called by the framework when there is a
403 | // read request for us to process
404 | //
405 | // INPUTS:
406 | //
407 | // Queue - Our default queue
408 | //
409 | // Request - A read request
410 | //
411 | // Length - The length of the read operation
412 | //
413 | // OUTPUTS:
414 | //
415 | // None.
416 | //
417 | // RETURNS:
418 | //
419 | // None.
420 | //
421 | // IRQL:
422 | //
423 | // This routine is called at IRQL <= DISPATCH_LEVEL
424 | //
425 | // NOTES:
426 | //
427 | //
428 | ///////////////////////////////////////////////////////////////////////////////
429 | VOID
430 | NothingEvtRead(WDFQUEUE Queue,
431 | WDFREQUEST Request,
432 | size_t Length)
433 | {
434 | PNOTHING_DEVICE_CONTEXT devContext;
435 |
436 | UNREFERENCED_PARAMETER(Length);
437 |
438 | #if DBG
439 | DbgPrint("NothingEvtRead\n");
440 | #endif
441 |
442 | //
443 | // Get a pointer to our device extension, just to show how it's done.
444 | // (get the WDFDEVICE from the WDFQUEUE, and the extension from the device)
445 | //
446 | devContext = NothingGetContextFromDevice(
447 | WdfIoQueueGetDevice(Queue));
448 |
449 | //
450 | // Nothing to do...
451 | // We're returning zero bytes, so fill that into the information field
452 | //
453 | WdfRequestCompleteWithInformation(Request,
454 | STATUS_SUCCESS,
455 | 0);
456 | }
457 |
458 | ///////////////////////////////////////////////////////////////////////////////
459 | //
460 | // NothingEvtWrite
461 | //
462 | // This routine is called by the framework when there is a
463 | // write request for us to process
464 | //
465 | // INPUTS:
466 | //
467 | // Queue - Our default queue
468 | //
469 | // Request - A write request
470 | //
471 | // Length - The length of the write operation
472 | //
473 | // OUTPUTS:
474 | //
475 | // None.
476 | //
477 | // RETURNS:
478 | //
479 | // None.
480 | //
481 | // IRQL:
482 | //
483 | // This routine is called at IRQL <= DISPATCH_LEVEL
484 | //
485 | // NOTES:
486 | //
487 | //
488 | ///////////////////////////////////////////////////////////////////////////////
489 | VOID
490 | NothingEvtWrite(WDFQUEUE Queue,
491 | WDFREQUEST Request,
492 | size_t Length)
493 | {
494 | UNREFERENCED_PARAMETER(Queue);
495 |
496 | #if DBG
497 | DbgPrint("NothingEvtWrite\n");
498 | #endif
499 |
500 | //
501 | // Nothing to do...
502 | //
503 | WdfRequestCompleteWithInformation(Request,
504 | STATUS_SUCCESS,
505 | Length);
506 | }
507 |
508 | ///////////////////////////////////////////////////////////////////////////////
509 | //
510 | // NothingEvtDeviceControl
511 | //
512 | // This routine is called by the framework when there is a
513 | // device control request for us to process
514 | //
515 | // INPUTS:
516 | //
517 | // Queue - Our default queue
518 | //
519 | // Request - A device control request
520 | //
521 | // OutputBufferLength - The length of the output buffer
522 | //
523 | // InputBufferLength - The length of the input buffer
524 | //
525 | // IoControlCode - The operation being performed
526 | //
527 | // OUTPUTS:
528 | //
529 | // None.
530 | //
531 | // RETURNS:
532 | //
533 | // None.
534 | //
535 | // IRQL:
536 | //
537 | // This routine is called at IRQL == PASSIVE_LEVEL, due to
538 | // our PASSIVE_LEVEL execution level contraint
539 | //
540 | // NOTES:
541 | //
542 | //
543 | ///////////////////////////////////////////////////////////////////////////////
544 | VOID
545 | NothingEvtDeviceControl(WDFQUEUE Queue,
546 | WDFREQUEST Request,
547 | size_t OutputBufferLength,
548 | size_t InputBufferLength,
549 | ULONG IoControlCode)
550 | {
551 | UNREFERENCED_PARAMETER(IoControlCode);
552 | UNREFERENCED_PARAMETER(InputBufferLength);
553 | UNREFERENCED_PARAMETER(OutputBufferLength);
554 | UNREFERENCED_PARAMETER(Queue);
555 |
556 | #if DBG
557 | DbgPrint("NothingEvtDeviceControl\n");
558 | #endif
559 |
560 | //
561 | // Nothing to do...
562 | // In this case, we return an info field of zero
563 | //
564 | WdfRequestCompleteWithInformation(Request,
565 | STATUS_SUCCESS,
566 | 0);
567 | }
568 |
569 | CHAR const *
570 | NothingPowerDeviceStateToString(
571 | WDF_POWER_DEVICE_STATE DeviceState
572 | ) {
573 |
574 | switch (DeviceState) {
575 | case WdfPowerDeviceInvalid:
576 | return "WdfPowerDeviceInvalid";
577 | case WdfPowerDeviceD0:
578 | return "WdfPowerDeviceD0";
579 | case WdfPowerDeviceD1:
580 | return "WdfPowerDeviceD1";
581 | case WdfPowerDeviceD2:
582 | return "WdfPowerDeviceD2";
583 | case WdfPowerDeviceD3:
584 | return "WdfPowerDeviceD3";
585 | case WdfPowerDeviceD3Final:
586 | return "WdfPowerDeviceD3Final";
587 | case WdfPowerDevicePrepareForHibernation:
588 | return "WdfPowerDevicePrepareForHibernation";
589 | case WdfPowerDeviceMaximum:
590 | return "WdfPowerDeviceMaximum";
591 | default:
592 | break;
593 | }
594 | return "Unknown";
595 |
596 | }
597 |
--------------------------------------------------------------------------------
/Solutions/2/2B/nothing.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | #include
41 | #include
42 |
43 | #include "NOTHING_IOCTL.h"
44 |
45 | //
46 | // Nothing device context structure
47 | //
48 | // KMDF will associate this structure with each "Nothing" device that
49 | // this driver creates.
50 | //
51 | typedef struct _NOTHING_DEVICE_CONTEXT {
52 |
53 | ULONG Nothing;
54 |
55 | } NOTHING_DEVICE_CONTEXT, *PNOTHING_DEVICE_CONTEXT;
56 |
57 | //
58 | // Accessor structure
59 | //
60 | // Given a WDFDEVICE handle, we'll use the following function to return
61 | // a pointer to our device's context area.
62 | //
63 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(NOTHING_DEVICE_CONTEXT,
64 | NothingGetContextFromDevice)
65 |
66 | //
67 | // Forward declarations
68 | //
69 | extern "C" {
70 | DRIVER_INITIALIZE DriverEntry;
71 | }
72 | EVT_WDF_DRIVER_DEVICE_ADD NothingEvtDeviceAdd;
73 | EVT_WDF_IO_QUEUE_IO_READ NothingEvtRead;
74 | EVT_WDF_IO_QUEUE_IO_WRITE NothingEvtWrite;
75 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL NothingEvtDeviceControl;
76 |
77 | EVT_WDF_DEVICE_D0_ENTRY NothingEvtDeviceD0Entry;
78 | EVT_WDF_DEVICE_D0_EXIT NothingEvtDeviceD0Exit;
79 |
80 | //
81 | CHAR const *
82 | NothingPowerDeviceStateToString(WDF_POWER_DEVICE_STATE DeviceState);
83 |
--------------------------------------------------------------------------------
/Solutions/3/3A/nothing.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | #include
41 | #include
42 |
43 | #include "NOTHING_IOCTL.h"
44 |
45 | //
46 | // Choose an arbitrary maximum buffer length
47 | //
48 | #define NOTHING_BUFFER_MAX_LENGTH 4096
49 |
50 | //
51 | // Nothing device context structure
52 | //
53 | // KMDF will associate this structure with each "Nothing" device that
54 | // this driver creates.
55 | //
56 | typedef struct _NOTHING_DEVICE_CONTEXT {
57 |
58 | ULONG Nothing;
59 |
60 | ULONG BytesStored;
61 | UCHAR Storage[NOTHING_BUFFER_MAX_LENGTH];
62 |
63 | } NOTHING_DEVICE_CONTEXT, *PNOTHING_DEVICE_CONTEXT;
64 |
65 | //
66 | // Accessor structure
67 | //
68 | // Given a WDFDEVICE handle, we'll use the following function to return
69 | // a pointer to our device's context area.
70 | //
71 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(NOTHING_DEVICE_CONTEXT,
72 | NothingGetContextFromDevice)
73 |
74 | //
75 | // Forward declarations
76 | //
77 | extern "C" {
78 | DRIVER_INITIALIZE DriverEntry;
79 | }
80 | EVT_WDF_DRIVER_DEVICE_ADD NothingEvtDeviceAdd;
81 | EVT_WDF_IO_QUEUE_IO_READ NothingEvtRead;
82 | EVT_WDF_IO_QUEUE_IO_WRITE NothingEvtWrite;
83 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL NothingEvtDeviceControl;
84 |
85 | EVT_WDF_DEVICE_D0_ENTRY NothingEvtDeviceD0Entry;
86 | EVT_WDF_DEVICE_D0_EXIT NothingEvtDeviceD0Exit;
87 |
88 | //
89 | CHAR const *
90 | NothingPowerDeviceStateToString(WDF_POWER_DEVICE_STATE DeviceState);
91 |
--------------------------------------------------------------------------------
/Solutions/3/3B/nothing.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2020 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | #include
41 | #include
42 |
43 | #include "NOTHING_IOCTL.h"
44 |
45 | //
46 | // Choose an arbitrary maximum buffer length
47 | //
48 | #define NOTHING_BUFFER_MAX_LENGTH 4096
49 |
50 | //
51 | // Nothing device context structure
52 | //
53 | // KMDF will associate this structure with each "Nothing" device that
54 | // this driver creates.
55 | //
56 | typedef struct _NOTHING_DEVICE_CONTEXT {
57 |
58 | ULONG Nothing;
59 |
60 | //
61 | // Manual queues for holding incoming requests if no data
62 | // pending.
63 | //
64 | WDFQUEUE ReadQueue;
65 | WDFQUEUE WriteQueue;
66 |
67 | } NOTHING_DEVICE_CONTEXT, *PNOTHING_DEVICE_CONTEXT;
68 |
69 | //
70 | // Accessor structure
71 | //
72 | // Given a WDFDEVICE handle, we'll use the following function to return
73 | // a pointer to our device's context area.
74 | //
75 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(NOTHING_DEVICE_CONTEXT,
76 | NothingGetContextFromDevice)
77 |
78 | //
79 | // Forward declarations
80 | //
81 | extern "C" {
82 | DRIVER_INITIALIZE DriverEntry;
83 | }
84 | EVT_WDF_DRIVER_DEVICE_ADD NothingEvtDeviceAdd;
85 | EVT_WDF_IO_QUEUE_IO_READ NothingEvtRead;
86 | EVT_WDF_IO_QUEUE_IO_WRITE NothingEvtWrite;
87 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL NothingEvtDeviceControl;
88 |
89 | EVT_WDF_DEVICE_D0_ENTRY NothingEvtDeviceD0Entry;
90 | EVT_WDF_DEVICE_D0_EXIT NothingEvtDeviceD0Exit;
91 |
92 | //
93 | CHAR const *
94 | NothingPowerDeviceStateToString(WDF_POWER_DEVICE_STATE DeviceState);
95 |
--------------------------------------------------------------------------------
/Solutions/4/4B/CDFilter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #include "CDFilter.h"
40 |
41 | ///////////////////////////////////////////////////////////////////////////////
42 | //
43 | // DriverEntry
44 | //
45 | // This routine is called by Windows when the driver is first loaded. It
46 | // is the responsibility of this routine to create the WDFDRIVER
47 | //
48 | // INPUTS:
49 | //
50 | // DriverObject - Address of the DRIVER_OBJECT created by Windows for this
51 | // driver.
52 | //
53 | // RegistryPath - UNICODE_STRING which represents this driver's key in the
54 | // Registry.
55 | //
56 | // OUTPUTS:
57 | //
58 | // None.
59 | //
60 | // RETURNS:
61 | //
62 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
63 | // load.
64 | //
65 | // IRQL:
66 | //
67 | // This routine is called at IRQL == PASSIVE_LEVEL.
68 | //
69 | // NOTES:
70 | //
71 | //
72 | ///////////////////////////////////////////////////////////////////////////////
73 | NTSTATUS
74 | DriverEntry(PDRIVER_OBJECT DriverObject,
75 | PUNICODE_STRING RegistryPath)
76 | {
77 | WDF_DRIVER_CONFIG driverConfig;
78 | NTSTATUS status;
79 |
80 | #if DBG
81 | DbgPrint("CDFilter: OSR CDFILTER Filter Driver...Compiled %s %s\n",
82 | __DATE__,
83 | __TIME__);
84 | #endif
85 |
86 | //
87 | // Initialize our driver config structure, specifying our
88 | // EvtDeviceAdd Event Processing Callback.
89 | //
90 | WDF_DRIVER_CONFIG_INIT(&driverConfig,
91 | CDFilterEvtDeviceAdd);
92 |
93 | //
94 | // Create the framework driver object...
95 | //
96 | status = WdfDriverCreate(DriverObject,
97 | RegistryPath,
98 | WDF_NO_OBJECT_ATTRIBUTES,
99 | &driverConfig,
100 | WDF_NO_HANDLE);
101 |
102 | if (!NT_SUCCESS(status)) {
103 | #if DBG
104 | DbgPrint("WdfDriverCreate failed - 0x%x\n",
105 | status);
106 | #endif
107 | }
108 |
109 | return status;
110 | }
111 |
112 | ///////////////////////////////////////////////////////////////////////////////
113 | //
114 | // CDFilterEvtDeviceAdd
115 | //
116 | // This routine is called by the framework when a device of
117 | // the type we filter is found in the system.
118 | //
119 | // INPUTS:
120 | //
121 | // DriverObject - Our WDFDRIVER object
122 | //
123 | // DeviceInit - The device initialization structure we'll
124 | // be using to create our WDFDEVICE
125 | //
126 | // OUTPUTS:
127 | //
128 | // None.
129 | //
130 | // RETURNS:
131 | //
132 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
133 | // load.
134 | //
135 | // IRQL:
136 | //
137 | // This routine is called at IRQL == PASSIVE_LEVEL.
138 | //
139 | // NOTES:
140 | //
141 | //
142 | ///////////////////////////////////////////////////////////////////////////////
143 | NTSTATUS
144 | CDFilterEvtDeviceAdd(WDFDRIVER Driver,
145 | PWDFDEVICE_INIT DeviceInit)
146 | {
147 | NTSTATUS status;
148 | WDF_OBJECT_ATTRIBUTES objAtttributes;
149 | WDFDEVICE wdfDevice;
150 | PFILTER_DEVICE_CONTEXT filterContext;
151 | WDF_IO_QUEUE_CONFIG queueConfig;
152 |
153 |
154 | UNREFERENCED_PARAMETER(Driver);
155 |
156 | #if DBG
157 | DbgPrint("CDFilter: Adding device...\n");
158 | #endif
159 |
160 | //
161 | // Indicate that we're creating a FILTER device. This will cause
162 | // KMDF to attach us correctly to the device stack and auto-forward
163 | // any requests we don't explicitly handle.
164 | //
165 | WdfFdoInitSetFilter(DeviceInit);
166 |
167 | //
168 | // Setup our device attributes to have our context type
169 | //
170 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objAtttributes,
171 | FILTER_DEVICE_CONTEXT);
172 |
173 | //
174 | // And create our WDF device
175 | //
176 | status = WdfDeviceCreate(&DeviceInit,
177 | &objAtttributes,
178 | &wdfDevice);
179 |
180 | if (!NT_SUCCESS(status)) {
181 | #if DBG
182 | DbgPrint("WdfDeviceCreate failed - 0x%x\n",
183 | status);
184 | #endif
185 | goto Done;
186 | }
187 |
188 | filterContext = CDFilterGetDeviceContext(wdfDevice);
189 |
190 | filterContext->WdfDevice = wdfDevice;
191 |
192 |
193 | //
194 | // Create a Queue that will allow us to pick off any I/O requests
195 | // that we may be interested in before they are forwarded
196 | // to the target device.
197 | //
198 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig,
199 | WdfIoQueueDispatchParallel);
200 |
201 | //
202 | // For this exercise we want to see all the READ Requests.
203 | // Note that all OTHER Requests (such as write and device control Requests)
204 | // will be automatically forwarded to our Local I/O Target by the Framework.
205 | //
206 | queueConfig.EvtIoRead = CDFilterEvtRead;
207 |
208 | //
209 | // Create the queue...
210 | //
211 | status = WdfIoQueueCreate(wdfDevice,
212 | &queueConfig,
213 | WDF_NO_OBJECT_ATTRIBUTES,
214 | nullptr);
215 |
216 | if (!NT_SUCCESS(status)) {
217 |
218 | #if DBG
219 | DbgPrint("WdfIoQueueCreate failed - 0x%x\n",
220 | status);
221 | #endif
222 | goto Done;
223 | }
224 |
225 |
226 | status = STATUS_SUCCESS;
227 |
228 | Done:
229 |
230 | return status;
231 | }
232 |
233 | ///////////////////////////////////////////////////////////////////////////////
234 | //
235 | // CDFilterEvtRead
236 | //
237 | // This routine is called by the framework for read requests
238 | // being sent to the device we're filtering
239 | //
240 | // INPUTS:
241 | //
242 | // Queue - Our default queue
243 | //
244 | // Request - A read request
245 | //
246 | // Length - The length of the read operation
247 | //
248 | // OUTPUTS:
249 | //
250 | // None.
251 | //
252 | // RETURNS:
253 | //
254 | // None.
255 | //
256 | // IRQL:
257 | //
258 | // This routine is called at IRQL <= DISPATCH_LEVEL
259 | //
260 | // NOTES:
261 | //
262 | //
263 | ///////////////////////////////////////////////////////////////////////////////
264 | VOID
265 | CDFilterEvtRead(WDFQUEUE Queue,
266 | WDFREQUEST Request,
267 | size_t Length)
268 | {
269 | WDF_REQUEST_SEND_OPTIONS options;
270 | NTSTATUS status;
271 | PFILTER_DEVICE_CONTEXT devContext;
272 |
273 | #if DBG
274 | DbgPrint("CDFilterEvtRead: Processing read. Length = 0x%x\n",
275 | Length);
276 | #endif
277 |
278 | //
279 | // Get the context that we setup during DeviceAdd processing
280 | //
281 | devContext = CDFilterGetDeviceContext(WdfIoQueueGetDevice(Queue));
282 |
283 | //
284 | // We're just going to be passing this Request on with
285 | // zero regard for what happens to it and we don't want to handle
286 | // it at all after the I/O Target completes it. Therefore, we'll
287 | // use the WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET option
288 | //
289 | WDF_REQUEST_SEND_OPTIONS_INIT(&options,
290 | WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);
291 |
292 | //
293 | // And send it!
294 | //
295 | if (!WdfRequestSend(Request,
296 | WdfDeviceGetIoTarget(devContext->WdfDevice),
297 | &options)) {
298 |
299 | //
300 | // Oops! Something bad happened and the Request was NOT sent
301 | // to the local I/O Target. That means we're responsible for
302 | // completing the Request
303 | //
304 | status = WdfRequestGetStatus(Request);
305 | #if DBG
306 | DbgPrint("WdfRequestSend failed - 0x%x\n",
307 | status);
308 | #endif
309 | WdfRequestComplete(Request,
310 | status);
311 | }
312 | }
313 |
--------------------------------------------------------------------------------
/Solutions/4/4B/CDFilter.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | //
45 | // Our per device context
46 | //
47 | typedef struct _FILTER_DEVICE_CONTEXT {
48 |
49 | WDFDEVICE WdfDevice;
50 |
51 | } FILTER_DEVICE_CONTEXT, *PFILTER_DEVICE_CONTEXT;
52 |
53 |
54 | //
55 | // Context accessor function
56 | //
57 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FILTER_DEVICE_CONTEXT,
58 | CDFilterGetDeviceContext)
59 |
60 | extern "C" {
61 | DRIVER_INITIALIZE DriverEntry;
62 | }
63 |
64 | EVT_WDF_DRIVER_DEVICE_ADD CDFilterEvtDeviceAdd;
65 |
66 | EVT_WDF_IO_QUEUE_IO_READ CDFilterEvtRead;
67 |
--------------------------------------------------------------------------------
/Solutions/4/4C/CDFilter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #include "CDFilter.h"
40 |
41 | ///////////////////////////////////////////////////////////////////////////////
42 | //
43 | // DriverEntry
44 | //
45 | // This routine is called by Windows when the driver is first loaded. It
46 | // is the responsibility of this routine to create the WDFDRIVER
47 | //
48 | // INPUTS:
49 | //
50 | // DriverObject - Address of the DRIVER_OBJECT created by Windows for this
51 | // driver.
52 | //
53 | // RegistryPath - UNICODE_STRING which represents this driver's key in the
54 | // Registry.
55 | //
56 | // OUTPUTS:
57 | //
58 | // None.
59 | //
60 | // RETURNS:
61 | //
62 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
63 | // load.
64 | //
65 | // IRQL:
66 | //
67 | // This routine is called at IRQL == PASSIVE_LEVEL.
68 | //
69 | // NOTES:
70 | //
71 | //
72 | ///////////////////////////////////////////////////////////////////////////////
73 | NTSTATUS
74 | DriverEntry(PDRIVER_OBJECT DriverObject,
75 | PUNICODE_STRING RegistryPath)
76 | {
77 | WDF_DRIVER_CONFIG driverConfig;
78 | NTSTATUS status;
79 |
80 | #if DBG
81 | DbgPrint("CDFilter: OSR CDFILTER Filter Driver...Compiled %s %s\n",
82 | __DATE__,
83 | __TIME__);
84 | #endif
85 |
86 | //
87 | // Initialize our driver config structure, specifying our
88 | // EvtDeviceAdd Event Processing Callback.
89 | //
90 | WDF_DRIVER_CONFIG_INIT(&driverConfig,
91 | CDFilterEvtDeviceAdd);
92 |
93 | //
94 | // Create the framework driver object...
95 | //
96 | status = WdfDriverCreate(DriverObject,
97 | RegistryPath,
98 | WDF_NO_OBJECT_ATTRIBUTES,
99 | &driverConfig,
100 | WDF_NO_HANDLE);
101 |
102 | if (!NT_SUCCESS(status)) {
103 | #if DBG
104 | DbgPrint("WdfDriverCreate failed - 0x%x\n",
105 | status);
106 | #endif
107 | }
108 |
109 | return status;
110 | }
111 |
112 | ///////////////////////////////////////////////////////////////////////////////
113 | //
114 | // CDFilterEvtDeviceAdd
115 | //
116 | // This routine is called by the framework when a device of
117 | // the type we filter is found in the system.
118 | //
119 | // INPUTS:
120 | //
121 | // DriverObject - Our WDFDRIVER object
122 | //
123 | // DeviceInit - The device initialization structure we'll
124 | // be using to create our WDFDEVICE
125 | //
126 | // OUTPUTS:
127 | //
128 | // None.
129 | //
130 | // RETURNS:
131 | //
132 | // STATUS_SUCCESS, otherwise an error indicating why the driver could not
133 | // load.
134 | //
135 | // IRQL:
136 | //
137 | // This routine is called at IRQL == PASSIVE_LEVEL.
138 | //
139 | // NOTES:
140 | //
141 | //
142 | ///////////////////////////////////////////////////////////////////////////////
143 | NTSTATUS
144 | CDFilterEvtDeviceAdd(WDFDRIVER Driver,
145 | PWDFDEVICE_INIT DeviceInit)
146 | {
147 | NTSTATUS status;
148 | WDF_OBJECT_ATTRIBUTES objAtttributes;
149 | WDFDEVICE wdfDevice;
150 | PFILTER_DEVICE_CONTEXT filterContext;
151 | WDF_IO_QUEUE_CONFIG queueConfig;
152 |
153 |
154 | UNREFERENCED_PARAMETER(Driver);
155 |
156 | #if DBG
157 | DbgPrint("CDFilter: Adding device...\n");
158 | #endif
159 |
160 | //
161 | // Indicate that we're creating a FILTER device. This will cause
162 | // KMDF to attach us correctly to the device stack and auto-forward
163 | // any requests we don't explicitly handle.
164 | //
165 | WdfFdoInitSetFilter(DeviceInit);
166 |
167 | //
168 | // Setup our device attributes to have our context type
169 | //
170 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objAtttributes,
171 | FILTER_DEVICE_CONTEXT);
172 |
173 | //
174 | // And create our WDF device
175 | //
176 | status = WdfDeviceCreate(&DeviceInit,
177 | &objAtttributes,
178 | &wdfDevice);
179 |
180 | if (!NT_SUCCESS(status)) {
181 | #if DBG
182 | DbgPrint("WdfDeviceCreate failed - 0x%x\n",
183 | status);
184 | #endif
185 | goto Done;
186 | }
187 |
188 | filterContext = CDFilterGetDeviceContext(wdfDevice);
189 |
190 | filterContext->WdfDevice = wdfDevice;
191 |
192 |
193 | //
194 | // Create a Queue that will allow us to pick off any I/O requests
195 | // that we may be interested in before they are forwarded
196 | // to the target device.
197 | //
198 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig,
199 | WdfIoQueueDispatchParallel);
200 |
201 | //
202 | // For this exercise we want to see all the READ Requests.
203 | // Note that all OTHER Requests (such as write and device control Requests)
204 | // will be automatically forwarded to our Local I/O Target by the Framework.
205 | //
206 | queueConfig.EvtIoRead = CDFilterEvtRead;
207 |
208 | //
209 | // Create the queue...
210 | //
211 | status = WdfIoQueueCreate(wdfDevice,
212 | &queueConfig,
213 | WDF_NO_OBJECT_ATTRIBUTES,
214 | nullptr);
215 |
216 | if (!NT_SUCCESS(status)) {
217 |
218 | #if DBG
219 | DbgPrint("WdfIoQueueCreate failed - 0x%x\n",
220 | status);
221 | #endif
222 | goto Done;
223 | }
224 |
225 |
226 | status = STATUS_SUCCESS;
227 |
228 | Done:
229 |
230 | return status;
231 | }
232 |
233 | ///////////////////////////////////////////////////////////////////////////////
234 | //
235 | // CDFilterEvtRead
236 | //
237 | // This routine is called by the framework for read requests
238 | // being sent to the device we're filtering
239 | //
240 | // INPUTS:
241 | //
242 | // Queue - Our default queue
243 | //
244 | // Request - A read request
245 | //
246 | // Length - The length of the read operation
247 | //
248 | // OUTPUTS:
249 | //
250 | // None.
251 | //
252 | // RETURNS:
253 | //
254 | // None.
255 | //
256 | // IRQL:
257 | //
258 | // This routine is called at IRQL <= DISPATCH_LEVEL
259 | //
260 | // NOTES:
261 | //
262 | //
263 | ///////////////////////////////////////////////////////////////////////////////
264 | VOID
265 | CDFilterEvtRead(WDFQUEUE Queue,
266 | WDFREQUEST Request,
267 | size_t Length)
268 | {
269 | WDF_REQUEST_SEND_OPTIONS options;
270 | NTSTATUS status;
271 | PFILTER_DEVICE_CONTEXT devContext;
272 |
273 | #if DBG
274 | DbgPrint("CDFilterEvtRead: Processing read. Length = 0x%x\n",
275 | Length);
276 | #endif
277 |
278 | //
279 | // Get the context that we setup during DeviceAdd processing
280 | //
281 | devContext = CDFilterGetDeviceContext(WdfIoQueueGetDevice(Queue));
282 |
283 | //
284 | // Establish the Request parameters (buffer description, etc) that'll
285 | // be seen by the receiving driver.
286 | //
287 | WdfRequestFormatRequestUsingCurrentType(Request);
288 |
289 | //
290 | // Set a completion routine to be called when the Request is done...
291 | //
292 | WdfRequestSetCompletionRoutine(Request,
293 | CDFilterReadComplete,
294 | nullptr);
295 | //
296 | // And send it!
297 | //
298 | if (!WdfRequestSend(Request,
299 | WdfDeviceGetIoTarget(devContext->WdfDevice),
300 | WDF_NO_SEND_OPTIONS)) {
301 |
302 | //
303 | // Oops! Something bad happened and the Request was NOT sent
304 | // to the local I/O Target. That means we're responsible for
305 | // completing the Request
306 | //
307 | status = WdfRequestGetStatus(Request);
308 | #if DBG
309 | DbgPrint("WdfRequestSend failed - 0x%x\n",
310 | status);
311 | #endif
312 | WdfRequestComplete(Request,
313 | status);
314 | }
315 | }
316 |
317 | ///////////////////////////////////////////////////////////////////////////////
318 | //
319 | // WdfFltrReadComplete
320 | //
321 | // This routine is our completion routine for read requests sent to the
322 | // filtered device
323 | //
324 | // INPUTS:
325 | //
326 | // Queue - Our filter device's default WDF queue
327 | //
328 | // Target - The I/O target of our default queue (i.e. an I/O target that
329 | // targets the filtered device
330 | //
331 | // Params - The completion information for the request
332 | //
333 | // Context - Whatever context we supplied to WdfRequestSetCompletionRoutine
334 | //
335 | // OUTPUTS:
336 | //
337 | // None.
338 | //
339 | // RETURNS:
340 | //
341 | // None
342 | //
343 | // IRQL:
344 | //
345 | // Depends entirely on the device that you're filtering. Typically
346 | // <= DISPATCH_LEVEL
347 | //
348 | // NOTES:
349 | //
350 | ///////////////////////////////////////////////////////////////////////////////
351 | VOID
352 | CDFilterReadComplete(
353 | IN WDFREQUEST Request,
354 | IN WDFIOTARGET Target,
355 | IN PWDF_REQUEST_COMPLETION_PARAMS Params,
356 | IN WDFCONTEXT Context
357 | )
358 | {
359 | UNREFERENCED_PARAMETER(Context);
360 | UNREFERENCED_PARAMETER(Target);
361 |
362 | //
363 | // Print the status and number of bytes read to the debugger
364 | //
365 | #if DBG
366 | DbgPrint("CDFilterReadComplete: Status-0x%x; Information-0x%x\n",
367 | Params->IoStatus.Status,
368 | Params->IoStatus.Information);
369 | #endif
370 |
371 | //
372 | // Now that we've seen it, complete the Request.
373 | //
374 | WdfRequestCompleteWithInformation(Request,
375 | Params->IoStatus.Status,
376 | Params->IoStatus.Information);
377 | }
378 |
--------------------------------------------------------------------------------
/Solutions/4/4C/CDFilter.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 |
39 | #pragma once
40 |
41 | #include
42 | #include
43 |
44 | //
45 | // Our per device context
46 | //
47 | typedef struct _FILTER_DEVICE_CONTEXT {
48 |
49 | WDFDEVICE WdfDevice;
50 |
51 | WDFIOTARGET LocalTarget;
52 |
53 | } FILTER_DEVICE_CONTEXT, *PFILTER_DEVICE_CONTEXT;
54 |
55 |
56 | //
57 | // Context accessor function
58 | //
59 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FILTER_DEVICE_CONTEXT,
60 | CDFilterGetDeviceContext)
61 |
62 | extern "C" {
63 | DRIVER_INITIALIZE DriverEntry;
64 | }
65 |
66 | EVT_WDF_DRIVER_DEVICE_ADD CDFilterEvtDeviceAdd;
67 |
68 | EVT_WDF_IO_QUEUE_IO_READ CDFilterEvtRead;
69 | EVT_WDF_REQUEST_COMPLETION_ROUTINE CDFilterReadComplete;
70 |
--------------------------------------------------------------------------------
/Solutions/5/5A/basicusb.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 |
46 | //
47 | // Generate our device interface GUID
48 | //
49 | #include // required for GUID definitions
50 | DEFINE_GUID (GUID_DEVINTERFACE_BASICUSB,
51 | 0x79963ae7, 0x45de, 0x4a31, 0x8f, 0x34, 0xf0, 0xe8, 0x90, 0xb, 0xc2, 0x18);
52 |
53 | #include "BASICUSB_IOCTL.h"
54 |
55 | //
56 | // BasicUsb device context structure
57 | //
58 | // WDF will associate this structure with each "BasicUsb" device that
59 | // this driver creates.
60 | //
61 | typedef struct _BASICUSB_DEVICE_CONTEXT {
62 |
63 | //
64 | // Our USB I/O target
65 | //
66 | WDFUSBDEVICE UsbDeviceTarget;
67 |
68 | //
69 | // Our bulk IN pipe
70 | //
71 | WDFUSBPIPE BulkInPipe;
72 |
73 | //
74 | // Our bulk OUT pipe
75 | //
76 | WDFUSBPIPE BulkOutPipe;
77 |
78 | //
79 | // Our interrupt IN pipe
80 | //
81 | WDFUSBPIPE InterruptInPipe;
82 |
83 | } BASICUSB_DEVICE_CONTEXT, * PBASICUSB_DEVICE_CONTEXT;
84 |
85 | //
86 | // The various vendor commands for our device.
87 | //
88 | constexpr UCHAR USBFX2LK_READ_7SEGMENT_DISPLAY = 0xD4;
89 | constexpr UCHAR USBFX2LK_READ_SWITCHES = 0xD6;
90 | constexpr UCHAR USBFX2LK_READ_BARGRAPH_DISPLAY = 0xD7;
91 | constexpr UCHAR USBFX2LK_SET_BARGRAPH_DISPLAY = 0xD8;
92 | constexpr UCHAR USBFX2LK_IS_HIGH_SPEED = 0xD9;
93 | constexpr UCHAR USBFX2LK_REENUMERATE = 0xDA;
94 | constexpr UCHAR USBFX2LK_SET_7SEGMENT_DISPLAY = 0xDB;
95 |
96 | //
97 | // Accessor structure
98 | //
99 | // Given a WDFDEVICE handle, we'll use the following function to return
100 | // a pointer to our device's context area.
101 | //
102 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(BASICUSB_DEVICE_CONTEXT, BasicUsbGetContextFromDevice)
103 |
104 | //
105 | // Forward declarations
106 | //
107 | extern "C" {
108 | DRIVER_INITIALIZE DriverEntry;
109 | }
110 | EVT_WDF_DRIVER_DEVICE_ADD BasicUsbEvtDeviceAdd;
111 | EVT_WDF_IO_QUEUE_IO_READ BasicUsbEvtRead;
112 | EVT_WDF_IO_QUEUE_IO_WRITE BasicUsbEvtWrite;
113 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL BasicUsbEvtDeviceControl;
114 | EVT_WDF_DEVICE_PREPARE_HARDWARE BasicUsbEvtDevicePrepareHardware;
115 |
116 | EVT_WDF_DEVICE_D0_ENTRY BasicUsbEvtDeviceD0Entry;
117 |
118 | EVT_WDF_DEVICE_D0_EXIT BasicUsbEvtDeviceD0Exit;
119 |
120 |
121 | EVT_WDF_USB_READER_COMPLETION_ROUTINE BasicUsbInterruptPipeReadComplete;
122 |
123 | EVT_WDF_REQUEST_COMPLETION_ROUTINE BasicUsbEvtRequestWriteCompletionRoutine;
124 |
125 | NTSTATUS
126 | BasicUsbDoSetBarGraph(_In_ PBASICUSB_DEVICE_CONTEXT DevContext,
127 | _In_ WDFREQUEST Request,
128 | _Out_ PULONG_PTR BytesWritten);
129 |
130 | EVT_WDF_REQUEST_COMPLETION_ROUTINE BasicUsbEvtRequestReadCompletionRoutine;
131 |
132 |
133 |
--------------------------------------------------------------------------------
/Solutions/5/5B/basicusb.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 |
46 | //
47 | // Generate our device interface GUID
48 | //
49 | #include // required for GUID definitions
50 | DEFINE_GUID (GUID_DEVINTERFACE_BASICUSB,
51 | 0x79963ae7, 0x45de, 0x4a31, 0x8f, 0x34, 0xf0, 0xe8, 0x90, 0xb, 0xc2, 0x18);
52 |
53 | #include "BASICUSB_IOCTL.h"
54 |
55 | //
56 | // BasicUsb device context structure
57 | //
58 | // WDF will associate this structure with each "BasicUsb" device that
59 | // this driver creates.
60 | //
61 | typedef struct _BASICUSB_DEVICE_CONTEXT {
62 |
63 | //
64 | // Our USB I/O target
65 | //
66 | WDFUSBDEVICE UsbDeviceTarget;
67 |
68 | //
69 | // Our bulk IN pipe
70 | //
71 | WDFUSBPIPE BulkInPipe;
72 |
73 | //
74 | // Our bulk OUT pipe
75 | //
76 | WDFUSBPIPE BulkOutPipe;
77 |
78 | //
79 | // Our interrupt IN pipe
80 | //
81 | WDFUSBPIPE InterruptInPipe;
82 |
83 | //
84 | // The current switch pack state
85 | //
86 | UCHAR SwitchPackState;
87 |
88 | } BASICUSB_DEVICE_CONTEXT, * PBASICUSB_DEVICE_CONTEXT;
89 |
90 | //
91 | // The various vendor commands for our device.
92 | //
93 | constexpr UCHAR USBFX2LK_READ_7SEGMENT_DISPLAY = 0xD4;
94 | constexpr UCHAR USBFX2LK_READ_SWITCHES = 0xD6;
95 | constexpr UCHAR USBFX2LK_READ_BARGRAPH_DISPLAY = 0xD7;
96 | constexpr UCHAR USBFX2LK_SET_BARGRAPH_DISPLAY = 0xD8;
97 | constexpr UCHAR USBFX2LK_IS_HIGH_SPEED = 0xD9;
98 | constexpr UCHAR USBFX2LK_REENUMERATE = 0xDA;
99 | constexpr UCHAR USBFX2LK_SET_7SEGMENT_DISPLAY = 0xDB;
100 |
101 | //
102 | // Accessor structure
103 | //
104 | // Given a WDFDEVICE handle, we'll use the following function to return
105 | // a pointer to our device's context area.
106 | //
107 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(BASICUSB_DEVICE_CONTEXT, BasicUsbGetContextFromDevice)
108 |
109 | //
110 | // Forward declarations
111 | //
112 | extern "C" {
113 | DRIVER_INITIALIZE DriverEntry;
114 | }
115 | EVT_WDF_DRIVER_DEVICE_ADD BasicUsbEvtDeviceAdd;
116 | EVT_WDF_IO_QUEUE_IO_READ BasicUsbEvtRead;
117 | EVT_WDF_IO_QUEUE_IO_WRITE BasicUsbEvtWrite;
118 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL BasicUsbEvtDeviceControl;
119 | EVT_WDF_DEVICE_PREPARE_HARDWARE BasicUsbEvtDevicePrepareHardware;
120 |
121 | EVT_WDF_DEVICE_D0_ENTRY BasicUsbEvtDeviceD0Entry;
122 |
123 | EVT_WDF_DEVICE_D0_EXIT BasicUsbEvtDeviceD0Exit;
124 |
125 |
126 | EVT_WDF_USB_READER_COMPLETION_ROUTINE BasicUsbInterruptPipeReadComplete;
127 |
128 | EVT_WDF_REQUEST_COMPLETION_ROUTINE BasicUsbEvtRequestWriteCompletionRoutine;
129 |
130 | NTSTATUS
131 | BasicUsbDoSetBarGraph(_In_ PBASICUSB_DEVICE_CONTEXT DevContext,
132 | _In_ WDFREQUEST Request,
133 | _Out_ PULONG_PTR BytesWritten);
134 |
135 | EVT_WDF_REQUEST_COMPLETION_ROUTINE BasicUsbEvtRequestReadCompletionRoutine;
136 |
137 |
138 |
--------------------------------------------------------------------------------
/Solutions/5/5B/basicusb_ioctl.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | // ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | // CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | // CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
28 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | // POSSIBILITY OF SUCH DAMAGE
30 | //
31 |
32 | //
33 | // This header file contains all declarations shared between driver and user
34 | // applications.
35 | //
36 |
37 | #ifndef __BASICUSB_IOCTL_H__
38 | #define __BASICUSB_IOCTL_H__ (1)
39 |
40 | //
41 | // The following value is arbitrarily chosen from the space defined by Microsoft
42 | // as being "for non-Microsoft use"
43 | //
44 | #define FILE_DEVICE_BASICUSB 0xCF53
45 |
46 | //
47 | // Device control codes - values between 2048 and 4095 arbitrarily chosen
48 | //
49 | #define IOCTL_OSR_BASICUSB_SET_BAR_GRAPH CTL_CODE(FILE_DEVICE_BASICUSB,\
50 | 2049, \
51 | METHOD_BUFFERED, \
52 | FILE_WRITE_ACCESS)
53 |
54 | #define IOCTL_OSR_BASICUSB_GET_SWITCHPACK_STATE \
55 | CTL_CODE(FILE_DEVICE_BASICUSB,\
56 | 2050, \
57 | METHOD_BUFFERED, \
58 | FILE_READ_ACCESS)
59 |
60 | #endif /* __BASICUSB_IOCTL_H__ */
61 |
62 |
--------------------------------------------------------------------------------
/Solutions/5/5C/basicusb.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 |
46 | //
47 | // Generate our device interface GUID
48 | //
49 | #include // required for GUID definitions
50 | DEFINE_GUID (GUID_DEVINTERFACE_BASICUSB,
51 | 0x79963ae7, 0x45de, 0x4a31, 0x8f, 0x34, 0xf0, 0xe8, 0x90, 0xb, 0xc2, 0x18);
52 |
53 | #include "BASICUSB_IOCTL.h"
54 |
55 | //
56 | // BasicUsb device context structure
57 | //
58 | // WDF will associate this structure with each "BasicUsb" device that
59 | // this driver creates.
60 | //
61 | typedef struct _BASICUSB_DEVICE_CONTEXT {
62 |
63 | //
64 | // Our USB I/O target
65 | //
66 | WDFUSBDEVICE UsbDeviceTarget;
67 |
68 | //
69 | // Our bulk IN pipe
70 | //
71 | WDFUSBPIPE BulkInPipe;
72 |
73 | //
74 | // Our bulk OUT pipe
75 | //
76 | WDFUSBPIPE BulkOutPipe;
77 |
78 | //
79 | // Our interrupt IN pipe
80 | //
81 | WDFUSBPIPE InterruptInPipe;
82 |
83 | //
84 | // The current switch pack state
85 | //
86 | UCHAR SwitchPackState;
87 |
88 | //
89 | // A manual queue to hold pending "switch pack state change"
90 | // requests.
91 | //
92 | WDFQUEUE SwitchPackStateChangeQueue;
93 |
94 | } BASICUSB_DEVICE_CONTEXT, * PBASICUSB_DEVICE_CONTEXT;
95 |
96 | //
97 | // The various vendor commands for our device.
98 | //
99 | constexpr UCHAR USBFX2LK_READ_7SEGMENT_DISPLAY = 0xD4;
100 | constexpr UCHAR USBFX2LK_READ_SWITCHES = 0xD6;
101 | constexpr UCHAR USBFX2LK_READ_BARGRAPH_DISPLAY = 0xD7;
102 | constexpr UCHAR USBFX2LK_SET_BARGRAPH_DISPLAY = 0xD8;
103 | constexpr UCHAR USBFX2LK_IS_HIGH_SPEED = 0xD9;
104 | constexpr UCHAR USBFX2LK_REENUMERATE = 0xDA;
105 | constexpr UCHAR USBFX2LK_SET_7SEGMENT_DISPLAY = 0xDB;
106 |
107 | //
108 | // Accessor structure
109 | //
110 | // Given a WDFDEVICE handle, we'll use the following function to return
111 | // a pointer to our device's context area.
112 | //
113 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(BASICUSB_DEVICE_CONTEXT, BasicUsbGetContextFromDevice)
114 |
115 | //
116 | // Forward declarations
117 | //
118 | extern "C" {
119 | DRIVER_INITIALIZE DriverEntry;
120 | }
121 | EVT_WDF_DRIVER_DEVICE_ADD BasicUsbEvtDeviceAdd;
122 | EVT_WDF_IO_QUEUE_IO_READ BasicUsbEvtRead;
123 | EVT_WDF_IO_QUEUE_IO_WRITE BasicUsbEvtWrite;
124 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL BasicUsbEvtDeviceControl;
125 | EVT_WDF_DEVICE_PREPARE_HARDWARE BasicUsbEvtDevicePrepareHardware;
126 |
127 | EVT_WDF_DEVICE_D0_ENTRY BasicUsbEvtDeviceD0Entry;
128 |
129 | EVT_WDF_DEVICE_D0_EXIT BasicUsbEvtDeviceD0Exit;
130 |
131 |
132 | EVT_WDF_USB_READER_COMPLETION_ROUTINE BasicUsbInterruptPipeReadComplete;
133 |
134 | EVT_WDF_REQUEST_COMPLETION_ROUTINE BasicUsbEvtRequestWriteCompletionRoutine;
135 |
136 | NTSTATUS
137 | BasicUsbDoSetBarGraph(_In_ PBASICUSB_DEVICE_CONTEXT DevContext,
138 | _In_ WDFREQUEST Request,
139 | _Out_ PULONG_PTR BytesWritten);
140 |
141 | EVT_WDF_REQUEST_COMPLETION_ROUTINE BasicUsbEvtRequestReadCompletionRoutine;
142 |
143 |
144 |
--------------------------------------------------------------------------------
/Solutions/5/5C/basicusb_ioctl.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 | // ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 | // CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 | // CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE)
28 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | // POSSIBILITY OF SUCH DAMAGE
30 | //
31 |
32 | //
33 | // This header file contains all declarations shared between driver and user
34 | // applications.
35 | //
36 |
37 | #ifndef __BASICUSB_IOCTL_H__
38 | #define __BASICUSB_IOCTL_H__ (1)
39 |
40 | //
41 | // The following value is arbitrarily chosen from the space defined by Microsoft
42 | // as being "for non-Microsoft use"
43 | //
44 | #define FILE_DEVICE_BASICUSB 0xCF53
45 |
46 | //
47 | // Device control codes - values between 2048 and 4095 arbitrarily chosen
48 | //
49 | #define IOCTL_OSR_BASICUSB_SET_BAR_GRAPH CTL_CODE(FILE_DEVICE_BASICUSB,\
50 | 2049, \
51 | METHOD_BUFFERED, \
52 | FILE_WRITE_ACCESS)
53 |
54 | #define IOCTL_OSR_BASICUSB_GET_SWITCHPACK_STATE \
55 | CTL_CODE(FILE_DEVICE_BASICUSB,\
56 | 2050, \
57 | METHOD_BUFFERED, \
58 | FILE_READ_ACCESS)
59 |
60 | #endif /* __BASICUSB_IOCTL_H__ */
61 |
62 |
--------------------------------------------------------------------------------
/Solutions/5/BasicUsb Test/basicusbtest.c:
--------------------------------------------------------------------------------
1 | //
2 | // basicusbtest.c
3 | //
4 | // Win32 console mode program to fire up requests to the
5 | // BASICUSB driver.
6 | //
7 | #define _CRT_SECURE_NO_WARNINGS
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | //
15 | // Simple test application to demonstrate the BasicUSB driver
16 | //
17 |
18 | __cdecl main(ULONG argc, LPSTR *argv)
19 | {
20 | HANDLE deviceHandle;
21 | DWORD code;
22 | ULONG index;
23 | UCHAR writeBuffer[512];
24 | UCHAR readBuffer[512];
25 | DWORD function;
26 | UCHAR barGraph;
27 | UCHAR switchPackState;
28 |
29 | //
30 | // Init the write and read buffers with known data
31 | //
32 | memset(readBuffer, 0xAA, sizeof(readBuffer));
33 |
34 | memset(writeBuffer, 0xEE, sizeof(writeBuffer));
35 |
36 | //
37 | // Open the sample PCI device
38 | //
39 | deviceHandle = CreateFile(L"\\\\.\\BASICUSB",
40 | GENERIC_READ|GENERIC_WRITE,
41 | 0,
42 | 0,
43 | OPEN_EXISTING,
44 | 0,
45 | 0);
46 |
47 | //
48 | // If this call fails, check to figure out what the error is and report it.
49 | //
50 | if (deviceHandle == INVALID_HANDLE_VALUE) {
51 |
52 | code = GetLastError();
53 |
54 | printf("CreateFile failed with error 0x%x\n", code);
55 |
56 | return(code);
57 | }
58 |
59 | //
60 | // Infinitely print out the list of choices, ask for input, process
61 | // the request
62 | //
63 | while(TRUE) {
64 |
65 | printf ("\nBASICUSB TEST -- functions:\n\n");
66 | printf ("\t1. Send a sync READ\n");
67 | printf ("\t2. Send a sync WRITE\n");
68 | printf ("\t3. Send SET_BAR_GRAPH IOCTL - All On\n");
69 | printf ("\t4. Send SET_BAR_GRAPH IOCTL - All Off\n");
70 | printf ("\t5. Get switch pack state\n");
71 | printf ("\n\t0. Exit\n");
72 | printf ("\n\tSelection: ");
73 | scanf ("%x", &function);
74 |
75 | switch(function) {
76 |
77 | case 1:
78 | //
79 | // Send a read
80 | //
81 | if ( !ReadFile(deviceHandle,
82 | readBuffer,
83 | sizeof(readBuffer),
84 | &index,
85 | NULL)) {
86 |
87 | code = GetLastError();
88 |
89 | printf("ReadFile failed with error 0x%x\n", code);
90 |
91 | return(code);
92 | }
93 | printf("Bytes Read = %d.\n", index);
94 | break;
95 |
96 | case 2:
97 | //
98 | // Send a write
99 | //
100 | if (!WriteFile(deviceHandle,
101 | writeBuffer,
102 | sizeof(writeBuffer),
103 | &index,
104 | NULL)) {
105 |
106 | code = GetLastError();
107 |
108 | printf("WriteFile failed with error 0x%x\n", code);
109 |
110 | return(code);
111 | }
112 | printf("Bytes Written = %d.\n", index);
113 | break;
114 |
115 | case 3:
116 | barGraph = 0xFF;
117 |
118 | if (!DeviceIoControl(deviceHandle,
119 | IOCTL_OSR_BASICUSB_SET_BAR_GRAPH,
120 | &barGraph,
121 | sizeof(UCHAR),
122 | NULL,
123 | 0,
124 | &index,
125 | NULL)) {
126 |
127 | code = GetLastError();
128 |
129 | printf("DeviceIoControl failed with error 0x%x\n", code);
130 | return(code);
131 |
132 | }
133 |
134 | printf("IOCTL worked!\n");
135 | break;
136 | case 4:
137 | barGraph = 0;
138 |
139 | if (!DeviceIoControl(deviceHandle,
140 | IOCTL_OSR_BASICUSB_SET_BAR_GRAPH,
141 | &barGraph,
142 | sizeof(UCHAR),
143 | NULL,
144 | 0,
145 | &index,
146 | NULL)) {
147 |
148 | code = GetLastError();
149 |
150 | printf("DeviceIoControl failed with error 0x%x\n", code);
151 | return(code);
152 |
153 | }
154 | printf("IOCTL worked!\n");
155 | break;
156 | case 5:
157 | switchPackState = 0;
158 |
159 | if (!DeviceIoControl(
160 | deviceHandle,
161 | IOCTL_OSR_BASICUSB_GET_SWITCHPACK_STATE,
162 | NULL, // Ptr to InBuffer
163 | 0, // Length of InBuffer
164 | &switchPackState, // Ptr to OutBuffer
165 | sizeof(UCHAR), // Length of OutBuffer
166 | &index, // BytesReturned
167 | NULL)) {
168 |
169 | code = GetLastError();
170 |
171 | printf("DeviceIoControl failed with error 0x%x\n", code);
172 | return(code);
173 |
174 | }
175 |
176 | printf("IOCTL worked! Switchpack state is 0x%x\n", switchPackState);
177 | break;
178 |
179 | case 0:
180 |
181 | //
182 | // zero is get out!
183 | //
184 | return(0);
185 |
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/Solutions/6/6a/nothing.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2007-2022 OSR Open Systems Resources, Inc.
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are met:
7 | //
8 | // 1. Redistributions of source code must retain the above copyright notice,
9 | // this list of conditions and the following disclaimer.
10 | //
11 | // 2. Redistributions in binary form must reproduce the above copyright notice,
12 | // this list of conditions and the following disclaimer in the documentation
13 | // and/or other materials provided with the distribution.
14 | //
15 | // 3. Neither the name of the copyright holder nor the names of its
16 | // contributors may be used to endorse or promote products derived from this
17 | // software without specific prior written permission.
18 | //
19 | // This software is supplied for instructional purposes only. It is not
20 | // complete, and it is not suitable for use in any production environment.
21 | //
22 | // OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
23 | // for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
24 | // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
26 | // PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
27 | // WITH YOU. OSR's entire liability and your exclusive remedy shall not
28 | // exceed the price paid for this material. In no event shall OSR or its
29 | // suppliers be liable for any damages whatsoever (including, without
30 | // limitation, damages for loss of business profit, business interruption,
31 | // loss of business information, or any other pecuniary loss) arising out
32 | // of the use or inability to use this software, even if OSR has been
33 | // advised of the possibility of such damages. Because some states/
34 | // jurisdictions do not allow the exclusion or limitation of liability for
35 | // consequential or incidental damages, the above limitation may not apply
36 | // to you.
37 | //
38 | #pragma once
39 |
40 | #include
41 | #include
42 |
43 | #include "NOTHING_IOCTL.h"
44 |
45 | //
46 | // Choose an arbitrary maximum buffer length
47 | //
48 | #define NOTHING_BUFFER_MAX_LENGTH 4096
49 |
50 | //
51 | // Nothing device context structure
52 | //
53 | // KMDF will associate this structure with each "Nothing" device that
54 | // this driver creates.
55 | //
56 | typedef struct _NOTHING_DEVICE_CONTEXT {
57 |
58 | ULONG Nothing;
59 |
60 | //
61 | // Manual queues for holding incoming requests if no data
62 | // pending.
63 | //
64 | WDFQUEUE ReadQueue;
65 | WDFQUEUE WriteQueue;
66 |
67 | //
68 | // We'll keep all the outstanding WDFFILEOBJECTs in a
69 | // collection.
70 | //
71 | WDFCOLLECTION FileObjectsCollection;
72 |
73 | //
74 | // Lock that guards removals from the above collection
75 | //
76 | WDFSPINLOCK FileObjectsCollectionLock;
77 |
78 | //
79 | // The WDFILEOBJECT of the only caller allowed to write to the
80 | // buffer.
81 | //
82 | WDFFILEOBJECT AllowedWriter;
83 |
84 | } NOTHING_DEVICE_CONTEXT, *PNOTHING_DEVICE_CONTEXT;
85 |
86 | //
87 | // Accessor structure
88 | //
89 | // Given a WDFDEVICE handle, we'll use the following function to return
90 | // a pointer to our device's context area.
91 | //
92 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(NOTHING_DEVICE_CONTEXT,
93 | NothingGetContextFromDevice)
94 |
95 | //
96 | // Forward declarations
97 | //
98 | extern "C" {
99 | DRIVER_INITIALIZE DriverEntry;
100 | }
101 | EVT_WDF_DRIVER_DEVICE_ADD NothingEvtDeviceAdd;
102 | EVT_WDF_IO_QUEUE_IO_READ NothingEvtRead;
103 | EVT_WDF_IO_QUEUE_IO_WRITE NothingEvtWrite;
104 | EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL NothingEvtDeviceControl;
105 |
106 | EVT_WDF_DEVICE_D0_ENTRY NothingEvtDeviceD0Entry;
107 | EVT_WDF_DEVICE_D0_EXIT NothingEvtDeviceD0Exit;
108 |
109 | EVT_WDF_DEVICE_FILE_CREATE NothingEvtFdoCreate;
110 | EVT_WDF_FILE_CLOSE NothingEvtFdoClose;
111 |
112 | //
113 | CHAR const *
114 | NothingPowerDeviceStateToString(WDF_POWER_DEVICE_STATE DeviceState);
115 |
--------------------------------------------------------------------------------
/Solutions/README.md:
--------------------------------------------------------------------------------
1 | # Solutions to Labs Exercises #
2 | These are the current solutions to the lab exercises provided on the first day of lab.
3 |
4 | [https://www.osr.com/seminars/wdf-drivers/](https://www.osr.com/seminars/wdf-drivers/)
5 |
6 |
--------------------------------------------------------------------------------