00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00020 #include <wdm.h>
00021 #include "cbm_driver.h"
00022 #include "iec.h"
00023
00027 static UNICODE_STRING ServiceKeyRegistryPath;
00028
00055 VOID
00056 cbm_init_registry(IN PUNICODE_STRING RegistryPath, IN PDEVICE_EXTENSION Pdx)
00057 {
00058 NTSTATUS ntStatus;
00059
00060 FUNC_ENTER();
00061
00062 ntStatus = STATUS_SUCCESS;
00063
00064 if (RegistryPath)
00065 {
00066
00067
00068 DBG_ASSERT(ServiceKeyRegistryPath.Buffer == 0);
00069
00070
00071
00072 ServiceKeyRegistryPath.Buffer = ExAllocatePoolWithTag(PagedPool,
00073 RegistryPath->Length, MTAG_SERVKEY);
00074
00075
00076
00077 if (ServiceKeyRegistryPath.Buffer)
00078 {
00079 ServiceKeyRegistryPath.MaximumLength =
00080 ServiceKeyRegistryPath.Length = RegistryPath->Length;
00081
00082 RtlCopyUnicodeString(&ServiceKeyRegistryPath, RegistryPath);
00083 }
00084 else
00085 {
00086
00087
00088
00089 ServiceKeyRegistryPath.MaximumLength =
00090 ServiceKeyRegistryPath.Length = 0;
00091 }
00092 }
00093
00094
00095
00096 if (ServiceKeyRegistryPath.Length != 0 && ServiceKeyRegistryPath.Buffer != NULL)
00097 {
00098 HANDLE hKey;
00099
00100
00101
00102 ntStatus = cbm_registry_open_for_read(&hKey, &ServiceKeyRegistryPath);
00103
00104 if (NT_SUCCESS(ntStatus))
00105 {
00106
00107
00108 ULONG iecCable = IEC_CABLETYPE_AUTO;
00109
00110 #if DBG
00111
00112
00113
00114 cbm_registry_read_ulong(hKey, L"DebugFlags", &DbgFlags);
00115
00116 #endif // #if DBG
00117
00118 if (Pdx)
00119 {
00120
00121
00122
00123
00124 cbm_registry_read_ulong(hKey, L"CableType", &iecCable);
00125
00126 cbmiec_set_cabletype(Pdx, iecCable);
00127
00128
00129
00130
00131
00132 iecCable = 1;
00133 cbm_registry_read_ulong(hKey, L"PermanentlyLock", &iecCable);
00134 Pdx->ParallelPortLock = iecCable ? TRUE : FALSE;
00135
00136 }
00137
00138
00139
00140 cbmiec_global_init(&hKey);
00141
00142
00143
00144 cbm_registry_close(hKey);
00145 }
00146 else
00147 {
00148
00149
00150
00151 cbmiec_global_init(NULL);
00152 }
00153 }
00154 else
00155 {
00156
00157
00158
00159 cbmiec_global_init(NULL);
00160 }
00161
00162
00163
00164
00165
00166 if (Pdx && Pdx->ParallelPortLock && Pdx->ParallelPortIsLocked == FALSE)
00167 {
00168 cbm_lock_parport(Pdx);
00169 }
00170
00171 FUNC_LEAVE();
00172 }
00173
00190 NTSTATUS
00191 DriverCommonInit(IN PDRIVER_OBJECT Driverobject, IN PUNICODE_STRING RegistryPath)
00192 {
00193 FUNC_ENTER();
00194
00195
00196
00197 PERF_INIT();
00198
00199
00200
00201 cbm_init_registry(RegistryPath, NULL);
00202
00203
00204
00205 Driverobject->DriverUnload = DriverUnload;
00206 Driverobject->MajorFunction[IRP_MJ_CREATE] = cbm_createopenclose;
00207 Driverobject->MajorFunction[IRP_MJ_CLOSE] = cbm_createopenclose;
00208 Driverobject->MajorFunction[IRP_MJ_CLEANUP] = cbm_cleanup;
00209 Driverobject->MajorFunction[IRP_MJ_READ] = cbm_readwrite;
00210 Driverobject->MajorFunction[IRP_MJ_WRITE] = cbm_readwrite;
00211 Driverobject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = cbm_devicecontrol;
00212
00213 FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
00214 }
00215
00223 VOID
00224 DriverCommonUninit(VOID)
00225 {
00226 FUNC_ENTER();
00227
00228
00229
00230 PERF_SAVE();
00231
00232
00233
00234
00235 if (ServiceKeyRegistryPath.Buffer)
00236 {
00237 ExFreePool(ServiceKeyRegistryPath.Buffer);
00238 DBGDO(ServiceKeyRegistryPath.Buffer = NULL;
00239 ServiceKeyRegistryPath.MaximumLength = ServiceKeyRegistryPath.Length = 0);
00240 }
00241
00242 FUNC_LEAVE();
00243 }
00244
00276 NTSTATUS
00277 AddDeviceCommonInit(IN PDEVICE_OBJECT Fdo, IN PUNICODE_STRING DeviceName,
00278 IN PCWSTR ParallelPortName)
00279 {
00280 PDEVICE_EXTENSION pdx;
00281 UNICODE_STRING parallelPortName;
00282 NTSTATUS ntStatus;
00283
00284 FUNC_ENTER();
00285
00286
00287
00288 pdx = Fdo->DeviceExtension;
00289
00290
00291
00292 RtlZeroMemory(pdx, sizeof(*pdx));
00293
00294
00295
00296 pdx->DeviceName.Buffer = DeviceName->Buffer;
00297 pdx->DeviceName.Length = DeviceName->Length;
00298 pdx->DeviceName.MaximumLength = DeviceName->MaximumLength;
00299
00300
00301
00302 pdx->Fdo = Fdo;
00303
00304
00305
00306 QueueInit(&pdx->IrpQueue, cbm_startio);
00307
00308
00309
00310
00311
00312 Fdo->Flags |= DO_BUFFERED_IO;
00313
00314
00315
00316
00317 parallelPortName.Buffer = (PWSTR) ParallelPortName;
00318 parallelPortName.Length = (USHORT) wcslen(ParallelPortName) * sizeof(WCHAR);
00319 parallelPortName.MaximumLength = parallelPortName.Length;
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 pdx->IsSMP = (CbmGetNumberProcessors() > 1) ? TRUE : FALSE;
00333
00334
00335
00336 ntStatus = ParPortInit(¶llelPortName, pdx);
00337
00338 if (!NT_SUCCESS(ntStatus))
00339 {
00340 DBG_ERROR((DBG_PREFIX "ParPortInit() FAILED, deleting device"));
00341 LogErrorString(Fdo, CBM_START_FAILED, L"initialization of the parallel port.", NULL);
00342 }
00343
00344
00345
00346 if (NT_SUCCESS(ntStatus))
00347 {
00348 ntStatus = cbm_start_thread(pdx);
00349 }
00350
00351
00352
00353
00354 if (NT_SUCCESS(ntStatus))
00355 {
00356 LogErrorOnly(Fdo, CBM_STARTED);
00357 }
00358
00359 FUNC_LEAVE_NTSTATUS(ntStatus);
00360 }