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

📄 isochapi.c

📁 winddk src目录下的WDM源码压缩!
💻 C
📖 第 1 页 / 共 4 页
字号:
/*++

Copyright (c) 1997-1998 Microsoft Corporation

Module Name:

    isochapi.c

Abstract


Author:

    Peter Binder (pbinder) 9-15-97

Revision History:
Date     Who       What
-------- --------- ------------------------------------------------------------
9-15-97  pbinder   birth
4-08-98  pbinder   taken from win1394
--*/

#define _ISOCHAPI_C
#include "pch.h"
#undef _ISOCHAPI_C

ULONG
WINAPI
IsochAllocateBandwidth(
    HWND                        hWnd,
    PSTR                        szDeviceName,
    PISOCH_ALLOCATE_BANDWIDTH   isochAllocateBandwidth
    )
{
    HANDLE      hDevice;
    DWORD       dwRet, dwBytesRet;

    TRACE(TL_TRACE, (hWnd, "Enter IsochAllocateBandwidth\r\n"));

    TRACE(TL_TRACE, (hWnd, "nMaxBytesPerFrameRequested = 0x%x\r\n", isochAllocateBandwidth->nMaxBytesPerFrameRequested));
    TRACE(TL_TRACE, (hWnd, "fulSpeed = 0x%x\r\n", isochAllocateBandwidth->fulSpeed));

    hDevice = OpenDevice(hWnd, szDeviceName, FALSE);

    if (hDevice != INVALID_HANDLE_VALUE) {

        dwRet = DeviceIoControl( hDevice,
                                 IOCTL_ISOCH_ALLOCATE_BANDWIDTH,
                                 isochAllocateBandwidth,
                                 sizeof(ISOCH_ALLOCATE_BANDWIDTH),
                                 isochAllocateBandwidth,
                                 sizeof(ISOCH_ALLOCATE_BANDWIDTH),
                                 &dwBytesRet,
                                 NULL
                                 );

        if (dwRet) {

            dwRet = ERROR_SUCCESS;

            TRACE(TL_TRACE, (hWnd, "hBandwidth = 0x%x\r\n", isochAllocateBandwidth->hBandwidth));
            TRACE(TL_TRACE, (hWnd, "BytesPerFrameAvailable = 0x%x\r\n", isochAllocateBandwidth->BytesPerFrameAvailable));
            TRACE(TL_TRACE, (hWnd, "Speed Selected = 0x%x\r\n", isochAllocateBandwidth->SpeedSelected));
        }
        else {

            dwRet = GetLastError();
            TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
        }

        // free up resources
        CloseHandle(hDevice);
    }
    else {

        dwRet = GetLastError();
        TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));        
    }
    
    TRACE(TL_TRACE, (hWnd, "Exit IsochAllocateBandwidth = %d\r\n", dwRet));
    return(dwRet);
} // IsochAllocateBandwidth

ULONG
WINAPI
IsochAllocateChannel(
    HWND                        hWnd,
    PSTR                        szDeviceName,
    PISOCH_ALLOCATE_CHANNEL     isochAllocateChannel
    )
{
    HANDLE      hDevice;
    DWORD       dwRet, dwBytesRet;

    TRACE(TL_TRACE, (hWnd, "Enter IsochAllocateChannel\r\n"));

    TRACE(TL_TRACE, (hWnd, "nRequestedChannel = 0x%x\r\n", isochAllocateChannel->nRequestedChannel));

    hDevice = OpenDevice(hWnd, szDeviceName, FALSE);

    if (hDevice != INVALID_HANDLE_VALUE) {

        dwRet = DeviceIoControl( hDevice,
                                 IOCTL_ISOCH_ALLOCATE_CHANNEL,
                                 isochAllocateChannel,
                                 sizeof(ISOCH_ALLOCATE_CHANNEL),
                                 isochAllocateChannel,
                                 sizeof(ISOCH_ALLOCATE_CHANNEL),
                                 &dwBytesRet,
                                 NULL
                                 );

        if (dwRet) {

            dwRet = ERROR_SUCCESS;

            TRACE(TL_TRACE, (hWnd, "Channel = 0x%x\r\n", isochAllocateChannel->Channel));
            TRACE(TL_TRACE, (hWnd, "ChannelsAvailable.LowPart = 0x%x\r\n", isochAllocateChannel->ChannelsAvailable.LowPart));
            TRACE(TL_TRACE, (hWnd, "ChannelsAvailable.HighPart = 0x%x\r\n", isochAllocateChannel->ChannelsAvailable.HighPart));
        }
        else {

            dwRet = GetLastError();
            TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
        }

        // free up resources
        CloseHandle(hDevice);
    }
    else {

        dwRet = GetLastError();
        TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));        
    }
    
    TRACE(TL_TRACE, (hWnd, "Exit IsochAllocateChannel = %d\r\n", dwRet));
    return(dwRet);
} // IsochAllocateChannel

