isochapi.c
来自「winddk src目录下的WDM源码压缩!」· C语言 代码 · 共 1,981 行 · 第 1/5 页
C
1,981 行
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ISOCH_FREE_BANDWIDTH;
pIrb->Flags = 0;
pIrb->u.IsochFreeBandwidth.hBandwidth = hBandwidth;
//
// If we allocated this irp, submit it asynchronously and wait for its
// completion event to be signaled. Otherwise submit it synchronously
//
if (allocNewIrp) {
KeInitializeEvent (&Event, NotificationEvent, FALSE);
ntStatus = t1394_SubmitIrpAsync (deviceExtension->StackDeviceObject, newIrp, pIrb);
if (ntStatus == STATUS_PENDING) {
KeWaitForSingleObject (&Event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
}
}
else {
ntStatus = t1394_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, pIrb);
}
if (!NT_SUCCESS(ntStatus)) {
TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
}
Exit_IsochFreeBandwidth:
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_IsochFreeBandwidth", ntStatus);
return(ntStatus);
} // t1394_IsochFreeBandwidth
NTSTATUS
t1394_IsochFreeChannel(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN ULONG nChannel
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIRB pIrb = NULL;
PIRP newIrp = NULL;
BOOLEAN allocNewIrp = FALSE;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
ENTER("t1394_IsochFreeChannel");
TRACE(TL_TRACE, ("nChannel = 0x%x\n", nChannel));
//
// If this is a UserMode request create a newIrp so that the request
// will be issued from KernelMode
//
if (Irp->RequestorMode == UserMode) {
newIrp = IoBuildDeviceIoControlRequest (IOCTL_1394_CLASS, deviceExtension->StackDeviceObject,
NULL, 0, NULL, 0, TRUE, &Event, &ioStatus);
if (!newIrp) {
TRACE(TL_ERROR, ("Failed to allocate newIrp!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_IsochFreeChannel;
}
allocNewIrp = TRUE;
}
pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));
if (!pIrb) {
TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_IsochFreeChannel;
} // if
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ISOCH_FREE_CHANNEL;
pIrb->Flags = 0;
pIrb->u.IsochFreeChannel.nChannel = nChannel;
//
// If we allocated this irp, submit it asynchronously and wait for its
// completion event to be signaled. Otherwise submit it synchronously
//
if (allocNewIrp) {
KeInitializeEvent (&Event, NotificationEvent, FALSE);
ntStatus = t1394_SubmitIrpAsync (deviceExtension->StackDeviceObject, newIrp, pIrb);
if (ntStatus == STATUS_PENDING) {
KeWaitForSingleObject (&Event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
}
}
else {
ntStatus = t1394_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, pIrb);
}
if (!NT_SUCCESS(ntStatus)) {
TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
}
Exit_IsochFreeChannel:
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_IsochFreeChannel", ntStatus);
return(ntStatus);
} // t1394_IsochFreeChannel
NTSTATUS
t1394_IsochFreeResources(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN HANDLE hResource
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIRB pIrb = NULL;
PISOCH_RESOURCE_DATA IsochResourceData = NULL;
KIRQL Irql;
PIRP newIrp = NULL;
BOOLEAN allocNewIrp = FALSE;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
ENTER("t1394_IsochFreeResources");
TRACE(TL_TRACE, ("hResource = 0x%x\n", hResource));
//
// If this is a UserMode request create a newIrp so that the request
// will be issued from KernelMode
//
if (Irp->RequestorMode == UserMode) {
newIrp = IoBuildDeviceIoControlRequest (IOCTL_1394_CLASS, deviceExtension->StackDeviceObject,
NULL, 0, NULL, 0, TRUE, &Event, &ioStatus);
if (!newIrp) {
TRACE(TL_ERROR, ("Failed to allocate newIrp!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_IsochFreeResources;
}
allocNewIrp = TRUE;
}
pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));
if (!pIrb) {
TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_IsochFreeResources;
} // if
// remove this one from our list...
KeAcquireSpinLock(&deviceExtension->IsochResourceSpinLock, &Irql);
IsochResourceData = (PISOCH_RESOURCE_DATA)deviceExtension->IsochResourceData.Flink;
while (IsochResourceData) {
TRACE(TL_TRACE, ("Removing hResource = 0x%x\n", hResource));
if (IsochResourceData->hResource == hResource) {
RemoveEntryList(&IsochResourceData->IsochResourceList);
ExFreePool(IsochResourceData);
break;
}
else if (IsochResourceData->IsochResourceList.Flink == &deviceExtension->IsochResourceData) {
break;
}
else
IsochResourceData = (PISOCH_RESOURCE_DATA)IsochResourceData->IsochResourceList.Flink;
}
KeReleaseSpinLock(&deviceExtension->IsochResourceSpinLock, Irql);
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ISOCH_FREE_RESOURCES;
pIrb->Flags = 0;
pIrb->u.IsochFreeResources.hResource = hResource;
//
// If we allocated this irp, submit it asynchronously and wait for its
// completion event to be signaled. Otherwise submit it synchronously
//
if (allocNewIrp) {
KeInitializeEvent (&Event, NotificationEvent, FALSE);
ntStatus = t1394_SubmitIrpAsync (deviceExtension->StackDeviceObject, newIrp, pIrb);
if (ntStatus == STATUS_PENDING) {
KeWaitForSingleObject (&Event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
}
}
else {
ntStatus = t1394_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, pIrb);
}
if (!NT_SUCCESS(ntStatus)) {
TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
}
Exit_IsochFreeResources:
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_IsochFreeResources", ntStatus);
return(ntStatus);
} // t1394_IsochFreeResources
NTSTATUS
t1394_IsochListen(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN HANDLE hResource,
IN ULONG fulFlags,
IN CYCLE_TIME StartTime
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIRB pIrb = NULL;
PIRP newIrp = NULL;
BOOLEAN allocNewIrp = FALSE;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
ENTER("t1394_IsochListen");
TRACE(TL_TRACE, ("hResource = 0x%x\n", hResource));
TRACE(TL_TRACE, ("fulFlags = 0x%x\n", fulFlags));
TRACE(TL_TRACE, ("StartTime.CL_CycleOffset = 0x%x\n", StartTime.CL_CycleOffset));
TRACE(TL_TRACE, ("StartTime.CL_CycleCount = 0x%x\n", StartTime.CL_CycleCount));
TRACE(TL_TRACE, ("StartTime.CL_SecondCount = 0x%x\n", StartTime.CL_SecondCount));
//
// If this is a UserMode request create a newIrp so that the request
// will be issued from KernelMode
//
if (Irp->RequestorMode == UserMode) {
newIrp = IoBuildDeviceIoControlRequest (IOCTL_1394_CLASS, deviceExtension->StackDeviceObject,
NULL, 0, NULL, 0, TRUE, &Event, &ioStatus);
if (!newIrp) {
TRACE(TL_ERROR, ("Failed to allocate newIrp!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_IsochListen;
}
allocNewIrp = TRUE;
}
pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));
if (!pIrb) {
TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_IsochListen;
} // if
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ISOCH_LISTEN;
pIrb->Flags = 0;
pIrb->u.IsochListen.hResource = hResource;
pIrb->u.IsochListen.fulFlags = fulFlags;
pIrb->u.IsochListen.StartTime = StartTime;
//
// If we allocated this irp, submit it asynchronously and wait for its
// completion event to be signaled. Otherwise submit it synchronously
//
if (allocNewIrp) {
KeInitializeEvent (&Event, NotificationEvent, FALSE);
ntStatus = t1394_SubmitIrpAsync (deviceExtension->StackDeviceObject, newIrp, pIrb);
if (ntStatus == STATUS_PENDING) {
KeWaitForSingleObject (&Event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
}
}
else {
ntStatus = t1394_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, pIrb);
}
if (!NT_SUCCESS(ntStatus)) {
TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
}
Exit_IsochListen:
if (pIrb)
{
ExFreePool(pIrb);
}
if (allocNewIrp)
{
Irp->IoStatus = ioStatus;
}
EXIT("t1394_IsochListen", ntStatus);
return(ntStatus);
} // t1394_IsochListen
NTSTATUS
t1394_IsochQueryCurrentCycleTime(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
OUT PCYCLE_TIME pCurrentCycleTime
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIRB pIrb = NULL;
PIRP newIrp = NULL;
BOOLEAN allocNewIrp = FALSE;
KEVENT Event;
IO_STATUS_BLOCK ioStatus;
ENTER("t1394_IsochQueryCurrentCycleTime");
//
// If this is a UserMode request create a newIrp so that the request
// will be issued from KernelMode
//
if (Irp->RequestorMode == UserMode) {
newIrp = IoBuildDeviceIoControlRequest (IOCTL_1394_CLASS, deviceExtension->StackDeviceObject,
NULL, 0, NULL, 0, TRUE, &Event, &ioStatus);
if (!newIrp) {
TRACE(TL_ERROR, ("Failed to allocate newIrp!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_IsochQueryCurrentCycleTime;
}
allocNewIrp = TRUE;
}
pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));
if (!pIrb) {
TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto Exit_IsochQueryCurrentCycleTime;
} // if
RtlZeroMemory (pIrb, sizeof (IRB));
pIrb->FunctionNumber = REQUEST_ISOCH_QUERY_CYCLE_TIME;
pIrb->Flags = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?