NTSTATUS PdoQueryId(PDEVICE_OBJECT DeviceObject, PIRP Irp, ULONG_PTR* Information) { WCHAR Buffer[256]; ULONG Index = 0; ULONG IdType; UNICODE_STRING SourceString; UNICODE_STRING String; NTSTATUS Status; IdType = IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryId.IdType; switch (IdType) { case BusQueryDeviceID: { RtlInitUnicodeString(&SourceString, L"USB\\ROOT_HUB20"); break; } case BusQueryHardwareIDs: { /* FIXME: Build from Device Vendor and Device ID */ Index += swprintf(&Buffer[Index], L"USB\\ROOT_HUB20&VID8086&PID265C&REV0000") + 1; Index += swprintf(&Buffer[Index], L"USB\\ROOT_HUB20&VID8086&PID265C") + 1; Index += swprintf(&Buffer[Index], L"USB\\ROOT_HUB20") + 1; Buffer[Index] = UNICODE_NULL; SourceString.Length = SourceString.MaximumLength = Index * sizeof(WCHAR); SourceString.Buffer = Buffer; break; } case BusQueryCompatibleIDs: { /* We have none */ return STATUS_SUCCESS; } case BusQueryInstanceID: { return STATUS_SUCCESS; } default: { DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_ID / unknown query id type 0x%lx\n", IdType); return STATUS_NOT_SUPPORTED; } } Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, &SourceString, &String); *Information = (ULONG_PTR)String.Buffer; return Status; }
static NTSTATUS PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs) { WCHAR Buffer[256]; UNICODE_STRING BufferU; ULONG Index; Index = 0; Index += swprintf(&Buffer[Index], L"GenFloppyDisk"); Index++; Buffer[Index] = UNICODE_NULL; BufferU.Length = BufferU.MaximumLength = (USHORT)Index * sizeof(WCHAR); BufferU.Buffer = Buffer; return DuplicateUnicodeString(0, &BufferU, CompatibleIDs); }
static NTSTATUS PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs) { WCHAR Buffer[256]; UNICODE_STRING BufferU; ULONG Index; Index = 0; Index += swprintf(&Buffer[Index], L"FDC\\GENERIC_FLOPPY_DRIVE"); Index++; Buffer[Index] = UNICODE_NULL; BufferU.Length = BufferU.MaximumLength = (USHORT) Index * sizeof(WCHAR); BufferU.Buffer = Buffer; return DuplicateUnicodeString(0, &BufferU, HardwareIDs); }
NTSTATUS NTAPI DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { PI8042_DRIVER_EXTENSION DriverExtension; ULONG i; NTSTATUS Status; /* ROS Hack: ideally, we shouldn't have to initialize debug level this way, but since the only way is to change it via KDBG, it's better to leave it here too. */ #if 0 DbgSetDebugFilterState( DPFLTR_I8042PRT_ID, (1 << DPFLTR_ERROR_LEVEL) | (1 << DPFLTR_WARNING_LEVEL) | (1 << DPFLTR_TRACE_LEVEL) /*| (1 << DPFLTR_INFO_LEVEL)*/ | DPFLTR_MASK, TRUE); #endif Status = IoAllocateDriverObjectExtension( DriverObject, DriverObject, sizeof(I8042_DRIVER_EXTENSION), (PVOID*)&DriverExtension); if (!NT_SUCCESS(Status)) { WARN_(I8042PRT, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status); return Status; } RtlZeroMemory(DriverExtension, sizeof(I8042_DRIVER_EXTENSION)); KeInitializeSpinLock(&DriverExtension->Port.SpinLock); InitializeListHead(&DriverExtension->DeviceListHead); KeInitializeSpinLock(&DriverExtension->DeviceListLock); Status = DuplicateUnicodeString( RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, RegistryPath, &DriverExtension->RegistryPath); if (!NT_SUCCESS(Status)) { WARN_(I8042PRT, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status); return Status; } Status = ReadRegistryEntries(RegistryPath, &DriverExtension->Port.Settings); if (!NT_SUCCESS(Status)) { WARN_(I8042PRT, "ReadRegistryEntries() failed with status 0x%08lx\n", Status); return Status; } DriverObject->DriverExtension->AddDevice = i8042AddDevice; DriverObject->DriverStartIo = i8042StartIo; for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) DriverObject->MajorFunction[i] = IrpStub; DriverObject->MajorFunction[IRP_MJ_CREATE] = i8042Create; DriverObject->MajorFunction[IRP_MJ_CLEANUP] = i8042Cleanup; DriverObject->MajorFunction[IRP_MJ_CLOSE] = i8042Close; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = i8042DeviceControl; DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = i8042InternalDeviceControl; DriverObject->MajorFunction[IRP_MJ_PNP] = i8042Pnp; if (IsFirstStageSetup()) return i8042AddLegacyKeyboard(DriverObject, RegistryPath); return STATUS_SUCCESS; }
static NTSTATUS ReportDetectedDevice( IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING DeviceDescription, IN PUNICODE_STRING DeviceId, IN PUNICODE_STRING InstanceId, IN PUNICODE_STRING HardwareIds, IN PUNICODE_STRING CompatibleIds) { PDEVICE_OBJECT Pdo = NULL; PPDO_DEVICE_EXTENSION PdoDeviceExtension = NULL; PFDO_DEVICE_EXTENSION FdoDeviceExtension; NTSTATUS Status; TRACE_(SERENUM, "ReportDetectedDevice() called with %wZ (%wZ) detected\n", DeviceId, DeviceDescription); Status = IoCreateDevice( DeviceObject->DriverObject, sizeof(PDO_DEVICE_EXTENSION), NULL, FILE_DEVICE_CONTROLLER, FILE_AUTOGENERATED_DEVICE_NAME, FALSE, &Pdo); if (!NT_SUCCESS(Status)) goto ByeBye; Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE; Pdo->Flags |= DO_POWER_PAGABLE; PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)Pdo->DeviceExtension; FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; RtlZeroMemory(PdoDeviceExtension, sizeof(PDO_DEVICE_EXTENSION)); PdoDeviceExtension->Common.IsFDO = FALSE; Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, DeviceDescription, &PdoDeviceExtension->DeviceDescription); if (!NT_SUCCESS(Status)) goto ByeBye; Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, DeviceId, &PdoDeviceExtension->DeviceId); if (!NT_SUCCESS(Status)) goto ByeBye; Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, InstanceId, &PdoDeviceExtension->InstanceId); if (!NT_SUCCESS(Status)) goto ByeBye; Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, HardwareIds, &PdoDeviceExtension->HardwareIds); if (!NT_SUCCESS(Status)) goto ByeBye; Status = DuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, CompatibleIds, &PdoDeviceExtension->CompatibleIds); if (!NT_SUCCESS(Status)) goto ByeBye; /* Device attached to serial port (Pdo) may delegate work to * serial port stack (Fdo = DeviceObject variable) */ Pdo->StackSize = DeviceObject->StackSize + 1; FdoDeviceExtension->AttachedPdo = Pdo; PdoDeviceExtension->AttachedFdo = DeviceObject; Pdo->Flags |= DO_BUFFERED_IO; Pdo->Flags &= ~DO_DEVICE_INITIALIZING; return STATUS_SUCCESS; ByeBye: if (Pdo) { ASSERT(PdoDeviceExtension); if (PdoDeviceExtension->DeviceDescription.Buffer) RtlFreeUnicodeString(&PdoDeviceExtension->DeviceDescription); if (PdoDeviceExtension->DeviceId.Buffer) RtlFreeUnicodeString(&PdoDeviceExtension->DeviceId); if (PdoDeviceExtension->InstanceId.Buffer) RtlFreeUnicodeString(&PdoDeviceExtension->InstanceId); if (PdoDeviceExtension->HardwareIds.Buffer) RtlFreeUnicodeString(&PdoDeviceExtension->HardwareIds); if (PdoDeviceExtension->CompatibleIds.Buffer) RtlFreeUnicodeString(&PdoDeviceExtension->CompatibleIds); IoDeleteDevice(Pdo); } return Status; }
PWSTR GetHelpFileName( HANDLE hPrinter, HANDLE hheap ) /*++ Routine Description: Return a string which contains the driver's help filename Arguments: hPrinter - Handle to the printer hheap - Handle to a heap from which to allocate memory Return Value: Pointer to the driver help filename, NULL if there is an error --*/ { static WCHAR HelpFileName[] = L"\\XLDRV.HLP"; PDRIVER_INFO_3 pDriverInfo3 = NULL; PWSTR pHelpFile = NULL; PWSTR pDriverDirectory; // // Attempt to get help file name using the new DRIVER_INFO_3 // if ((pDriverInfo3 = MyGetPrinterDriver(hPrinter, 3)) && pDriverInfo3->pHelpFile) pHelpFile = DuplicateUnicodeString(pDriverInfo3->pHelpFile, hheap); MemFree(pDriverInfo3); if (pHelpFile) return pHelpFile; // // If DRIVER_INFO_3 isn't supported, generate help file name by // concatenating the driver directory with hardcoded help filename. // if (pDriverDirectory = MyGetPrinterDriverDirectory(NULL, 1)) { INT size = sizeof(HelpFileName) + sizeof(WCHAR) * (wcslen(pDriverDirectory) + 1); if (pHelpFile = HeapAlloc(hheap, 0, size)) { wcscpy(pHelpFile, pDriverDirectory); wcscat(pHelpFile, HelpFileName); } MemFree(pDriverDirectory); } return pHelpFile; }
PUIDATA FillUiData( HANDLE hPrinter, PDEVMODE pdmInput, INT caller ) /*++ Routine Description: Fill in the global data structure used by the driver user interface Arguments: hPrinter - Handle to the printer pdmInput - Pointer to input devmode, NULL if there is none caller - Identifier who the caller is Return Value: Pointer to UIDATA structure, NULL if there is an error --*/ { PRINTER_INFO_2 *pPrinterInfo2 = NULL; PUIDATA pUiData = NULL; HANDLE hheap = NULL; DWORD cbNeeded; // // Create a heap to manage memory // Allocate memory to hold UIDATA structure // Load printer description data // Retrieve printer properties data from registry // Get printer info from the spooler // Copy the driver name // if (! (hheap = HeapCreate(0, 4096, 0)) || ! (pUiData = HeapAlloc(hheap, HEAP_ZERO_MEMORY, sizeof(UIDATA))) || ! (pUiData->pmpd = LoadMpdFile(hPrinter)) || ! GetPrinterProperties(&pUiData->prnprop, hPrinter, pUiData->pmpd) || ! (pPrinterInfo2 = MyGetPrinter(hPrinter, 2)) || ! (pUiData->pDriverName = DuplicateUnicodeString(pPrinterInfo2->pDriverName, hheap))) { if (pUiData && pUiData->pmpd) UnloadMpdFile(pUiData->pmpd); if (hheap) HeapDestroy(hheap); MemFree(pPrinterInfo2); return NULL; } pUiData->hPrinter = hPrinter; pUiData->hheap = hheap; pUiData->signature = DRIVER_SIGNATURE; // // Add printer-specific forms to the global forms database // if (! AddDriverForms(hPrinter, pUiData->pmpd)) { Error(("Failed to add printer-specific forms\n")); } // // If we're doing document properties, combine input devmode with defaults // if (caller == DOCPROPDLG) { FORM_INFO_1 formInfo; WCHAR formName[CCHFORMNAME]; // // Start with driver default devmode // DriverDefaultDevmode(&pUiData->devmode, NULL, pUiData->pmpd); // // Merge with system defaults and the input devmode // if (! MergeDevmode(&pUiData->devmode, pPrinterInfo2->pDevMode, pUiData->pmpd)) { Error(("Invalid system default devmode\n")); } if (! MergeDevmode(&pUiData->devmode, pdmInput, pUiData->pmpd)) { Error(("Invalid input devmode\n")); } // // Validate the form requested by the input devmode // if (! ValidDevmodeForm(hPrinter, &pUiData->devmode.dmPublic, &formInfo, formName)) { Error(("Invalid form requested\n")); } // // Convert public devmode fields to printer feature selections // DevmodeFieldsToOptions(&pUiData->devmode, pUiData->devmode.dmPublic.dmFields, pUiData->pmpd); // // Look for conflicts between feature selections // CombineDocumentAndPrinterFeatureSelections(pUiData->pmpd, pUiData->devmode.dmPrivate.options, pUiData->devmode.dmPrivate.options, pUiData->prnprop.options); } MemFree(pPrinterInfo2); return pUiData; }