Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

wdm/PortEnum.c

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or
00003  *  modify it under the terms of the GNU General Public License
00004  *  as published by the Free Software Foundation; either version
00005  *  2 of the License, or (at your option) any later version.
00006  *
00007  *  Copyright 2004 Spiro Trikaliotis
00008  *
00009  */
00010 
00020 #include <initguid.h>
00021 #include <wdm.h>
00022 
00023 #define PENUMERATE_DEFINED 
00024 typedef struct ENUMERATE_WDM *PENUMERATE;
00025 #include "cbm_driver.h"
00026 
00031 typedef
00032 struct ENUMERATE_WDM
00033 {
00037     PWSTR SymbolicLinkList;
00038 
00040     PWSTR CurrentSymbolicLink;
00041 } ENUMERATE, *PENUMERATE;
00042 
00043 
00064 NTSTATUS
00065 ParPortEnumerateOpen(PENUMERATE *EnumStruct)
00066 {
00067     PENUMERATE enumStruct;
00068     NTSTATUS ntStatus;
00069 
00070     FUNC_ENTER();
00071 
00072     // Allocate memory for the enumStruct
00073 
00074     DBG_IRQL( < DISPATCH_LEVEL);
00075     enumStruct = ExAllocatePoolWithTag(PagedPool, 
00076         sizeof(ENUMERATE), MTAG_SENUMERATE);
00077 
00078     if (enumStruct)
00079     {
00080         // Mark: We did not yet enumerate the first entry
00081 
00082         enumStruct->CurrentSymbolicLink = NULL;
00083 
00084         // Get every device which implementes our interface
00085 
00086         DBG_IRQL( == PASSIVE_LEVEL);
00087         ntStatus = IoGetDeviceInterfaces(&GUID_PARALLEL_DEVICE,
00088             NULL, // no pdo given
00089             0,
00090             &enumStruct->SymbolicLinkList);
00091     }
00092     else 
00093     {
00094         ntStatus = STATUS_INSUFFICIENT_RESOURCES;
00095     }
00096 
00097     // didn't we succeed? Then return with the correct value
00098 
00099     if (!NT_SUCCESS(ntStatus))  
00100     {
00101         // We had a problem obtaining the devices which implement the
00102         // parallel port interface, thus, fail this function
00103 
00104         if (enumStruct)
00105         {
00106             // Free the enumStruct
00107 
00108             DBG_IRQL( < DISPATCH_LEVEL);
00109             ExFreePool(enumStruct);
00110 
00111             enumStruct = NULL;
00112         }
00113     }
00114 
00115     *EnumStruct = enumStruct;
00116 
00117     FUNC_LEAVE_NTSTATUS(ntStatus);
00118 }
00119 
00143 NTSTATUS
00144 ParPortEnumerate(PENUMERATE EnumStruct, PCWSTR *DriverName)
00145 {
00146     FUNC_ENTER();
00147 
00148     DBG_ASSERT(EnumStruct != NULL);
00149     DBG_ASSERT(EnumStruct->SymbolicLinkList != NULL);
00150 
00151     // Advance EnumStruct->CurrentSymbolicLink to the next entry
00152 
00153     if (EnumStruct->CurrentSymbolicLink == NULL)
00154     {
00155         // we just started enumerating, get the first entry
00156 
00157         EnumStruct->CurrentSymbolicLink = EnumStruct->SymbolicLinkList;
00158     }
00159     else
00160     {
00161         // advance to the next entry
00162 
00163         EnumStruct->CurrentSymbolicLink += wcslen(EnumStruct->CurrentSymbolicLink)+1;
00164     }
00165 
00166     // Give the next driver name to the caller
00167 
00168     *DriverName = EnumStruct->CurrentSymbolicLink;
00169 
00170     FUNC_LEAVE_NTSTATUS((**DriverName) ? STATUS_SUCCESS : STATUS_NO_MORE_ENTRIES);
00171 }
00172 
00188 VOID
00189 ParPortEnumerateClose(PENUMERATE EnumStruct)
00190 {
00191     FUNC_ENTER();
00192 
00193     DBG_ASSERT(EnumStruct != NULL);
00194     DBG_ASSERT(EnumStruct->SymbolicLinkList != NULL);
00195 
00196     // Free both allocated buffers
00197 
00198     DBG_IRQL( < DISPATCH_LEVEL);
00199     ExFreePool(EnumStruct->SymbolicLinkList);
00200     ExFreePool(EnumStruct);
00201 
00202     DBGDO(EnumStruct = NULL;)
00203 
00204     FUNC_LEAVE();
00205 }
00206 
00213 NTSTATUS 
00214 CbmOpenDeviceRegistryKey(IN PDEVICE_OBJECT a, IN ULONG b, IN ACCESS_MASK c, OUT PHANDLE d)
00215 {
00216     FUNC_ENTER();
00217 
00218     FUNC_LEAVE_NTSTATUS(IoOpenDeviceRegistryKey(a, b, c, d));
00219 }

Generated on Sun Apr 30 18:45:57 2006 for opencbm by  doxygen 1.4.2