亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? usbfx2lk_io.cpp

?? VisualC++寫的一個USB的驅動程序。
?? CPP
?? 第 1 頁 / 共 4 頁
字號:
///////////////////////////////////////////////////////////////////////////////
//
//    (C) Copyright 2005 OSR Open Systems Resources, Inc.
//    All Rights Reserved
//
//    This sofware is supplied for instructional purposes only.
//
//    OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
//    for this software.  THIS SOFTWARE IS PROVIDED  "AS IS" WITHOUT WARRANTY
//    OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
//    THE IMPLIED WARRANTIES OF MECHANTABILITY OR FITNESS FOR A PARTICULAR
//    PURPOSE.  THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
//    WITH YOU.  OSR's entire liability and your exclusive remedy shall not
//    exceed the price paid for this material.  In no event shall OSR or its
//    suppliers be liable for any damages whatsoever (including, without
//    limitation, damages for loss of business profit, business interruption,
//    loss of business information, or any other pecuniary loss) arising out
//    of the use or inability to use this software, even if OSR has been
//    advised of the possibility of such damages.  Because some states/
//    jurisdictions do not allow the exclusion or limitation of liability for
//    consequential or incidental damages, the above limitation may not apply
//    to you.
//
//    OSR Open Systems Resources, Inc.
//    105 Route 101A Suite 19
//    Amherst, NH 03031  (603) 595-6500 FAX: (603) 595-6503
//    email bugs to: bugs@osr.com
//
//
//    MODULE:
//
//      USBFx2LK_io.cpp
//
//    ABSTRACT:
//
//      This file contains the routines that handle IRP_MJ_READ and
//      IRP_MJ_WRITE processing for the OSR USB FX2 Learning Kit Device
//
//    AUTHOR(S):
//
//      OSR Open Systems Resources, Inc.
// 
///////////////////////////////////////////////////////////////////////////////
#include "usbfx2lk.h"

#ifdef WPP_TRACING
//
// Include the necessary tmh file - this is 
//  just a matter of course if you're using WPP tracing.
//
extern "C" {
#include "usbfx2lk_io.tmh"
}
#endif

//
// Forward Definitions
//
NTSTATUS UsbFx2LkReadCompletionRoutine(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN PVOID  Context);
NTSTATUS UsbFx2LkWriteCompletionRoutine(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN PVOID  Context);
VOID IssueUsbReadRequest(IN PDEVICE_OBJECT DeviceObject,IN PVOID Context);
VOID IssueUsbWriteRequest(IN PDEVICE_OBJECT DeviceObject,IN PVOID Context);


///////////////////////////////////////////////////////////////////////////////
//
// ProcessNextIrpInQueue
//
//  This routine processes the Next Irp in the Io Queue, if we are in a state
//  to process Irps.   If not, the Irps will remain in the queue until the state
//  of the device changes to either a state where the Irps can be processed or where
//  the Irps will be removed from the queue.
//
//  INPUTS:
//
//      DevExt  -  Address of our Device Extension.
//
//  OUTPUTS:
//
//      None
//
//  RETURNS:
//
//      None
//
//  IRQL:
//
//      IRQL == PASSIVE_LEVEL
//
//  CONTEXT:
//
//      User Context
//
//  NOTES:
//
///////////////////////////////////////////////////////////////////////////////
VOID ProcessNextIrpInQueue(PUSBFX2LK_EXT DevExt)
{
    KIRQL       oldIrql;
    PIRP        irp;

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_READWRITE, ("ProcessNextIrpInQueue Entered...\n"));

    //
    // Check the state of the device.   If we not processing irps
    // we will just return.
    //
    KeAcquireSpinLock(&DevExt->IoStateLock,&oldIrql);
    if(DevExt->DevicePnPState >= STATE_ALL_ABOVE_QUEUE) {
        KeReleaseSpinLock(&DevExt->IoStateLock,oldIrql);
        OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_READWRITE,
            ("ProcessNextIrpInQueue: Exit Queuing Irps, Not Processing\n"));
        return;
    }
    KeReleaseSpinLock(&DevExt->IoStateLock,oldIrql);

    //
    // See if the device is currently suspended. If it 
    //  is, this routine will attempt to asynchronously power 
    //  the device back up and will return TRUE. In that
    //  case, the power up code will restart our queues and
    //  we can simply exit here. However, if this routine
    //  returns FALSE the device is already powered up
    //  and we can attempt to start the next IRP in
    //  the queue.
    //
    if (!SSPowerDeviceIfSuspendedAsync(DevExt)) {
    
        //
        // Attempt to remove an IRP from the Queue.  
        //
        irp = IoCsqRemoveNextIrp(&DevExt->CancelSafeIoQueue,NULL);

        //
        // See if we got an IRP.   If not, then we exit.
        //
        if(!irp) {

            OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_READWRITE, 
                ("ProcessNextIrpInQueue Exit No Irps in Queue\n"));
            return;
        }

        //
        // Got an IRP, submit it to the Device Below us.
        //
        (VOID)IoCallDriver(DevExt->DeviceToSendIrpsTo,irp);

    }

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_READWRITE, ("ProcessNextIrpInQueue Exit...\n"));

    return;
}

