⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isochapi.c

📁 关于1394diag的资料和源代码的实例
💻 C
📖 第 1 页 / 共 3 页
字号:

    if (!pIrb) {

        TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
        TRAP;

        ntStatus = STATUS_INSUFFICIENT_RESOURCES;
        goto Exit_IsochSetChannelBandwidth;
    } // if

    pIrb->FunctionNumber = REQUEST_ISOCH_SET_CHANNEL_BANDWIDTH;
    pIrb->Flags = 0;
    pIrb->u.IsochSetChannelBandwidth.hBandwidth = hBandwidth;
    pIrb->u.IsochSetChannelBandwidth.nMaxBytesPerFrame = nMaxBytesPerFrame;

	ntStatus = t1394Diag_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, pIrb);

    if (!NT_SUCCESS(ntStatus)) {

        TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
        TRAP;
    }
	
    ExFreePool(pIrb);

Exit_IsochSetChannelBandwidth:

    EXIT("t1394Diag_IsochSetChannelBandwidth",  ntStatus);
    return(ntStatus);
} // t1394Diag_IsochSetChannelBandwidth

NTSTATUS
t1394Diag_IsochStop(
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp,
    IN HANDLE           hResource,
    IN ULONG            fulFlags
    )
{
    NTSTATUS            ntStatus = STATUS_SUCCESS;
    PDEVICE_EXTENSION   deviceExtension = DeviceObject->DeviceExtension;
    PIRB                pIrb;

    ENTER("t1394Diag_IsochStop");

    TRACE(TL_TRACE, ("hResource = 0x%x\n", hResource));
    TRACE(TL_TRACE, ("fulFlags = 0x%x\n", fulFlags));

    pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));

    if (!pIrb) {

        TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
        TRAP;

        ntStatus = STATUS_INSUFFICIENT_RESOURCES;
        goto Exit_IsochStop;
    } // if

    pIrb->FunctionNumber = REQUEST_ISOCH_STOP;
    pIrb->Flags = 0;
    pIrb->u.IsochStop.hResource = hResource;
    pIrb->u.IsochStop.fulFlags = fulFlags;

    ntStatus = t1394Diag_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, pIrb);

    if (!NT_SUCCESS(ntStatus)) {

        TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
        TRAP;
    }
	
    ExFreePool(pIrb);
	
Exit_IsochStop:

    EXIT("t1394Diag_IsochStop", ntStatus);
    return(ntStatus);
} // t1394Diag_IsochStop

NTSTATUS
t1394Diag_IsochTalk(
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp,
    IN HANDLE           hResource,
    IN ULONG            fulFlags,
    CYCLE_TIME          StartTime
    )
{
    NTSTATUS            ntStatus = STATUS_SUCCESS;
    PDEVICE_EXTENSION   deviceExtension = DeviceObject->DeviceExtension;
    PIRB                pIrb;

    ENTER("t1394Diag_IsochTalk");

    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));

    pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));

    if (!pIrb) {

        TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
        TRAP;

        ntStatus = STATUS_INSUFFICIENT_RESOURCES;
        goto Exit_IsochTalk;
    } // if

    pIrb->FunctionNumber = REQUEST_ISOCH_TALK;
    pIrb->Flags = 0;
    pIrb->u.IsochTalk.hResource = hResource;
    pIrb->u.IsochTalk.fulFlags = fulFlags;
    pIrb->u.IsochTalk.StartTime = StartTime;

    ntStatus = t1394Diag_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, pIrb);

    if (!NT_SUCCESS(ntStatus)) {

        TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
        TRAP;
    }
	
    ExFreePool(pIrb);

Exit_IsochTalk:

    EXIT("t1394Diag_IsochTalk", ntStatus);
    return(ntStatus);
} // t1394Diag_IsochTalk

void
t1394Diag_IsochCallback(
    IN PDEVICE_EXTENSION    DeviceExtension,
    IN PISOCH_DETACH_DATA   IsochDetachData
    )
{
    KIRQL               Irql;

    ENTER("t1394Diag_IsochCallback");

    if (!DeviceExtension->bShutdown) {

        KeAcquireSpinLock(&DeviceExtension->IsochSpinLock, &Irql);
        RemoveEntryList(&IsochDetachData->IsochDetachList);
        KeCancelTimer(&IsochDetachData->Timer);

        TRACE(TL_TRACE, ("IsochCallback: IsochDetachData = 0x%x\n", IsochDetachData));
        TRACE(TL_TRACE, ("IsochCallback: IsochDetachData->Irp = 0x%x\n", IsochDetachData->Irp));

        if (IsochDetachData->Tag != ISOCH_DETACH_TAG) {

            TRACE(TL_ERROR, ("Invalid Detach Tag!\n"));
            TRAP;

            KeReleaseSpinLock(&DeviceExtension->IsochSpinLock, Irql);
        }
        else {

            // clear the tag...
            IsochDetachData->Tag = 0;

            KeReleaseSpinLock(&DeviceExtension->IsochSpinLock, Irql);

            // need to save the status of the attach
            // we'll clean up in the same spot for success's and timeout's
            IsochDetachData->AttachStatus = IsochDetachData->Irp->IoStatus.Status;

            t1394Diag_IsochCleanup(IsochDetachData);
        }
    }

    EXIT("t1394Diag_IsochCallback", 0);
} // t1394Diag_IsochCallback