ULONG
WINAPI
IsochAllocateResources(
    HWND                        hWnd,
    PSTR                        szDeviceName,
    PISOCH_ALLOCATE_RESOURCES   isochAllocateResources
    )
{
    HANDLE      hDevice;
    DWORD       dwRet, dwBytesRet;
    
    TRACE(TL_TRACE, (hWnd, "Enter IsochAllocateResources\r\n"));

    TRACE(TL_TRACE, (hWnd, "fulSpeed = 0x%x\r\n", isochAllocateResources->fulSpeed));
    TRACE(TL_TRACE, (hWnd, "fulFlags = 0x%x\r\n", isochAllocateResources->fulFlags));
    TRACE(TL_TRACE, (hWnd, "nChannel = 0x%x\r\n", isochAllocateResources->nChannel));
    TRACE(TL_TRACE, (hWnd, "nMaxBytesPerFrame = 0x%x\r\n", isochAllocateResources->nMaxBytesPerFrame));
    TRACE(TL_TRACE, (hWnd, "nNumberOfBuffers = 0x%x\r\n", isochAllocateResources->nNumberOfBuffers));
    TRACE(TL_TRACE, (hWnd, "nMaxBufferSize = 0x%x\r\n", isochAllocateResources->nMaxBufferSize));
    TRACE(TL_TRACE, (hWnd, "nQuadletsToStrip = 0x%x\r\n", isochAllocateResources->nQuadletsToStrip));

    hDevice = OpenDevice(hWnd, szDeviceName, FALSE);

    if (hDevice != INVALID_HANDLE_VALUE) {

        dwRet = DeviceIoControl( hDevice,
                                 IOCTL_ISOCH_ALLOCATE_RESOURCES,
                                 isochAllocateResources,
                                 sizeof(ISOCH_ALLOCATE_RESOURCES),
                                 isochAllocateResources,
                                 sizeof(ISOCH_ALLOCATE_RESOURCES),
                                 &dwBytesRet,
                                 NULL
                                 );

        if (dwRet) {

            dwRet = ERROR_SUCCESS;

            TRACE(TL_TRACE, (hWnd, "hResource = %p\r\n", isochAllocateResources->hResource));
        }
        else {

            dwRet = GetLastError();
            TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
        }

        // free up resources
        CloseHandle(hDevice);
    }
    else {

        dwRet = GetLastError();
        TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));        
    }
    
    TRACE(TL_TRACE, (hWnd, "Exit IsochAllocateResources = %d\r\n", dwRet));
    return(dwRet);
} // IsochAllocateResources

