OpenCBM
wdm/PortEnum.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2004 Spiro Trikaliotis
8  *
9  */
10 
19 #include <initguid.h>
20 #include <wdm.h>
21 
22 #define PENUMERATE_DEFINED
23 typedef struct ENUMERATE_WDM *PENUMERATE;
24 #include "cbm_driver.h"
25 
30 typedef
31 struct ENUMERATE_WDM
32 {
37 
41 
42 
63 NTSTATUS
64 ParPortEnumerateOpen(PENUMERATE *EnumStruct)
65 {
66  PENUMERATE enumStruct;
67  NTSTATUS ntStatus;
68 
69  FUNC_ENTER();
70 
71  // Allocate memory for the enumStruct
72 
73  DBG_IRQL( < DISPATCH_LEVEL);
74  enumStruct = ExAllocatePoolWithTag(PagedPool,
75  sizeof(ENUMERATE), MTAG_SENUMERATE);
76 
77  if (enumStruct)
78  {
79  // Mark: We did not yet enumerate the first entry
80 
81  enumStruct->CurrentSymbolicLink = NULL;
82 
83  // Get every device which implementes our interface
84 
85  DBG_IRQL( == PASSIVE_LEVEL);
86  ntStatus = IoGetDeviceInterfaces(&GUID_PARALLEL_DEVICE,
87  NULL, // no pdo given
88  0,
89  &enumStruct->SymbolicLinkList);
90  }
91  else
92  {
93  ntStatus = STATUS_INSUFFICIENT_RESOURCES;
94  }
95 
96  // didn't we succeed? Then return with the correct value
97 
98  if (!NT_SUCCESS(ntStatus))
99  {
100  // We had a problem obtaining the devices which implement the
101  // parallel port interface, thus, fail this function
102 
103  if (enumStruct)
104  {
105  // Free the enumStruct
106 
107  DBG_IRQL( < DISPATCH_LEVEL);
108  ExFreePool(enumStruct);
109 
110  enumStruct = NULL;
111  }
112  }
113 
114  *EnumStruct = enumStruct;
115 
116  FUNC_LEAVE_NTSTATUS(ntStatus);
117 }
118 
142 NTSTATUS
143 ParPortEnumerate(PENUMERATE EnumStruct, PCWSTR *DriverName)
144 {
145  FUNC_ENTER();
146 
147  DBG_ASSERT(EnumStruct != NULL);
148  DBG_ASSERT(EnumStruct->SymbolicLinkList != NULL);
149 
150  // Advance EnumStruct->CurrentSymbolicLink to the next entry
151 
152  if (EnumStruct->CurrentSymbolicLink == NULL)
153  {
154  // we just started enumerating, get the first entry
155 
156  EnumStruct->CurrentSymbolicLink = EnumStruct->SymbolicLinkList;
157  }
158  else
159  {
160  // advance to the next entry
161 
162  EnumStruct->CurrentSymbolicLink += wcslen(EnumStruct->CurrentSymbolicLink)+1;
163  }
164 
165  // Give the next driver name to the caller
166 
167  *DriverName = EnumStruct->CurrentSymbolicLink;
168 
169  FUNC_LEAVE_NTSTATUS((**DriverName) ? STATUS_SUCCESS : STATUS_NO_MORE_ENTRIES);
170 }
171 
187 VOID
188 ParPortEnumerateClose(PENUMERATE EnumStruct)
189 {
190  FUNC_ENTER();
191 
192  DBG_ASSERT(EnumStruct != NULL);
193  DBG_ASSERT(EnumStruct->SymbolicLinkList != NULL);
194 
195  // Free both allocated buffers
196 
197  DBG_IRQL( < DISPATCH_LEVEL);
198  ExFreePool(EnumStruct->SymbolicLinkList);
199  ExFreePool(EnumStruct);
200 
201  DBGDO(EnumStruct = NULL;)
202 
203  FUNC_LEAVE();
204 }
205 
212 NTSTATUS
213 CbmOpenDeviceRegistryKey(IN PDEVICE_OBJECT a, IN ULONG b, IN ACCESS_MASK c, OUT PHANDLE d)
214 {
215  FUNC_ENTER();
216 
217  FUNC_LEAVE_NTSTATUS(IoOpenDeviceRegistryKey(a, b, c, d));
218 }
#define DBGDO(_xxx)
Definition: debug.h:409
NTSTATUS CbmOpenDeviceRegistryKey(IN PDEVICE_OBJECT a, IN ULONG b, IN ACCESS_MASK c, OUT PHANDLE d)
Stub for a function.
Definition: wdm/PortEnum.c:213
#define FUNC_LEAVE()
Definition: debug.h:349
NTSTATUS ParPortEnumerate(PENUMERATE EnumStruct, PCWSTR *DriverName)
Get next enumerated parallel port driver.
Definition: wdm/PortEnum.c:143
VOID ParPortEnumerateClose(PENUMERATE EnumStruct)
Stop enumeration of the parallel port drivers.
Definition: wdm/PortEnum.c:188
#define DBG_ASSERT(_xxx)
Definition: debug.h:401
NTSTATUS ParPortEnumerateOpen(PENUMERATE *EnumStruct)
Start enumeration of the parallel port drivers.
Definition: wdm/PortEnum.c:64
struct ENUMERATE_WDM ENUMERATE
struct ENUMERATE_WDM * PENUMERATE
pointer to a ENUMERATE_WDM or ENUMERATE_NT4 struct
Definition: wdm/PortEnum.c:23
#define FUNC_ENTER()
Definition: debug.h:347
#define MTAG_SENUMERATE
Definition: memtags.h:29
PWSTR SymbolicLinkList
Definition: wdm/PortEnum.c:36
PWSTR CurrentSymbolicLink
Definition: wdm/PortEnum.c:39