53 AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PdoUNUSED, IN PCWSTR ParallelPortName)
56 UNICODE_STRING deviceNameNumber;
57 UNICODE_STRING deviceNamePrefix;
58 UNICODE_STRING deviceName;
60 WCHAR deviceNameNumberBuffer[50];
67 UNREFERENCED_PARAMETER(PdoUNUSED);
71 ntStatus = STATUS_SUCCESS;
76 DBG_IRQL( <= DISPATCH_LEVEL);
77 RtlInitUnicodeString(&deviceNamePrefix, CBMDEVICENAME);
81 deviceNameNumber.Length = 0;
82 deviceNameNumber.MaximumLength =
sizeof(deviceNameNumberBuffer);
83 deviceNameNumber.Buffer = deviceNameNumberBuffer;
84 DBG_IRQL( == PASSIVE_LEVEL);
85 RtlIntegerToUnicodeString(no, 10, &deviceNameNumber);
94 deviceName.MaximumLength = deviceNamePrefix.Length + deviceNameNumber.Length;
95 deviceName.Buffer = (PWCHAR) ExAllocatePoolWithTag(NonPagedPool,
98 if (!deviceName.Buffer)
100 ntStatus = STATUS_INSUFFICIENT_RESOURCES;
102 LogErrorString(NULL, CBM_START_FAILED, L
"allocating memory for device name", NULL);
105 if (NT_SUCCESS(ntStatus))
109 DBG_IRQL( < DISPATCH_LEVEL);
110 RtlCopyUnicodeString(&deviceName, &deviceNamePrefix);
111 DBG_IRQL( < DISPATCH_LEVEL);
112 RtlAppendUnicodeStringToString(&deviceName, &deviceNameNumber);
116 DBG_IRQL( == PASSIVE_LEVEL);
117 ntStatus = IoCreateDevice(DriverObject,
sizeof(
DEVICE_EXTENSION), &deviceName,
118 FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, TRUE, &fdo);
120 if (!NT_SUCCESS(ntStatus))
124 LogErrorString(NULL, CBM_START_FAILED, L
"creation of the device object", NULL);
128 if (NT_SUCCESS(ntStatus))
135 if (!NT_SUCCESS(ntStatus))
137 PDEVICE_EXTENSION pdx;
143 pdx = fdo->DeviceExtension;
147 if (pdx->DeviceName.Buffer)
149 DBG_IRQL( < DISPATCH_LEVEL);
150 ExFreePool(pdx->DeviceName.Buffer);
153 DBG_IRQL( == PASSIVE_LEVEL);
178 PDEVICE_EXTENSION pdx = fdo->DeviceExtension;
184 FUNC_LEAVE_NTSTATUS(ntStatus);
187 static KMUTEX MutexDriverLoadUnload;
204 PDEVICE_OBJECT currentDevice;
210 DBG_IRQL( < DISPATCH_LEVEL);
211 KeWaitForMutexObject(&MutexDriverLoadUnload, Executive, KernelMode,
216 while (currentDevice = DriverObject->DeviceObject)
218 PDEVICE_EXTENSION pdx = currentDevice->DeviceExtension;
224 if (pdx->ParallelPortIsLocked)
240 if (pdx->DeviceName.Buffer)
242 DBG_IRQL( < DISPATCH_LEVEL);
243 ExFreePool(pdx->DeviceName.Buffer);
250 DBG_IRQL( == PASSIVE_LEVEL);
251 IoDeleteDevice(currentDevice);
266 DBG_IRQL( <= DISPATCH_LEVEL);
267 KeReleaseMutex(&MutexDriverLoadUnload, FALSE);
295 DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
308 KeInitializeMutex(&MutexDriverLoadUnload, 0);
312 DBG_IRQL( < DISPATCH_LEVEL);
313 KeWaitForMutexObject(&MutexDriverLoadUnload, Executive, KernelMode,
338 if (NT_SUCCESS(ntStatus))
346 if (NT_SUCCESS(ntStatus) && *DriverName)
349 AddDevice(DriverObject, NULL, DriverName);
351 }
while (NT_SUCCESS(ntStatus) && *DriverName);
358 DBG_IRQL( <= DISPATCH_LEVEL);
359 KeReleaseMutex(&MutexDriverLoadUnload, FALSE);
361 FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
VOID DriverUnload(IN PDRIVER_OBJECT DriverObject)
Unload routine of the driver.
#define LogErrorString(_Fdo_, _UniqueErrorValue_, _String1_, _String2_)
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 AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PdoUNUSED, IN PCWSTR ParallelPortName)
create functional device object (FDO) for enumerated device
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.
#define DBG_SUCCESS(_xxx)
VOID cbm_init_registry(IN PUNICODE_STRING RegistryPath, IN PDEVICE_EXTENSION Pdx)
Initialize from registry.
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.
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Start routine of the driver.
VOID DbgFreeMemoryBuffer(VOID)
Free storage area for debugging output.