void
t1394Diag_IsochTimeout(
    IN PKDPC                Dpc,
    IN PISOCH_DETACH_DATA   IsochDetachData,
    IN PVOID                SystemArgument1,
    IN PVOID                SystemArgument2
    )
{
    KIRQL               Irql;
    PDEVICE_EXTENSION   DeviceExtension;

    ENTER("t1394Diag_IsochTimeout");

    TRACE(TL_WARNING, ("Isoch Timeout!\n"));

    DeviceExtension = IsochDetachData->DeviceExtension;

    if (!DeviceExtension->bShutdown) {

        KeAcquireSpinLock(&DeviceExtension->IsochSpinLock, &Irql);
        RemoveEntryList(&IsochDetachData->IsochDetachList);
        KeCancelTimer(&IsochDetachData->Timer);

        TRACE(TL_TRACE, ("IsochTimeout: IsochDetachData = 0x%x\n", IsochDetachData));
        TRACE(TL_TRACE, ("IsochTimeout: IsochDetachData->Irp = 0x%x\n", IsochDetachData->Irp));

        if (IsochDetachData->Tag != ISOCH_DETACH_TAG) {

            TRACE(TL_ERROR, ("Invalid Detach Tag!\n"));
            TRAP;

            KeReleaseSpinLock(&DeviceExtension->IsochSpinLock, Irql);
        }
        else {

            // clear the tag...
            IsochDetachData->Tag = 0;

            KeReleaseSpinLock(&DeviceExtension->IsochSpinLock, Irql);

            // need to save the status of the attach
            // we'll clean up in the same spot for success's and timeout's
            IsochDetachData->AttachStatus = STATUS_TIMEOUT;

            t1394Diag_IsochCleanup(IsochDetachData);
        }
    }

    EXIT("t1394Diag_IsochTimeout", 0);
} // t1394Diag_IsochTimeout

void
t1394Diag_IsochCleanup(
    IN PISOCH_DETACH_DATA   IsochDetachData
    )
{
    ULONG               i;
    PDEVICE_EXTENSION   DeviceExtension;

    ENTER("t1394Diag_IsochCleanup");

    DeviceExtension = IsochDetachData->DeviceExtension;

    //
    // see if we need to detach this buffer
    //
    if (IsochDetachData->bDetach) {

        PIRB                pIrb;
        NTSTATUS            ntStatus;
        PIO_STACK_LOCATION  NextIrpStack;

        pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));

        if (!pIrb) {

            TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
            TRACE(TL_WARNING, ("Can't detach buffer!\n"));
            TRAP;

            ntStatus = STATUS_INSUFFICIENT_RESOURCES;
            goto Exit_IsochDetachBuffers;
        } // if

        // save the irb in our detach data context
        IsochDetachData->DetachIrb = pIrb;

        pIrb->FunctionNumber = REQUEST_ISOCH_DETACH_BUFFERS;
        pIrb->Flags = 0;
        pIrb->u.IsochDetachBuffers.hResource = IsochDetachData->hResource;
        pIrb->u.IsochDetachBuffers.nNumberOfDescriptors = IsochDetachData->numIsochDescriptors;
        pIrb->u.IsochDetachBuffers.pIsochDescriptor = IsochDetachData->IsochDescriptor;

        NextIrpStack = IoGetNextIrpStackLocation(IsochDetachData->Irp);
        NextIrpStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
        NextIrpStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_1394_CLASS;
        NextIrpStack->Parameters.Others.Argument1 = pIrb;

        IoSetCompletionRoutine( IsochDetachData->Irp,
                                t1394Diag_IsochDetachCompletionRoutine,
                                IsochDetachData,
                                TRUE,
                                TRUE,
                                TRUE
                                );

        IoCallDriver(DeviceExtension->StackDeviceObject, IsochDetachData->Irp);
    }
    else {

Exit_IsochDetachBuffers:

        TRACE(TL_TRACE, ("Complete Irp.\n"));

        if (IsochDetachData->AttachIrb)
            ExFreePool(IsochDetachData->AttachIrb);

        for (i=0; i<IsochDetachData->numIsochDescriptors; i++)
            ExFreePool(IsochDetachData->IsochDescriptor[i].Mdl);

        ExFreePool(IsochDetachData->IsochDescriptor);

        IsochDetachData->Irp->IoStatus.Status = IsochDetachData->AttachStatus;

        // only set this if its a success...
        if (NT_SUCCESS(IsochDetachData->AttachStatus))
            IsochDetachData->Irp->IoStatus.Information = IsochDetachData->outputBufferLength;

        IoCompleteRequest(IsochDetachData->Irp, IO_NO_INCREMENT);

        // all done with IsochDetachData, lets deallocate it...
        ExFreePool(IsochDetachData);
    }

    EXIT("t1394Diag_IsochCleanup", 0);
} // t1394Diag_IsochCleanup

