ReactOS  0.4.15-dev-3163-gf17c2c0
fxdeviceinterfacekm.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxDeviceInterfaceKM.cpp
8 
9 Abstract:
10 
11  This module implements the device interface object.
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Kernel mode only
20 
21 Revision History:
22 
23 --*/
24 
25 #include "fxsupportpch.hpp"
26 
27 extern "C" {
28 // #include "FxDeviceInterfaceKM.tmh"
29 }
30 
32  )
33 /*++
34 
35 Routine Description:
36  Constructor for the object. Initializes all fields
37 
38 Arguments:
39  None
40 
41 Return Value:
42  None
43 
44  --*/
45 {
47 
50 
51  m_Entry.Next = NULL;
52 
53  m_State = FALSE;
54 }
55 
57 /*++
58 
59 Routine Description:
60  Destructor for FxDeviceInterface. Cleans up any allocations previously
61  allocated.
62 
63 Arguments:
64  None
65 
66 Return Value:
67  None
68 
69  --*/
70 {
71  // the device interface should be off now
72  ASSERT(m_State == FALSE);
73 
74  // should no longer be in any list
75  ASSERT(m_Entry.Next == NULL);
76 
77  if (m_ReferenceString.Buffer != NULL) {
80  }
81 
84  }
85 }
86 
90  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
91  __in CONST GUID* InterfaceGUID,
93  )
94 /*++
95 
96 Routine Description:
97  Initializes the object with the interface GUID and optional reference string
98 
99 Arguments:
100  InterfaceGUID - GUID describing the interface
101 
102  ReferenceString - string used to differentiate between 2 interfaces on the
103  same PDO
104 
105 Return Value:
106  STATUS_SUCCESS or STATUS_INSUFFICIENT_RESOURCES
107 
108  --*/
109 {
110  RtlCopyMemory(&m_InterfaceClassGUID, InterfaceGUID, sizeof(GUID));
111 
112  if (ReferenceString != NULL) {
113  return FxDuplicateUnicodeString(FxDriverGlobals,
116  }
117  else {
118  return STATUS_SUCCESS;
119  }
120 }
121 
122 
123 VOID
126  )
127 /*++
128 
129 Routine Description:
130  Sets the state of the device interface
131 
132 Arguments:
133  State - the state to set
134 
135 
136 Return Value:
137  None.
138 
139  --*/
140 {
141  m_State = State;
142 
143  //
144  // Only set the state if the interface has been registered
145  //
146  if (m_SymbolicLinkName.Buffer != NULL) {
148  }
149 }
150 
152 NTSTATUS
155  )
156 /*++
157 
158 Routine Description:
159  Registers the device interface for a given PDO
160 
161 Arguments:
162  Pdo - PDO for the device stack
163 
164 
165 Return Value:
166  returned by IoRegisterDeviceInterface
167 
168  --*/
169 {
171 
172  if (m_ReferenceString.Length > 0) {
174  }
175  else {
176  pString = NULL;
177  }
178 
181 }
182 
184 NTSTATUS
187  )
188 {
190  MdDeviceObject pdo;
191 
192  pdo = Device->GetSafePhysicalDevice();
193 
194  if (pdo != NULL) {
195  status = Register(pdo);
196  }
197  else {
198  //
199  // Leave the device interface unregistered. When we are in hardware
200  // available, we will register there once we know for sure we have a
201  // real live PDO that the system has acknowledged.
202  //
203  DO_NOTHING();
204 
206  }
207 
208  return status;
209 }
210 
211 NTSTATUS
213  _In_ FxString* LinkString
214  )
215 {
217 
218  if (m_SymbolicLinkName.Buffer == NULL) {
219  //
220  // The device interface has not yet been registered b/c it
221  // belongs to a PDO and the PDO has not been recognized by
222  // pnp yet.
223  //
225  UNREFERENCED_PARAMETER(LinkString);
226  }
227  else {
228  //
229  // Attempt a copy
230  //
231  status = LinkString->Assign(&m_SymbolicLinkName);
232  }
233 
234  return status;
235 }
236 
static __inline NTSTATUS MxRegisterDeviceInterface(_In_ PDEVICE_OBJECT PhysicalDeviceObject, _In_ const GUID *InterfaceClassGuid, _In_opt_ PUNICODE_STRING ReferenceString, _Out_ PUNICODE_STRING SymbolicLinkName)
Definition: mxgeneralkm.h:619
UNICODE_STRING m_ReferenceString
_Must_inspect_result_ NTSTATUS Register(__in MdDeviceObject Pdo)
#define __in_opt
Definition: dbghelp.h:38
_Must_inspect_result_ NTSTATUS Initialize(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in CONST GUID *InterfaceGUID, __in_opt PCUNICODE_STRING ReferenceString)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
NTSTATUS GetSymbolicLinkName(_In_ FxString *LinkString)
UNICODE_STRING m_SymbolicLinkName
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
#define FALSE
Definition: types.h:117
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:64
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
VOID SetState(__in BOOLEAN State)
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629
_Must_inspect_result_ NTSTATUS FxDuplicateUnicodeString(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in const UNICODE_STRING *Source, __out PUNICODE_STRING Destination)
Definition: stringutil.cpp:180
static __inline NTSTATUS MxSetDeviceInterfaceState(_In_ PUNICODE_STRING SymbolicLinkName, _In_ BOOLEAN Enable)
Definition: mxgeneralkm.h:608
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
FxString * pString
_Must_inspect_result_ _In_ WDFDEVICE _In_ CONST GUID _In_opt_ PCUNICODE_STRING ReferenceString
Definition: wdfdevice.h:3625
#define NULL
Definition: types.h:112
SINGLE_LIST_ENTRY m_Entry
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
#define __in
Definition: dbghelp.h:35
static SERVICE_STATUS status
Definition: service.c:31
#define CONST
Definition: pedump.c:81
#define DO_NOTHING()
Definition: mxgeneral.h:32
Definition: ps.c:97