ULONG
WINAPI
IsochAttachBuffers(
    HWND                        hWnd,
    PSTR                        szDeviceName,
    PISOCH_ATTACH_BUFFERS       isochAttachBuffers,
    BOOL                        bAutoAlloc,
    BOOL                        bAutoFill
    )
{
    HANDLE      hDevice;

    PISOCH_ATTACH_BUFFERS           pIsochAttachBuffers;

    PRING3_ISOCH_DESCRIPTOR         pR3TempDescriptor;
    RING3_ISOCH_DESCRIPTOR          R3_IsochDescriptor;
    
    OVERLAPPED                      overLapped;
    
    ULONG                           ulBufferSize;
    DWORD                           dwBytesRet;
    DWORD                           dwRet;
    
    ULONG                           i, n;

    TRACE(TL_TRACE, (hWnd, "Enter IsochAttachBuffers\r\n"));

    TRACE(TL_TRACE, (hWnd, "hResource = %p\r\n", isochAttachBuffers->hResource));
    TRACE(TL_TRACE, (hWnd, "nNumberOfDescriptors = 0x%x\r\n", isochAttachBuffers->nNumberOfDescriptors));
    TRACE(TL_TRACE, (hWnd, "fulFlags = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].fulFlags));
    TRACE(TL_TRACE, (hWnd, "ulLength = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].ulLength));
    TRACE(TL_TRACE, (hWnd, "nMaxBytesPerFrame = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].nMaxBytesPerFrame));
    TRACE(TL_TRACE, (hWnd, "ulSynch = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].ulSynch));
    TRACE(TL_TRACE, (hWnd, "ulTag = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].ulTag));
    TRACE(TL_TRACE, (hWnd, "StartTime.CL_CycleOffset = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].CycleTime.CL_CycleOffset));
    TRACE(TL_TRACE, (hWnd, "StartTime.CL_CycleCount = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].CycleTime.CL_CycleCount));
    TRACE(TL_TRACE, (hWnd, "StartTime.CL_SecondCount = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].CycleTime.CL_SecondCount));
    TRACE(TL_TRACE, (hWnd, "bUseCallback = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].bUseCallback));
    TRACE(TL_TRACE, (hWnd, "bAutoDetach = 0x%x\r\n", isochAttachBuffers->R3_IsochDescriptor[0].bAutoDetach));
    TRACE(TL_TRACE, (hWnd, "bAutoAlloc = %d\r\n", bAutoAlloc));
    TRACE(TL_TRACE, (hWnd, "bAutoFill = %d\r\n", bAutoFill));

    hDevice = OpenDevice(hWnd, szDeviceName, TRUE);

    if (hDevice != INVALID_HANDLE_VALUE) {

        R3_IsochDescriptor = isochAttachBuffers->R3_IsochDescriptor[0];
    
        // they are always required to give me at least one filled in ring3 isoch descriptor.
        // this way if they set the bAutoAlloc flag, i have a template on what to set up.
        // basically, i'll auto allocate however many descriptors they want, base on the first one.
        // if they want something more, then they are required to allocate all of the descriptors themselves

        //
        // if the bAutoAlloc flag is set, that means that we allocate according to
        // the first descriptor. we assume there's only one configured descriptor
        //
        if (bAutoAlloc) {

            // lets calculate the buffer size
            ulBufferSize = sizeof(ISOCH_ATTACH_BUFFERS) +
                (isochAttachBuffers->R3_IsochDescriptor[0].ulLength*isochAttachBuffers->nNumberOfDescriptors) +
                (sizeof(RING3_ISOCH_DESCRIPTOR)*(isochAttachBuffers->nNumberOfDescriptors-1));

            pIsochAttachBuffers = (PISOCH_ATTACH_BUFFERS)LocalAlloc(LPTR, ulBufferSize);
            if (!pIsochAttachBuffers) {
                
                dwRet = GetLastError();
                TRACE(TL_ERROR, (hWnd, "Could not allocate pIsochAttachBuffers\r\n"));
                goto Exit_IsochAttachBuffers;
            }
    
            ZeroMemory(pIsochAttachBuffers, ulBufferSize);
            *pIsochAttachBuffers = *isochAttachBuffers;

            //
            // now we need to setup each descriptor
            //
            pR3TempDescriptor = &pIsochAttachBuffers->R3_IsochDescriptor[0];

            for (i=0; i < isochAttachBuffers->nNumberOfDescriptors; i++) {

            *pR3TempDescriptor = R3_IsochDescriptor;

            pR3TempDescriptor =
                (PRING3_ISOCH_DESCRIPTOR)((ULONG_PTR)pR3TempDescriptor +
                                              pR3TempDescriptor->ulLength +
                                              sizeof(RING3_ISOCH_DESCRIPTOR));
            }
        }
        else {

            // we have already received an allocated buffer, let's just map it into
            // our attach struct and pass it down.
            pIsochAttachBuffers = isochAttachBuffers;
            ulBufferSize = pIsochAttachBuffers->ulBufferSize;
        }

        if (pIsochAttachBuffers) {

            overLapped.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );

            // reset our event, in case we'll be doing another attach
            ResetEvent(overLapped.hEvent);

            if (bAutoFill) {

                // get the point to the first descriptor
                pR3TempDescriptor = &pIsochAttachBuffers->R3_IsochDescriptor[0];

                for (i=0; i < pIsochAttachBuffers->nNumberOfDescriptors;  i++) {

                    // if we're listening, fill it with 0's
                    // if we're talking, fill it incrementally
                    if (isochAttachBuffers->R3_IsochDescriptor[i].fulFlags & RESOURCE_USED_IN_LISTENING) {

                        FillMemory(&pR3TempDescriptor->Data, pR3TempDescriptor->ulLength, 0);
                    }
                    else {

                        if (pR3TempDescriptor->fulFlags == DESCRIPTOR_HEADER_SCATTER_GATHER) {


                        }
                
                        else {

                            for (n=0; n < (pR3TempDescriptor->ulLength/sizeof(ULONG)); n++) {

                                CopyMemory((ULONG *)&pR3TempDescriptor->Data+n, (ULONG *)&n, sizeof(ULONG));
                            }
                        }
                    }

                    pR3TempDescriptor = (PRING3_ISOCH_DESCRIPTOR)((ULONG_PTR)pR3TempDescriptor +
                                    pR3TempDescriptor->ulLength + sizeof(RING3_ISOCH_DESCRIPTOR));

                }
            }
        }

        DeviceIoControl( hDevice,
                         IOCTL_ISOCH_ATTACH_BUFFERS,
                         pIsochAttachBuffers,
                         ulBufferSize,
                         pIsochAttachBuffers,
                         ulBufferSize,

⌨️ 快捷键说明

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