📄 profim.c
字号:
deviceExtension->TempIrp = Irp;
KeSynchronizeExecution( deviceExtension->InterruptObject,
ProfiM_Read, deviceExtension );
break;
}
//******************************************************************
case IOCTL_PROFIM_CANCEL_WAITING:
{
if ( inputBufferLength < 4 )
{
Irp->IoStatus.Information = 0;
break;
}
MID = * ((int *)(Irp->AssociatedIrp.SystemBuffer));
if (irpStack->FileObject)
{
DelIrp=IrpB_DeleteIrp( & deviceExtension->IrpB, ( int ) irpStack->FileObject->FsContext , MID );
PB_DbgPrintL2( "ProfiM: CANCEL_WAITING: MID=%u IRP=%u", MID, (int)DelIrp );
if (DelIrp)
{
DelIrp->IoStatus.Status = STATUS_SUCCESS;
DelIrp->IoStatus.Information = 0;
IoCompleteRequest( DelIrp, IO_NO_INCREMENT );
PB_DbgPrintL2( "ProfiM: Irp=%u canceled.", (int)DelIrp );
}
}
Irp->IoStatus.Information = 0;
break;
}
//******************************************************************
case IOCTL_PROFIM_GET_MASTER_STATE:
{
RS_DbgPrint( "ProfiM: GET_MASTER_STATE\n" );
if ( outputBufferLength >= 4 )
{
*( ULONG * ) ioBuffer = deviceExtension->PB.StationStatus;
Irp->IoStatus.Information = 4;
}
break;
}
//******************************************************************
case IOCTL_PROFIM_RESTART_MASTER:
{
RS_DbgPrint( "ProfiM: RESTART_MASTER\n" );
if ( outputBufferLength >= 4 )
{
*( ULONG * ) ioBuffer = deviceExtension->PB.StationStatus;
Irp->IoStatus.Information = 4;
}
break;
}
//******************************************************************
default:
{
PB_DbgPrintL1( "ProfiM: Unknown IRP_MJ_DEVICE_CONTROL\n" );
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
break;
}
}
break;
}
//*********************************************************************
default:
{
PB_DbgPrintL1( "ProfiM: Unhandled IRP_MJ function\n" );
Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
break;
}
}
//
// DON'T get cute and try to use the status field of
// the irp in the return status. That IRP IS GONE as
// soon as you call IoCompleteRequest.
//
ntStatus = Irp->IoStatus.Status;
if ( Irp->IoStatus.Status == STATUS_PENDING )
{
KIRQL OldIrql;
IoAcquireCancelSpinLock( &OldIrql );
IoSetCancelRoutine( Irp, &ProfiM_IrpCancel );
IoReleaseCancelSpinLock( OldIrql );
IoMarkIrpPending( Irp );
}
else
IoCompleteRequest( Irp, IO_NO_INCREMENT );
PB_DbgPrintL1( "ProfiM: DisptachRoutine exit.\n" );
return ntStatus;
}
//***************************************************************************
// GetConfiguration
//
// Description:
// Obtains driver configuration information from the Registry.
//
// Arguments:
// DeviceExtension - Pointer to the device extension.
// RegistryPath - Pointer to the null-terminated Unicode name of the
// registry path for this driver.
//
// Return Value:
// NTSTATUS
//
NTSTATUS GetConfiguration( IN PPROFIM_DEVICE_EXTENSION DeviceExtension,
IN PUNICODE_STRING RegistryPath )
{
PRTL_QUERY_REGISTRY_TABLE parameters = NULL;
UNICODE_STRING parametersPath;
ULONG notThereDefault = 1234567;
ULONG PortAddressDefault;
ULONG IRQLineDefault;
ULONG BaudRateDefault;
ULONG BufferSizeDefault;
NTSTATUS status = STATUS_SUCCESS;
PWSTR path = NULL;
USHORT queriesPlusOne = 4;
if ( !DeviceExtension )
{
DbgPrint( "ProfiM: GetConfiguration Error - DeviceExtension is NULL!" );
return STATUS_UNSUCCESSFUL;
}
if ( DeviceExtension->magic != PROFIM_MAGIC )
{
DbgPrint( "ProfiM: GetConfiguration Error - Device Extension MAGIC is invalid!" );
return STATUS_UNSUCCESSFUL;
}
parametersPath.Buffer = NULL;
//
// Registry path is already null-terminated, so just use it.
//
path = RegistryPath->Buffer;
//
// Allocate the Rtl query table.
//
parameters = ExAllocatePool( PagedPool,
sizeof( RTL_QUERY_REGISTRY_TABLE ) * queriesPlusOne );
if ( !parameters )
{
RS_DbgPrint( "ProfiM: ExAllocatePool failed for Rtl in GetConfiguration\n" );
status = STATUS_UNSUCCESSFUL;
}
else
{
RtlZeroMemory( parameters,
sizeof( RTL_QUERY_REGISTRY_TABLE ) * queriesPlusOne );
//
// Form a path to this driver's Parameters subkey.
//
RtlInitUnicodeString( ¶metersPath, NULL );
parametersPath.MaximumLength = RegistryPath->Length +
sizeof( L"\\Parameters" );
parametersPath.Buffer = ExAllocatePool( PagedPool,
parametersPath.MaximumLength );
if ( !parametersPath.Buffer )
{
RS_DbgPrint( "ProfiM: ExAllocatePool failed for Path in GetConfiguration\n" );
status = STATUS_UNSUCCESSFUL;
}
}
if ( NT_SUCCESS( status ) )
{
//
// Form the parameters path.
//
RtlZeroMemory( parametersPath.Buffer, parametersPath.MaximumLength );
RtlAppendUnicodeToString( ¶metersPath, path );
RtlAppendUnicodeToString( ¶metersPath, L"\\Parameters" );
//
// Gather all of the "user specified" information from
// the registry.
//
parameters[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[0].Name = L"Port Address";
parameters[0].EntryContext = &PortAddressDefault;
parameters[0].DefaultType = REG_DWORD;
parameters[0].DefaultData = ¬ThereDefault;
parameters[0].DefaultLength = sizeof( ULONG );
parameters[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[1].Name = L"IRQ Line";
parameters[1].EntryContext = &IRQLineDefault;
parameters[1].DefaultType = REG_DWORD;
parameters[1].DefaultData = ¬ThereDefault;
parameters[1].DefaultLength = sizeof( ULONG );
parameters[2].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[2].Name = L"Baud Rate";
parameters[2].EntryContext = &BaudRateDefault;
parameters[2].DefaultType = REG_DWORD;
parameters[2].DefaultData = ¬ThereDefault;
parameters[2].DefaultLength = sizeof( ULONG );
/*
parameters[3].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[3].Name = L"Buffer Size";
parameters[3].EntryContext = &BufferSizeDefault;
parameters[3].DefaultType = REG_DWORD;
parameters[3].DefaultData = ¬ThereDefault;
parameters[3].DefaultLength = sizeof( ULONG );
*/
status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE |
RTL_REGISTRY_OPTIONAL,
parametersPath.Buffer,
parameters,
NULL,
NULL );
if ( !NT_SUCCESS( status ) )
{
RS_DbgPrint( "ProfiM: RtlQueryRegistryValues failed\n" );
}
status = STATUS_SUCCESS;
}
//
// Go ahead and assign driver defaults.
//
if ( PortAddressDefault == notThereDefault )
{
DeviceExtension->PortAddress = ( PUCHAR ) DEF_PORT_ADDRESS;
}
else
{
DeviceExtension->PortAddress = ( PVOID ) PortAddressDefault;
}
if ( IRQLineDefault == notThereDefault )
{
DeviceExtension->IRQLine = DEF_IRQ_LINE;
}
else
{
DeviceExtension->IRQLine = ( KIRQL ) IRQLineDefault;
}
if ( BaudRateDefault == notThereDefault )
{
DeviceExtension->BaudRate = DEF_BAUD_RATE;
}
else
{
DeviceExtension->BaudRate = BaudRateDefault;
}
/* if ( BufferSizeDefault == notThereDefault )
{*/
DeviceExtension->BufferSize = DEF_BUFFER_SIZE;
/* }
else
{
DeviceExtension->BufferSize = BufferSizeDefault;
}*/
DbgPrint( "ProfiM: GetConfiguration - BufferSize=%d",
DeviceExtension->BufferSize );
if ( DeviceExtension->BufferSize == 0 )
{
DbgPrint( "ProfiM: Error BufferSize can't be null!" );
return STATUS_UNSUCCESSFUL;
}
DbgPrint( "ProfiM: GetConfiguration - BaudRate=%d",
DeviceExtension->BaudRate );
//
// Free the allocated memory before returning.
//
if ( parametersPath.Buffer )
ExFreePool( parametersPath.Buffer );
if ( parameters )
ExFreePool( parameters );
return ( status );
}
//***************************************************************************
// GetPnPConfiguration
//
// Description:
// Obtains driver configuration information from the Registry in PnP
// mode.
//
// Arguments:
// DeviceExtension - Pointer to the device extension.
//
// Return Value:
// NTSTATUS
//
#ifdef PnP
NTSTATUS GetPnPConfiguration( IN PPROFIM_DEVICE_EXTENSION DeviceExtension)
{
NTSTATUS status = STATUS_SUCCESS;
int i;
int BR;
HANDLE regKeyHandle;
ULONG Data;
NTSTATUS code;
if ( !DeviceExtension )
{
DbgPrint( "ProfiM: GetConfiguration Error - DeviceExtension is NULL!" );
return STATUS_UNSUCCESSFUL;
}
if ( DeviceExtension->magic != PROFIM_MAGIC )
{
DbgPrint( "ProfiM: GetConfiguration Error - Device Extension MAGIC is invalid!" );
return STATUS_UNSUCCESSFUL;
}
//
// Read values from registry
//
code = IoOpenDeviceRegistryKey( DeviceExtension->PhysicalDeviceObject,
PLUGPLAY_REGKEY_DEVICE,
STANDARD_RIGHTS_WRITE,
®KeyHandle );
if ( NT_SUCCESS( code ) )
{
/*
if ( GetRegistryDWord ( regKeyHandle, L"Port Address", &Data) )
DeviceExtension->PortAddress = ( PUCHAR ) Data;
else
DeviceExtension->PortAddress = ( PUCHAR ) DEF_PORT_ADDRESS;
if ( GetRegistryDWord ( regKeyHandle, L"IRQ Line", &Data) )
DeviceExtension->IRQLine = ( KIRQL ) Data;
else
DeviceExtension->IRQLine = ( KIRQL ) DEF_IRQ_LINE;
*/
if ( GetRegistryDWord ( regKeyHandle, L"Baud Rate", &Data) )
DeviceExtension->BaudRate = Data;
else
DeviceExtension->BaudRate = DEF_BAUD_RATE;
/*
if ( GetRegistryDWord ( regKeyHandle, L"Buffer Size", &Data) )
DeviceExtension->BufferSize = Data;
else
*/
DeviceExtension->BufferSize = DEF_BUFFER_SIZE;
ZwClose( regKeyHandle );
}
DbgPrint( "ProfiM: GetPnPConfiguration - BufferSize=%d",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -