Hi. I have developed my first filter driver for SerialPort, and I need to obtain data about the port settings via IRP. The driver has functions like DriverEntry and Unload LogDataFile, and it works perfectly. However, after I added the AddDevice function, I noticed through the log that AddDevice is not loading, and this has caused the Unload function to stop working.
here you can see prt of my code from inf and c files
**From inf file **
[Version]
Signature = “$WINDOWS NT$”
Class = “Ports”
ClassGuid = {4d36e978-e325-11ce-bfc1-08002be10318}
Standard]
%MyPortMonitor.DeviceDesc%=MyPortMonitor_Device, *PNP0501
[MyPortMonitor_Device.NT]
CopyFiles=Drivers_Dir
[MyPortMonitor_Device.NT.HW]
AddReg=MyPortMonitor_UpperFilters_AddReg
[MyPortMonitor_UpperFilters_AddReg]
HKR,“UpperFilters”,0x00010008,“MyPortMonitor”
[MyPortMonitor_Device.NT.AddReg]
HKR,DeviceCharacteristics,0x10001,0x0100 ; Use same security checks on relative opens
HKR,Security,“D:P(A;;GA;;;BA)(A;;GA;;;SY)” ; Allow generic-all access to Built-in administrators and Local system
From mydriverMonitor.c
NTSTATUS AddDevices(PDRIVER_OBJECT DriverObject, In PDEVICE_OBJECT PhysicalDeviceObject)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_OBJECT myFilterDeviceObject = NULL;
KdPrint((“Entering AddDevices\n”));
// Logging the entry into the function.
WriteStringLogFile("Entering AddDevices\r\n");
// Create a filter device object for the detected COM port.
status = IoCreateDevice(
DriverObject,
0, // Set to 0 since we're not using a device extension.
NULL, // No name for the filter device object.
FILE_DEVICE_SERIAL_PORT,
0,
FALSE,
&myFilterDeviceObject);
if (!NT_SUCCESS(status))
{
KdPrint(("Error creating device object for COM port: %08x\n", status));
WriteStringLogFile("Error creating device object for COM port\r\n");
return status;
}
// Attach filter to the device stack
myFilterDeviceObject->NextDevice = IoAttachDeviceToDeviceStack(
myFilterDeviceObject,
PhysicalDeviceObject
);
if (!myFilterDeviceObject->NextDevice)
{
IoDeleteDevice(myFilterDeviceObject);
KdPrint(("Failed to attach to device stack\n"));
WriteStringLogFile("Failed to attach to device stack\r\n");
return STATUS_UNSUCCESSFUL;
}
// Set the flags inherited from the lower device object
myFilterDeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
myFilterDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
// Log success message
KdPrint(("COM port device added successfully\n"));
WriteStringLogFile("COM port device added successfully\r\n");*/
return STATUS_SUCCESS;
}
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_OBJECT deviceObject = NULL;
UNICODE_STRING comPortNames[MAX_COM_PORTS];
UNICODE_STRING comPortDevicePaths[MAX_COM_PORTS];
ULONG numPortsFound = 0;
PDEVICE_OBJECT myDeviceObject = NULL;
KdPrint(("LOAD SUCCESS \r\n"));
WriteStringLogFile("LOAD SUCCESS\r\n");
KIRQL currentIrql = KeGetCurrentIrql();
if (currentIrql == PASSIVE_LEVEL)
{
// The current IRQL is PASSIVE_LEVEL
KdPrint(("Current IRQL is PASSIVE_LEVEL\n"));
WriteStringLogFile("Current IRQL is PASSIVE_LEVE\r\n");
}
else
{
// The current IRQL is not PASSIVE_LEVEL
KdPrint(("Current IRQL is NOT PASSIVE_LEVEL, it is %d\n", currentIrql));
WriteULongLogFIle("Current IRQL is NOT PASSIVE_LEVEL, it is: ", (ULONG)currentIrql);
}
DriverObject->DriverUnload = UnloadDriver;
DriverObject->DriverExtension->AddDevice = AddDevices;
DriverObject->MajorFunction[IRP_MJ_CREATE] = MySerialPortCreate;
Thank you in advance for your help.
Boris .