ReactOS 0.4.15-dev-7958-gcd0bb1a
filter.c File Reference
#include <kmt_test.h>
#include "kmtest.h"
#include <assert.h>
Include dependency graph for filter.c:

Go to the source code of this file.

Macros

#define SERVICE_ACCESS   (SERVICE_START | SERVICE_STOP | DELETE)
 

Functions

KmtFltLoad

Start the specified filter driver by name

Parameters
ServiceNameThe name of the filter to start
Returns
Win32 error code
DWORD KmtFltLoad (_In_z_ PCWSTR ServiceName)
 
KmtFltConnect

Create a comms connection to the specified filter

Parameters
ServiceNameName of the filter to connect to
hPortHandle to the filter's comms port
Returns
Win32 error code
DWORD KmtFltConnect (_In_z_ PCWSTR ServiceName, _Out_ HANDLE *hPort)
 
KmtFltDisconnect

Disconenct from the comms port

Parameters
hPortHandle to the filter's comms port
Returns
Win32 error code
DWORD KmtFltDisconnect (_In_ HANDLE hPort)
 
KmtFltSendMessage

Sneds a message to a filter driver

Parameters
hPortHandle to the filter's comms port @InBuffer Pointer to a buffer to send to the filter @InBufferSize Size of the buffer pointed to by InBuffer @OutBuffer Pointer to a buffer to receive reply data from the filter @OutBufferSize Size of the buffer pointed to by OutBuffer @BytesReturned Number of bytes written in the reply buffer
Returns
Win32 error code
DWORD KmtFltSendMessage (_In_ HANDLE hPort, _In_reads_bytes_(dwInBufferSize) LPVOID InBuffer, _In_ DWORD InBufferSize, _Out_writes_bytes_to_opt_(dutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
 
KmtFltGetMessage

Gets a message from a filter driver

Parameters
hPortHandle to the filter's comms port @MessageBuffer Pointer to a buffer to receive the data from the filter @MessageBufferSize Size of the buffer pointed to by MessageBuffer @Overlapped Pointer to an overlapped structure
Returns
Win32 error code
DWORD KmtFltGetMessage (_In_ HANDLE hPort, _Out_writes_bytes_(MessageBufferSize) PFILTER_MESSAGE_HEADER MessageBuffer, _In_ DWORD MessageBufferSize, _In_opt_ LPOVERLAPPED Overlapped)
 
KmtFltReplyMessage

Replies to a message from a filter driver

Parameters
hPortHandle to the filter's comms port @ReplyBuffer Pointer to a buffer to return to the filter @ReplyBufferSize Size of the buffer pointed to by ReplyBuffer
Returns
Win32 error code
DWORD KmtFltReplyMessage (_In_ HANDLE hPort, _In_reads_bytes_(ReplyBufferSize) PFILTER_REPLY_HEADER ReplyBuffer, _In_ DWORD ReplyBufferSize)
 
KmtFltGetMessageResult

Gets the overlapped result from the IO

Parameters
hPortHandle to the filter's comms port @Overlapped Pointer to the overlapped structure usdd in the IO @BytesTransferred Number of bytes transferred in the IO
Returns
Win32 error code
DWORD KmtFltGetMessageResult (_In_ HANDLE hPort, _In_ LPOVERLAPPED Overlapped, _Out_ LPDWORD BytesTransferred)
 
KmtFltUnload

Unload the specified filter driver

Parameters
ServiceNameThe name of the filter to unload
Returns
Win32 error code
DWORD KmtFltUnload (_In_z_ PCWSTR ServiceName)
 

Macro Definition Documentation

◆ SERVICE_ACCESS

#define SERVICE_ACCESS   (SERVICE_START | SERVICE_STOP | DELETE)

Definition at line 15 of file filter.c.

Function Documentation

◆ KmtFltConnect()

DWORD KmtFltConnect ( _In_z_ PCWSTR  ServiceName,
_Out_ HANDLE hPort 
)

Definition at line 119 of file filter.c.

122{
123 HRESULT hResult;
124 DWORD Error;
125
127 assert(hPort);
128
130 0,
131 NULL,
132 0,
133 NULL,
134 hPort);
135 Error = SCODE_CODE(hResult);
136
137 return Error;
138}
static WCHAR ServiceName[]
Definition: browser.c:19
BOOL Error
Definition: chkdsk.c:66
#define NULL
Definition: types.h:112
_Must_inspect_result_ HRESULT WINAPI FilterConnectCommunicationPort(_In_ LPCWSTR lpPortName, _In_ DWORD dwOptions, _In_reads_bytes_opt_(wSizeOfContext) LPCVOID lpContext, _In_ WORD wSizeOfContext, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Outptr_ HANDLE *hPort)
Definition: message.c:25
#define assert(x)
Definition: debug.h:53
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SCODE_CODE(sc)
Definition: winerror.h:77

Referenced by KmtFltConnectComms().

◆ KmtFltDisconnect()

DWORD KmtFltDisconnect ( _In_ HANDLE  hPort)

Definition at line 151 of file filter.c.

153{
155
156 assert(hPort);
157
158 if (!CloseHandle(hPort))
159 {
161 }
162
163 return Error;
164}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CloseHandle
Definition: compat.h:739
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by KmtFltDisconnectComms(), and KmtFltUnloadDriver().

◆ KmtFltGetMessage()

DWORD KmtFltGetMessage ( _In_ HANDLE  hPort,
_Out_writes_bytes_(MessageBufferSize) PFILTER_MESSAGE_HEADER  MessageBuffer,
_In_ DWORD  MessageBufferSize,
_In_opt_ LPOVERLAPPED  Overlapped 
)

Definition at line 241 of file filter.c.

246{
247 HRESULT hResult;
248 DWORD Error;
249
250 assert(hPort);
251 assert(MessageBuffer);
252
253 hResult = FilterGetMessage(hPort,
254 MessageBuffer,
255 MessageBufferSize,
256 Overlapped);
257 Error = SCODE_CODE(hResult);
258 return Error;
259}
_Must_inspect_result_ HRESULT WINAPI FilterGetMessage(_In_ HANDLE hPort, _Out_writes_bytes_(dwMessageBufferSize) PFILTER_MESSAGE_HEADER lpMessageBuffer, _In_ DWORD dwMessageBufferSize, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: message.c:150

◆ KmtFltGetMessageResult()

DWORD KmtFltGetMessageResult ( _In_ HANDLE  hPort,
_In_ LPOVERLAPPED  Overlapped,
_Out_ LPDWORD  BytesTransferred 
)

Definition at line 306 of file filter.c.

310{
313
314 *BytesTransferred = 0;
315
316 Success = GetOverlappedResult(hPort, Overlapped, BytesTransferred, TRUE);
317 if (!Success)
318 {
320 }
321
322 return Error;
323}
#define TRUE
Definition: types.h:120
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:221
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR _Out_opt_ PULONG BytesTransferred
Definition: wdfusb.h:1342

◆ KmtFltLoad()

DWORD KmtFltLoad ( _In_z_ PCWSTR  ServiceName)

Definition at line 30 of file filter.c.

32{
33 HRESULT hResult;
35
37
38 hResult = FilterLoad(ServiceName);
39 Error = SCODE_CODE(hResult);
40
41 return Error;
42}
_Must_inspect_result_ HRESULT WINAPI FilterLoad(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:42

Referenced by KmtFltLoadDriver().

◆ KmtFltReplyMessage()

DWORD KmtFltReplyMessage ( _In_ HANDLE  hPort,
_In_reads_bytes_(ReplyBufferSize) PFILTER_REPLY_HEADER  ReplyBuffer,
_In_ DWORD  ReplyBufferSize 
)

Definition at line 276 of file filter.c.

280{
281 HRESULT hResult;
282 DWORD Error;
283
284 hResult = FilterReplyMessage(hPort,
286 ReplyBufferSize);
287 Error = SCODE_CODE(hResult);
288 return Error;
289}
_Must_inspect_result_ HRESULT WINAPI FilterReplyMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwReplyBufferSize) PFILTER_REPLY_HEADER lpReplyBuffer, _In_ DWORD dwReplyBufferSize)
Definition: message.c:165
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID ReplyBuffer
Definition: fltkernel.h:1902

◆ KmtFltSendMessage()

DWORD KmtFltSendMessage ( _In_ HANDLE  hPort,
_In_reads_bytes_(dwInBufferSize) LPVOID  InBuffer,
_In_ DWORD  InBufferSize,
_Out_writes_bytes_to_opt_(dutBufferSize, *BytesReturned) LPVOID  OutBuffer,
_In_ DWORD  OutBufferSize,
_Out_opt_ LPDWORD  BytesReturned 
)

Definition at line 187 of file filter.c.

194{
195 DWORD BytesRet;
196 HRESULT hResult;
197 DWORD Error;
198
199 assert(hPort);
200 assert(InBuffer);
202
204
205 hResult = FilterSendMessage(hPort,
206 InBuffer,
208 OutBuffer,
210 &BytesRet);
211
212 Error = SCODE_CODE(hResult);
213 if (Error == ERROR_SUCCESS)
214 {
215 if (BytesRet)
216 {
217 *BytesReturned = BytesRet;
218 }
219 }
220
221 return Error;
222}
_Must_inspect_result_ HRESULT WINAPI FilterSendMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwInBufferSize) LPVOID lpInBuffer, _In_ DWORD dwInBufferSize, _Out_writes_bytes_to_opt_(dwOutBufferSize, *lpBytesReturned) LPVOID lpOutBuffer, _In_ DWORD dwOutBufferSize, _Out_ LPDWORD lpBytesReturned)
Definition: message.c:131
_In_ UCHAR _In_ ULONG _Out_ PUCHAR _Outptr_result_bytebuffer_ OutBufferLength PVOID * OutBuffer
Definition: scsi.h:4071
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesReturned
Definition: wdfiotarget.h:1052
_In_ ULONG OutBufferSize
Definition: wdfwmi.h:87
_In_ ULONG InBufferSize
Definition: wdfwmi.h:106

Referenced by KmtFltSendBufferToDriver().

◆ KmtFltUnload()

DWORD KmtFltUnload ( _In_z_ PCWSTR  ServiceName)

Definition at line 336 of file filter.c.

338{
339 HRESULT hResult;
341
343
344 hResult = FilterUnload(ServiceName);
345 Error = SCODE_CODE(hResult);
346
347 return Error;
348}
_Must_inspect_result_ HRESULT WINAPI FilterUnload(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:50

Referenced by KmtFltLoadDriver(), and KmtFltUnloadDriver().