///////////////////////////////////////////////////////////////////////////////
//
// UsbFx2LkRead
//
//  This routine is called by the IO Manager to process a IRP_MJ_READ
//  Irp.
//
//
//  INPUTS:
//
//      DeviceObject  -  One of our Device Objects.
//      Irp  -  The Irp to process.
//
//  OUTPUTS:
//
//      None
//
//  RETURNS:
//
//      STATUS_PENDING, or an ERROR.  
//
//  IRQL:
//
//      IRQL == PASSIVE_LEVEL
//
//  CONTEXT:
//
//      User Context
//
//  NOTES:
//
//      READ requests are always serviced by the bulk input pipe
//
///////////////////////////////////////////////////////////////////////////////
NTSTATUS UsbFx2LkRead(PDEVICE_OBJECT DeviceObject,PIRP Irp)
{
    PUSBFX2LK_EXT           devExt = (PUSBFX2LK_EXT)DeviceObject->DeviceExtension;
    PIO_STACK_LOCATION      ioStack = IoGetCurrentIrpStackLocation(Irp);
    KIRQL                   oldIrql;
    PUSBFX2LK_IO_CONTEXT    pFx2Context = NULL;
    NTSTATUS                status;
    PMDL                    pMdl = NULL;
    ULONG                   totalLength = 0;
    ULONG                   urbFlags = 0;
    PUCHAR                  virtualAddress = 0;
    ULONG                   stageLength = 0;
    PURB                    urb = NULL;
    PIO_STACK_LOCATION      nextStack = IoGetNextIrpStackLocation(Irp);

    //
    // We should never be here and not at PASSIVE_LEVEL
    //
    ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);

    //
    // Major issue is we haven't setup our bulk input pipe yet
    //
    ASSERT(devExt->BulkInPipe);

    OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_READWRITE, ("UsbFx2LkRead Entered...\n"));

    //
    // Increment the number of outstanding IOs queued to the device.
    //
    OsrIncrementOutstandingIoCount(devExt,__FILE__,__LINE__);


    //
    // See what sort of state we're in. 
    //
    KeAcquireSpinLock(&devExt->IoStateLock,&oldIrql);
    if (devExt->DevicePnPState < STATE_ALL_BELOW_FAIL) {

        KeReleaseSpinLock(&devExt->IoStateLock,oldIrql);
        OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_READWRITE, 
                ("UsbFx2LkRead: Failing  request due to Pnp State! Current PnP state - %s\n",
                  OsrPrintState(devExt)));

        status = STATUS_INVALID_DEVICE_STATE;
        goto UsbFx2LkRead_Exit;
    }
    KeReleaseSpinLock(&devExt->IoStateLock,oldIrql);

    //
    // We do not support zero length operations in this driver
    //
    if(!ioStack->Parameters.Read.Length || !Irp->MdlAddress) {

        OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_READWRITE, 
                ("UsbFx2LkRead: Invalid Parameters to READ \n"));

        status = STATUS_INVALID_PARAMETER;
        goto UsbFx2LkRead_Exit;
    }


    //
    // Get the total length of the transfer we are asked to perform.
    //
    totalLength = ioStack->Parameters.Read.Length;

    //
    // See if the transfer length is greater than the maximum packet
    //  size of the pipe * the amount of buffering that the firmware
    //  provides. If the transfer is too large, we will reject it here
    //  without further processing
    //
    if(totalLength > 
            (ULONG)(devExt->BulkInPipe->PipeInformation.MaximumPacketSize * \
                                        USBFX2LK_BULK_TRANSFER_FW_BUFFERING)) {

        OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_READWRITE,
            ("UsbFx2LkRead: Length exceeds %d\n", 
            devExt->BulkInPipe->PipeInformation.MaximumPacketSize * USBFX2LK_BULK_TRANSFER_FW_BUFFERING));

        status = STATUS_INVALID_PARAMETER;
        goto UsbFx2LkRead_Exit;
    }

    //
    // Allocate a USBFX2 I/O context. This is a driver specific
    //  structure that we'll use to contain all the necessary
    //  information about this particular request while we
    //  own that request
    //
    pFx2Context = (PUSBFX2LK_IO_CONTEXT) ExAllocatePoolWithTag(NonPagedPool,sizeof(USBFX2LK_IO_CONTEXT),'ciuO');

    if(pFx2Context == NULL) {
        OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_READWRITE,
            ("UsbFx2LkRead: Failed to allocate IO Context\n"));
        status = STATUS_INSUFFICIENT_RESOURCES;
        goto UsbFx2LkRead_Exit;
    }

    //
    // Get the user's base virtual address from the MDL. This
    //  will be used as a cookie to indicate what area of the 
    //  user's data buffer we are currently copying data into
    //
    virtualAddress = (PUCHAR) MmGetMdlVirtualAddress(Irp->MdlAddress);

    //
    // the transfer request is for totalLength. We can perform a maximum of
    // the bulk input pipe's PipeInformation.MaximumPacketSize in each stage.
    //
    pFx2Context->MaxmimumStageSize = devExt->BulkInPipe->PipeInformation.MaximumPacketSize;

    if(totalLength > devExt->BulkInPipe->PipeInformation.MaximumPacketSize) {
        //
        // Total length is bigger that we can send, so we will break up
        // the transfer into smaller pieces.
        //
        stageLength = pFx2Context->MaxmimumStageSize;
    } else {
        //
        // We can send this packet in one transfer.
        //
        stageLength = totalLength;
    }

    //
    // We asked the I/O manager to supply reads and writes from user
    //  mode components in the form of MDLs by setting the DO_DIRECT_IO
    //  bit in our device object during AddDevice. This will result in
    //  the I/O manager sending our driver MDLs that describe the entire
    //  length of the user's buffer for the entire operation.
    //
    // However, we may need to split this single user transfer up
    //  into multiple "stages" so that we don't send our device
    //  I/O operations that exceed the maximum supported single 
    //  transfer size. To do this, we will build what are called
    //  "partial MDLs" that describe only the portion of the user's
    //  data buffer that we will be transferring at each individual
    //  stage. 
    //
    // The first step in building partial MDLs will be allocating 
    //  a new MDL that is large enough to describe the passed in MDL.
    //  
    pMdl = IoAllocateMdl((PVOID)virtualAddress,
                         totalLength,
                         FALSE,
                         FALSE,
                         NULL);

    if(pMdl == NULL) {
        OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_READWRITE,("UsbFx2LkRead: Failed to Allocate Mdl\n"));
        status = STATUS_INSUFFICIENT_RESOURCES;
        ExFreePool(pFx2Context);
        goto UsbFx2LkRead_Exit;
    }

    //
    // Now, build a partial MDL out of the newly allocated 
    //  MDL. This will map the first stageLength bytes of
    //  the MDL in the IRP into the newly allocated MDL
    //
    IoBuildPartialMdl(Irp->MdlAddress,
                      pMdl,
                      (PVOID)virtualAddress,
                      stageLength);

    //
    // Allocate an URB to be used for the transfer.
    //
    urb = (PURB) ExAllocatePoolWithTag(NonPagedPool,sizeof(URB),'bruO');

    if(urb == NULL) {
        OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_READWRITE,("UsbFx2LkRead: Failed to allocate URB\n"));
        status = STATUS_INSUFFICIENT_RESOURCES;
        ExFreePool(pFx2Context);
        IoFreeMdl(pMdl);
        goto UsbFx2LkRead_Exit;
    }

    //
    // Build the Transfer URB.
    //

    //
    // Indicate that this is a read function and that we will allow short
    // transfers of data.
    //
    urbFlags = USBD_SHORT_TRANSFER_OK | USBD_TRANSFER_DIRECTION_IN;

    UsbBuildInterruptOrBulkTransferRequest(
                            urb,
                            sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER),
                            devExt->BulkInPipe->PipeInformation.PipeHandle,
                            NULL,
                            pMdl,
                            stageLength,

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
狠狠色狠狠色综合系列| 欧美三级一区二区| 91福利社在线观看| 精品福利二区三区| 亚洲自拍欧美精品| 国产成人在线影院| 日韩欧美一区在线| 亚洲一区二区三区四区五区中文| 国产麻豆9l精品三级站| 欧美群妇大交群的观看方式| 中文字幕在线免费不卡| 国产制服丝袜一区| 日韩一区二区在线看| 亚洲福利一二三区| 色乱码一区二区三区88| 中文字幕精品在线不卡| 国产精品一区免费视频| 久久亚洲精华国产精华液| 美女尤物国产一区| 538在线一区二区精品国产| 一区二区三区在线高清| 91片在线免费观看| 国产精品电影一区二区三区| 高清免费成人av| 国产欧美一区二区精品性色超碰| 久草在线在线精品观看| 欧美成人欧美edvon| 青青草国产精品亚洲专区无| 欧美久久久久免费| 五月综合激情网| 91精彩视频在线观看| 亚洲精品国产a久久久久久| 成人av电影在线网| 亚洲色图视频网| 色综合久久久久网| 一区二区三区日本| 制服丝袜亚洲色图| 美女视频一区二区| 国产亚洲va综合人人澡精品| 成人自拍视频在线| 亚洲欧洲无码一区二区三区| 91一区二区三区在线观看| 亚洲欧美日韩一区二区三区在线观看| 91视频精品在这里| 亚洲成年人影院| 欧美高清激情brazzers| 奇米888四色在线精品| 日韩精品一区二区三区在线观看| 国产专区综合网| 18欧美亚洲精品| 宅男噜噜噜66一区二区66| 美女性感视频久久| 欧美经典一区二区三区| 日本韩国一区二区三区视频| 亚洲成国产人片在线观看| 日韩丝袜情趣美女图片| 丁香婷婷深情五月亚洲| 亚洲精选一二三| 欧美一区日本一区韩国一区| 国内精品国产成人国产三级粉色 | 精品亚洲国产成人av制服丝袜| 欧美videossexotv100| 99综合电影在线视频| 一区二区视频在线看| 91精品国产色综合久久不卡电影| 韩国女主播一区| 亚洲乱码中文字幕综合| 精品免费国产二区三区| a级高清视频欧美日韩| 婷婷综合五月天| 国产精品日韩精品欧美在线| 欧美日韩美少妇| 国产精品99久久久久久有的能看| 一区二区三区在线免费观看 | 国产欧美中文在线| 欧美亚州韩日在线看免费版国语版| 麻豆91在线播放| 亚洲精品一二三区| 久久久99精品免费观看不卡| 欧美日韩免费一区二区三区| 成人美女视频在线观看18| 日韩电影在线观看网站| 亚洲码国产岛国毛片在线| 精品日韩av一区二区| 色综合激情久久| 国产黄色成人av| 蜜臀a∨国产成人精品| 亚洲自拍偷拍九九九| 国产精品高清亚洲| 久久久久久久久一| 日韩欧美区一区二| 欧美日韩一级二级三级| heyzo一本久久综合| 国产一区二区成人久久免费影院 | 亚洲国产一区二区在线播放| 国产欧美精品一区| 欧美精品一区二区三区在线| 欧美日韩国产系列| 日本黄色一区二区| 色综合久久久久综合| 9久草视频在线视频精品| 国产91精品一区二区麻豆亚洲| 青青草国产精品97视觉盛宴| 亚洲精品久久嫩草网站秘色| 亚洲青青青在线视频| 中文字幕亚洲区| 国产精品天美传媒| 欧美极品aⅴ影院| 亚洲国产精品成人综合| 国产精品久久综合| 国产精品激情偷乱一区二区∴| 久久精品视频一区二区三区| 国产日韩欧美a| 国产精品婷婷午夜在线观看| 国产精品动漫网站| 亚洲视频在线一区| 亚洲一区二区三区四区五区中文 | 亚洲欧洲一区二区在线播放| 综合av第一页| 亚洲人亚洲人成电影网站色| 亚洲美女视频一区| 亚洲成人激情av| 久久精品国产精品亚洲精品| 精品一区免费av| 精品影视av免费| 国产成人精品免费| 一本一道久久a久久精品| 欧美在线免费播放| 91精品欧美久久久久久动漫 | 欧美一区二区大片| 欧美不卡视频一区| 中国av一区二区三区| 亚洲精品一二三四区| 天天色综合成人网| 九九在线精品视频| 成人av免费网站| 在线电影欧美成精品| 久久网站热最新地址| 亚洲色图一区二区| 日本午夜一区二区| 成人一区二区三区在线观看| 一本久久a久久免费精品不卡| 欧美老女人在线| 久久噜噜亚洲综合| 一区二区三区成人| 精品系列免费在线观看| 97se狠狠狠综合亚洲狠狠| 欧美老年两性高潮| 久久久精品tv| 亚洲最色的网站| 激情综合一区二区三区| 99久久er热在这里只有精品15| 欧美久久婷婷综合色| 国产精品欧美一区二区三区| 午夜精品福利一区二区蜜股av| 国产精品资源在线看| 欧美色图一区二区三区| 国产日韩精品一区二区三区在线| 亚洲国产日韩精品| 国产91精品一区二区麻豆亚洲| 在线精品观看国产| 久久精品水蜜桃av综合天堂| 亚洲精品国久久99热| 日韩高清欧美激情| 91丨porny丨在线| 久久久av毛片精品| 午夜激情一区二区| av不卡免费在线观看| 精品精品国产高清a毛片牛牛 | 自拍偷自拍亚洲精品播放| 麻豆国产一区二区| 欧美日韩亚洲综合一区二区三区| 国产欧美一区在线| 美脚の诱脚舐め脚责91| 欧美在线你懂得| 成人欧美一区二区三区1314| 激情偷乱视频一区二区三区| 911精品产国品一二三产区| 成人欧美一区二区三区白人| 粉嫩av一区二区三区粉嫩 | 4hu四虎永久在线影院成人| 亚洲同性gay激情无套| 国产精品资源站在线| 欧美mv和日韩mv国产网站| 蜜乳av一区二区三区| 欧美女孩性生活视频| 一区二区三区美女视频| 91视频精品在这里| 亚洲人成在线观看一区二区| 丰满岳乱妇一区二区三区| www欧美成人18+| 国内不卡的二区三区中文字幕| 日韩免费一区二区| 麻豆freexxxx性91精品| 欧美成人高清电影在线| 久久国产精品色婷婷| 欧美成人vps| 国产一区二区视频在线播放| 欧美mv日韩mv亚洲| 国产在线精品不卡|