55 AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PdoUNUSED, IN PCWSTR ParallelPortName)
58 UNICODE_STRING deviceNameNumber;
59 UNICODE_STRING deviceNamePrefix;
60 UNICODE_STRING deviceName;
62 WCHAR deviceNameNumberBuffer[50];
69 UNREFERENCED_PARAMETER(PdoUNUSED);
73 ntStatus = STATUS_SUCCESS;
78 DBG_IRQL( <= DISPATCH_LEVEL);
79 RtlInitUnicodeString(&deviceNamePrefix, CBMDEVICENAME);
83 deviceNameNumber.Length = 0;
84 deviceNameNumber.MaximumLength =
sizeof(deviceNameNumberBuffer);
85 deviceNameNumber.Buffer = deviceNameNumberBuffer;
86 DBG_IRQL( == PASSIVE_LEVEL);
87 RtlIntegerToUnicodeString(no, 10, &deviceNameNumber);
96 deviceName.MaximumLength = deviceNamePrefix.Length + deviceNameNumber.Length;
97 deviceName.Buffer = (PWCHAR) ExAllocatePoolWithTag(NonPagedPool,
100 if (!deviceName.Buffer)
102 ntStatus = STATUS_INSUFFICIENT_RESOURCES;
104 LogErrorString(NULL, CBM_START_FAILED, L
"allocating memory for device name", NULL);
107 if (NT_SUCCESS(ntStatus))
111 DBG_IRQL( < DISPATCH_LEVEL);
112 RtlCopyUnicodeString(&deviceName, &deviceNamePrefix);
113 DBG_IRQL( < DISPATCH_LEVEL);
114 RtlAppendUnicodeStringToString(&deviceName, &deviceNameNumber);
118 DBG_IRQL( == PASSIVE_LEVEL);
119 ntStatus = IoCreateDevice(DriverObject,
sizeof(
DEVICE_EXTENSION), &deviceName,
120 FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, TRUE, &fdo);
122 if (!NT_SUCCESS(ntStatus))
126 LogErrorString(NULL, CBM_START_FAILED, L
"creation of the device object", NULL);
130 if (NT_SUCCESS(ntStatus))
132 PDEVICE_EXTENSION pdx;
140 pdx = fdo->DeviceExtension;
143 if (!NT_SUCCESS(ntStatus))
149 if (pdx->DeviceName.Buffer)
151 DBG_IRQL( < DISPATCH_LEVEL);
152 ExFreePool(pdx->DeviceName.Buffer);
155 DBG_IRQL( == PASSIVE_LEVEL);
160 FUNC_LEAVE_NTSTATUS(ntStatus);
163 static KMUTEX MutexDriverLoadUnload;
180 PDEVICE_OBJECT currentDevice;
186 DBG_IRQL( < DISPATCH_LEVEL);
187 KeWaitForMutexObject(&MutexDriverLoadUnload, Executive, KernelMode,
192 while (currentDevice = DriverObject->DeviceObject)
194 PDEVICE_EXTENSION pdx = currentDevice->DeviceExtension;
200 if (pdx->ParallelPortIsLocked)
216 if (pdx->DeviceName.Buffer)
218 DBG_IRQL( < DISPATCH_LEVEL);
219 ExFreePool(pdx->DeviceName.Buffer);
226 DBG_IRQL( == PASSIVE_LEVEL);
227 IoDeleteDevice(currentDevice);
242 DBG_IRQL( <= DISPATCH_LEVEL);
243 KeReleaseMutex(&MutexDriverLoadUnload, FALSE);
271 DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
284 KeInitializeMutex(&MutexDriverLoadUnload, 0);
288 DBG_IRQL( < DISPATCH_LEVEL);
289 KeWaitForMutexObject(&MutexDriverLoadUnload, Executive, KernelMode,
310 if (NT_SUCCESS(ntStatus))
318 if (NT_SUCCESS(ntStatus) && *DriverName)
321 AddDevice(DriverObject, NULL, DriverName);
323 }
while (NT_SUCCESS(ntStatus) && *DriverName);
330 DBG_IRQL( <= DISPATCH_LEVEL);
331 KeReleaseMutex(&MutexDriverLoadUnload, FALSE);
333 FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
#define LogErrorString(_Fdo_, _UniqueErrorValue_, _String1_, _String2_)
NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PdoUNUSED, IN PCWSTR ParallelPortName)
create functional device object (FDO) for enumerated device
NTSTATUS cbm_unlock_parport(IN PDEVICE_EXTENSION Pdx)
Unlock the parallel port for the driver.
NTSTATUS AddDeviceCommonInit(IN PDEVICE_OBJECT Fdo, IN PUNICODE_STRING DeviceName, IN PCWSTR ParallelPortName)
Initialize device object, common to WDM and NT4 driver.
NTSTATUS DriverCommonInit(IN PDRIVER_OBJECT Driverobject, IN PUNICODE_STRING RegistryPath)
Perform driver initialization, common to WDM and NT4 driver.
Define the IOCTL codes for the opencbm driver.
NTSTATUS ParPortEnumerate(PENUMERATE EnumStruct, PCWSTR *DriverName)
Get next enumerated parallel port driver.
VOID DbgAllocateMemoryBuffer(VOID)
Get storage area for debugging output.
VOID cbm_stop_thread(IN PDEVICE_EXTENSION Pdx)
Stop the worker thread.
VOID ParPortEnumerateClose(PENUMERATE EnumStruct)
Stop enumeration of the parallel port drivers.
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Start routine of the driver.
VOID DriverUnload(IN PDRIVER_OBJECT DriverObject)
Unload routine of the driver.
#define DBG_SUCCESS(_xxx)
VOID DriverCommonUninit(VOID)
Undo what DriverCommonInit() has done.
NTSTATUS ParPortEnumerateOpen(PENUMERATE *EnumStruct)
Start enumeration of the parallel port drivers.
const UCHAR * DebugNtStatus(NTSTATUS Value)
Return the description of an NTSTATUS code.
Definitions for the opencbm driver.
NTSTATUS ParPortDeinit(PDEVICE_EXTENSION Pdx)
Undoes anything ParPortInit has done.
VOID DbgFreeMemoryBuffer(VOID)
Free storage area for debugging output.