NTSTATUS
t1394Diag_IsochDetachCompletionRoutine(
    IN PDEVICE_OBJECT       DeviceObject,
    IN PIRP                 Irp,
    IN PISOCH_DETACH_DATA   IsochDetachData
    )
{
    NTSTATUS        ntStatus = STATUS_SUCCESS;
    ULONG           i;

    ENTER("t1394Diag_IsochDetachCompletionRoutine");

    if (IsochDetachData->DetachIrb)
        ExFreePool(IsochDetachData->DetachIrb);

    TRACE(TL_TRACE, ("Complete Irp.\n"));

    if (IsochDetachData->AttachIrb)
        ExFreePool(IsochDetachData->AttachIrb);

    for (i=0; i<IsochDetachData->numIsochDescriptors; i++)
        ExFreePool(IsochDetachData->IsochDescriptor[i].Mdl);
    	
    ExFreePool(IsochDetachData->IsochDescriptor);

    // only set this if its a success...
    if (NT_SUCCESS(IsochDetachData->AttachStatus))
        IsochDetachData->Irp->IoStatus.Information = IsochDetachData->outputBufferLength;

    IsochDetachData->Irp->IoStatus.Status = IsochDetachData->AttachStatus;

    IoCompleteRequest(IsochDetachData->Irp, IO_NO_INCREMENT);

    // all done with IsochDetachData, lets deallocate it...
    ExFreePool(IsochDetachData);
    
    EXIT("t1394Diag_IsochDetachCompletionRoutine", ntStatus);
    return(STATUS_MORE_PROCESSING_REQUIRED);
} // t1394Diag_IsochDetachCompletionRoutine

NTSTATUS
t1394Diag_IsochAttachCompletionRoutine(
    IN PDEVICE_OBJECT       DeviceObject,
    IN PIRP                 Irp,
    IN PISOCH_DETACH_DATA   IsochDetachData
    )
{
    NTSTATUS            ntStatus = STATUS_SUCCESS;
    ULONG               i;
    KIRQL               Irql;
    PDEVICE_EXTENSION   DeviceExtension;

    ENTER("t1394Diag_IsochAttachCompletionRoutine");

    if (Irp->IoStatus.Status) {

        TRACE(TL_ERROR, ("Isoch Attach Failed! = 0x%x\n", Irp->IoStatus.Status));
//        TRAP;

        if (!IsochDetachData) {
        
            goto Exit_IsochAttachCompletionRoutine;
        }

        DeviceExtension = IsochDetachData->DeviceExtension;

        if (!DeviceExtension->bShutdown) {

            KeAcquireSpinLock(&DeviceExtension->IsochSpinLock, &Irql);
            RemoveEntryList(&IsochDetachData->IsochDetachList);
            KeCancelTimer(&IsochDetachData->Timer);

            TRACE(TL_TRACE, ("IsochAttachCompletionRoutine: IsochDetachData = 0x%x\n", IsochDetachData));
            TRACE(TL_TRACE, ("IsochAttachCompletionRoutine: IsochDetachData->Irp = 0x%x\n", IsochDetachData->Irp));

            if (IsochDetachData->Tag != ISOCH_DETACH_TAG) {

                TRACE(TL_ERROR, ("Invalid Detach Tag!\n"));
                TRAP;

                KeReleaseSpinLock(&DeviceExtension->IsochSpinLock, Irql);
            }
            else {

                // clear the tag...
                IsochDetachData->Tag = 0;

                KeReleaseSpinLock(&DeviceExtension->IsochSpinLock, Irql);

                TRACE(TL_TRACE, ("Complete Irp.\n"));

                if (IsochDetachData->AttachIrb)
                    ExFreePool(IsochDetachData->AttachIrb);

                for (i=0; i<IsochDetachData->numIsochDescriptors; i++)
                    ExFreePool(IsochDetachData->IsochDescriptor[i].Mdl);
    	
                ExFreePool(IsochDetachData->IsochDescriptor);

                IoCompleteRequest(Irp, IO_NO_INCREMENT);

                // all done with IsochDetachData, lets deallocate it...
                ExFreePool(IsochDetachData);
            }
        }
    }

Exit_IsochAttachCompletionRoutine:

    EXIT("t1394Diag_IsochAttachCompletionRoutine", ntStatus);
    return(STATUS_MORE_PROCESSING_REQUIRED);
} // t1394Diag_IsochAttachCompletionRoutine


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -