ReactOS  0.4.14-dev-98-gb0d4763
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 }
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416
_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
LPTSTR ServiceName
Definition: ServiceMain.c:15
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#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  {
160  Error = GetLastError();
161  }
162 
163  return Error;
164 }
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
#define assert(x)
Definition: debug.h:53
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66

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 }
#define assert(x)
Definition: debug.h:53
_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
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define SCODE_CODE(sc)
Definition: winerror.h:77

◆ KmtFltGetMessageResult()

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

Definition at line 306 of file filter.c.

310 {
311  BOOL Success;
313 
314  *BytesTransferred = 0;
315 
316  Success = GetOverlappedResult(hPort, Overlapped, BytesTransferred, TRUE);
317  if (!Success)
318  {
319  Error = GetLastError();
320  }
321 
322  return Error;
323 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66

◆ 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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define assert(x)
Definition: debug.h:53
LPTSTR ServiceName
Definition: ServiceMain.c:15
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define SCODE_CODE(sc)
Definition: winerror.h:77
_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,
285  ReplyBuffer,
286  ReplyBufferSize);
287  Error = SCODE_CODE(hResult);
288  return Error;
289 }
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID ReplyBuffer
Definition: fltkernel.h:1903
#define SCODE_CODE(sc)
Definition: winerror.h:77
_Must_inspect_result_ HRESULT WINAPI FilterReplyMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwReplyBufferSize) PFILTER_REPLY_HEADER lpReplyBuffer, _In_ DWORD dwReplyBufferSize)
Definition: message.c:165

◆ 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 
203  if (BytesReturned) *BytesReturned = 0;
204 
205  hResult = FilterSendMessage(hPort,
206  InBuffer,
207  InBufferSize,
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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG OutBufferSize
Definition: classpnp.h:429
#define assert(x)
Definition: debug.h:53
_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_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG InBufferSize
Definition: classpnp.h:429
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
#define SCODE_CODE(sc)
Definition: winerror.h:77

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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define assert(x)
Definition: debug.h:53
_Must_inspect_result_ HRESULT WINAPI FilterUnload(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:50
LPTSTR ServiceName
Definition: ServiceMain.c:15
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define SCODE_CODE(sc)
Definition: winerror.h:77

Referenced by KmtFltLoadDriver(), and KmtFltUnloadDriver().