[an error occurred while processing this directive]
|
Примерно так. Только это кусок из драйвера-фильтра нижнего уровня. И тут не прописывается CMD, но аналогично. И тут порты, а не память. И делаются специфические проверки на адреса, так как предварительно ресурс-лист отдавался через IRP_MN_QUERY_RESOURCE_REQUIREMENTS и фильтровался по IRP_MN_FILTER_RESOURCE_REQUIREMENTS, и наложение масок, такое как тут, корректно.
case IRP_MN_START_DEVICE:
ResourceList = IrpSp->Parameters.StartDevice.AllocatedResources;
if (ResourceList) {
FullResourceDescriptor = &ResourceList->List[0];
if( FullResourceDescriptor ) {
deviceExtension->InterfaceType = FullResourceDescriptor->InterfaceType;
PartialResourceList = &FullResourceDescriptor->PartialResourceList;
for (i = 0; i < PartialResourceList->Count; i++) {
PartialResourceDescriptor = &PartialResourceList->PartialDescriptors[i];
switch (PartialResourceDescriptor->Type) {
case CmResourceTypePort:
length = PartialResourceDescriptor->u.Port.Length;
switch( length ) {
case 4: // EMU510PCI - LPT
deviceExtension->ports[0] = (ULONG)PartialResourceDescriptor->u.Port.Start.QuadPart;
break;
case 0x20:
switch ( ((ULONG)PartialResourceDescriptor->u.Port.Start.QuadPart) & 0xC00) {
case 0x000:
deviceExtension->ports[1] = (ULONG)PartialResourceDescriptor->u.Port.Start.QuadPart;
break;
case 0x400:
deviceExtension->ports[2] = (ULONG)PartialResourceDescriptor->u.Port.Start.QuadPart;
break;
case 0x800:
deviceExtension->ports[3] = (ULONG)PartialResourceDescriptor->u.Port.Start.QuadPart;
break;
default:
break;
}
}
break;
case CmResourceTypeBusNumber:
deviceExtension->BusNumber = PartialResourceDescriptor->u.BusNumber.Start;
break;
default:
break;
} // end switch( PartialResourceDescriptor->Type )
} // end for(... ; i < PartialResourceList->Count ; ...)
} // end if( FullResourceDescriptor )
}SetDeviceParameterBin(deviceExtension->NextLowerDriver,(PWSTR)L"DebugConfigM",(PULONG)deviceExtension->ports,16);
flag=TRUE;
for (i=0; i < 4; i++) if (!deviceExtension->ports[i]) flag=FALSE;if (flag) {
KeInitializeEvent( &event, NotificationEvent, FALSE );irp1 = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
deviceExtension->NextLowerDriver,
NULL,
0,
NULL,
&event,
&ioStatusBlock );if (irp1 == NULL) {
status = STATUS_INSUFFICIENT_RESOURCES;
goto targetExit;
}
pBuf=ExAllocatePool(NonPagedPool,16);if (!pBuf) {
status = STATUS_INSUFFICIENT_RESOURCES;
goto targetExit;
}pBuf[0]=(ULONG)deviceExtension->ports[0];
pBuf[1]=(ULONG)deviceExtension->ports[1];
pBuf[2]=(ULONG)deviceExtension->ports[2];
pBuf[3]=(ULONG)deviceExtension->ports[3];
irpStack = IoGetNextIrpStackLocation( irp1 );
irpStack->MajorFunction = IRP_MJ_PNP;
irpStack->MinorFunction = IRP_MN_WRITE_CONFIG;
irpStack->Parameters.ReadWriteConfig.WhichSpace = PCI_WHICHSPACE_CONFIG;
irpStack->Parameters.ReadWriteConfig.Buffer = pBuf;
irpStack->Parameters.ReadWriteConfig.Offset = 0x10; // 0x10 - bar0
irpStack->Parameters.ReadWriteConfig.Length = 0x10; // 4*4 bytes// Initialize the status to error in case the bus driver does not
// set it correctly.
irp1->IoStatus.Status = STATUS_NOT_SUPPORTED ;
status = IoCallDriver(deviceExtension->NextLowerDriver , irp1 );
if (status == STATUS_PENDING) {
KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL );
status = ioStatusBlock.Status;
}
ExFreePool(pBuf);if( !NT_SUCCESS( status ) ) {
goto targetExit;
}
E-mail: info@telesys.ru