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

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

?? intrwr.c

?? 在PC上通過USB與C8051通信
?? C
?? 第 1 頁 / 共 2 頁
字號:
 /*++


Module Name:

    intrwr.c

Abstract:

    This file has routines to perform reads and writes.
    The read and writes are for int transfers.

Environment:

    Kernel mode

Notes:

    
--*/

#include "intusb.h"
#include "intpnp.h"
#include "intpwr.h"
#include "intdev.h"
#include "intrwr.h"
#include "intwmi.h"
#include "intusr.h"


///////////////////////////////////////////////////////////////////////////////

//#pragma PAGEDCODE
#pragma LOCKEDCODE

NTSTATUS 
CreateInterruptUrbIN(
	IN PDEVICE_OBJECT DeviceObject
	)
/*++
 
Routine Description:

    Create the input URB Polling Interrupt.

Arguments:

    DeviceObject - pointer to DeviceObject
    
Return Value:

    NT status value

--*/
	{							// CreateInterruptUrb
	PIRP IrpIN;
	PURB urbIN;
	PDEVICE_EXTENSION      deviceExtension;
	KdPrint( (DRIVERNAME " - CreateInterruptUrbIN - begins %8.8lX\n"));

	deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
	ASSERT(deviceExtension->PollingIrpIN == NULL);
	ASSERT(deviceExtension->PollingUrbIN == NULL);

	IrpIN = IoAllocateIrp(deviceExtension->TopOfStackDeviceObject->StackSize, FALSE);
	if (!IrpIN)
		{
		KdPrint((DRIVERNAME " - Unable to create IRP for interrupt polling\n"));
		return STATUS_INSUFFICIENT_RESOURCES;
		}

	urbIN = (PURB) ExAllocatePool(NonPagedPool, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER));
	if (!urbIN)
		{
		KdPrint((DRIVERNAME " - Unable to allocate interrupt polling URB\n"));
		IoFreeIrp(IrpIN);
		return STATUS_INSUFFICIENT_RESOURCES;
		}
	
	deviceExtension->PollingIrpIN = IrpIN;
	deviceExtension->PollingUrbIN = urbIN;
	
	return STATUS_SUCCESS;
	}							// CreateInterruptUrb


///////////////////////////////////////////////////////////////////////////////

#pragma PAGEDCODE

VOID 
DeleteInterruptUrbIN(
	IN PDEVICE_OBJECT DeviceObject
	)
/*++
 
Routine Description:

    Delete the input URB Polling Interrupt.

Arguments:

    DeviceObject - pointer to DeviceObject
    
Return Value:

    NT status value

--*/
	{							// DeleteInterruptUrb
	PDEVICE_EXTENSION deviceExtension;

	KdPrint( (DRIVERNAME " - DeleteInterruptUrbIN - begins %8.8lX\n"));

	deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
	ASSERT(deviceExtension->PollingIrpIN != NULL);
	ASSERT(deviceExtension->PollingUrbIN != NULL);
	
	ExFreePool(deviceExtension->PollingUrbIN);
	IoFreeIrp(deviceExtension->PollingIrpIN);
	deviceExtension->PollingIrpIN = NULL;
	deviceExtension->PollingUrbIN = NULL;
	
	}							// DeleteInterruptUrb


///////////////////////////////////////////////////////////////////////////////

#pragma LOCKEDCODE

NTSTATUS 
StartInterruptUrbIN(
	IN PDEVICE_EXTENSION deviceExtension
	)
/*++
 
Routine Description:

    Submit the Polling IRP with associated URB to the bus driver.
	The URB is formatted for an 8 byte transfer on the interrupt 
	intput pipe.

Arguments:

    deviceExtension - Pointer to the device Extension

Return Value:

    NT status value

--*/
	{							// StartInterruptUrb

	NTSTATUS ReturnStatus;
	BOOLEAN startirp;
	KIRQL oldirql;
	PIRP IrpIN;
	PURB urbIN;
	NTSTATUS status;
	PIO_STACK_LOCATION stackIN;

	//KdPrint( (DRIVERNAME " - StartInterruptUrbIN - begins %8.8lX\n"));
	
	// Check to see if a Poll is already pending before submitting 
	// request to the bus.

	KeAcquireSpinLock(&deviceExtension->polllock, &oldirql);
	if (deviceExtension->pollpending)
		startirp = FALSE;
	else
		startirp = TRUE, deviceExtension->pollpending = TRUE;
	KeReleaseSpinLock(&deviceExtension->polllock, oldirql);

	if (!startirp)
		return STATUS_DEVICE_BUSY;	// already pending

	IrpIN = deviceExtension->PollingIrpIN;
	urbIN = deviceExtension->PollingUrbIN;
	ASSERT(IrpIN && urbIN);
	
	// Acquire the remove lock the device cannot be removed while the IRP
	// is active.

	status = IoAcquireRemoveLock(&deviceExtension->RemoveLock, IrpIN);
	if (!NT_SUCCESS(status))
		{
		deviceExtension->pollpending = 0;
		return status;
		}

	// Initialize the URB we use for reading the interrupt pipe

	deviceExtension->hintpipeIN = deviceExtension->UsbInterface->Pipes[0].PipeHandle;

	UsbBuildInterruptOrBulkTransferRequest(urbIN, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER),
		deviceExtension->hintpipeIN, &deviceExtension->intdataIN, NULL, 8, USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK, NULL);

	// Install "OnInterruptIN" as the completion routine for the polling IRP.
	
	IoSetCompletionRoutine(IrpIN, (PIO_COMPLETION_ROUTINE) OnInterruptIN, deviceExtension, TRUE, TRUE, TRUE);

	// Initialize the IRP for an internal control request

	stackIN = IoGetNextIrpStackLocation(IrpIN);
	stackIN->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
	stackIN->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
	stackIN->Parameters.Others.Argument1 = urbIN;

	// Make sure the Cancel Flag is cleared

	IrpIN->Cancel = FALSE;

	status = IoCallDriver(deviceExtension->TopOfStackDeviceObject, IrpIN);
	
	return status;
	}							// StartInterruptUrb


///////////////////////////////////////////////////////////////////////////////

#pragma LOCKEDCODE
	
VOID 
StopInterruptUrbIN(
	IN PDEVICE_EXTENSION deviceExtension
	)
/*++
 
Routine Description:

    This routine cancels the Polling IRP

Arguments:

    deviceExtension - Pointer to the device Extension


--*/
	{							// StopInterruptUrb

	KdPrint( (DRIVERNAME " - StopInterruptUrbIN - begins %8.8lX\n"));
	
	if (deviceExtension->pollpending)
		IoCancelIrp(deviceExtension->PollingIrpIN);
	}							// StopInterruptUrb

///////////////////////////////////////////////////////////////////////////////



#pragma LOCKEDCODE

NTSTATUS 
OnInterruptIN(
	IN PDEVICE_OBJECT junk, 
	IN PIRP IrpIN, 
	IN PDEVICE_EXTENSION deviceExtension
	)
/*++
 
Routine Description:

    This routine is the completion routine for the Polling IRP submitted in
	the StartInterruptIN routine. If the IRP was successful this routine will
	transfer the input data to the Application by means of an IO Control request.
	An the IO Control request must already be submitted and outstanding before this 
	routine is called in order to be serviced.

Arguments:

    DeviceObject - pointer to DeviceObject
    IrpIN - Polling input pipe Irp to be serviced.
	deviceExtension - Pointer to the device Extension

Return Value:

    NT status value

--*/
	{							// OnInterrupt

	KIRQL oldirql;
	PVOID powercontext;
	PIRP intirpIN;
	IO_REMOVE_LOCK localRemoveLock;
	UCHAR localBuffer[12];
	
	//KdPrint( (DRIVERNAME " - OnInterruptIN - begins %8.8lX\n"));
	
	KeAcquireSpinLock(&deviceExtension->polllock, &oldirql);
	deviceExtension->pollpending = FALSE;		// allow another poll to be started
	powercontext = deviceExtension->powercontext;
	deviceExtension->powercontext = NULL;
	KeReleaseSpinLock(&deviceExtension->polllock, oldirql);

	// If the poll completed successfully,answer the IOCTL request sent by the Windows
	// application and reissue the read. We're trying to have a read outstanding on the
	// interrupt pipe when the device is running.

	if (NT_SUCCESS(IrpIN->IoStatus.Status))
		{						// an interrupt has occurred
		//KdPrint((DRIVERNAME " - Interrupt IN!\n"));

		intirpIN = UncacheReadRequest(deviceExtension, &deviceExtension->InterruptIrp);
		if (intirpIN)
		{
			// Exchange data between the Polling URB and the Servicing IRP
			RtlCopyMemory(&(localBuffer[8]), &deviceExtension->numintsIN,4);
			RtlCopyMemory(&localBuffer, &deviceExtension->intdataIN,8);
			RtlCopyMemory(intirpIN->AssociatedIrp.SystemBuffer,&localBuffer,12);
			
			// Complete the request and indicate a length
			// of 12 bytes in the information field.
			
        	CompleteRequest(intirpIN, STATUS_SUCCESS, 12);
		}
		else
			// Interrupt occurred but was not serviced
			InterlockedIncrement(&deviceExtension->numintsIN);

		// Reissue the polling IRP. 
		StartInterruptUrbIN(deviceExtension); // issue next polling request
		}						// device signalled an interrupt
#if DBG	
	else
		{
		KdPrint((DRIVERNAME " - Interrupt polling IRP IN %X failed - %X (USBD status %X)\n",
			IrpIN, IrpIN->IoStatus.Status, URB_STATUS(deviceExtension->PollingUrbIN)));
		}
#endif

	// Release RemoveLock which was acquired in StartInterruptUrbIN
	IoReleaseRemoveLock(&deviceExtension->RemoveLock, IrpIN); 

	return STATUS_MORE_PROCESSING_REQUIRED;
	}							// OnInterrupt



///////////////////////////////////////////////////////////////////////////////

#pragma LOCKEDCODE

NTSTATUS 
CompleteRequest(
	IN PIRP Irp, 
	IN NTSTATUS status, 
	IN ULONG_PTR info
	)
/*++
 
Routine Description:

    Complete the Request with no priority boost since we are not waiting on IO.

Arguments:

    Irp - IRP to be completed
	status - IRP completion status
	info - information associated with the IRP

Return Value:

    NT status value

--*/
{							
	Irp->IoStatus.Status = status;
	Irp->IoStatus.Information = info;
	IoCompleteRequest(Irp, IO_NO_INCREMENT);
	return status;
}							


PINTUSB_PIPE_CONTEXT
IntUsb_PipeWithName(
    IN PDEVICE_OBJECT  DeviceObject,
    IN PUNICODE_STRING FileName
    )
/*++
 
Routine Description:

    This routine will pass the string pipe name and
    fetch the pipe number.

Arguments:

    DeviceObject - pointer to DeviceObject
    FileName - string pipe name

Return Value:

    The device extension maintains a pipe context for 
    the pipes on the board.
    This routine returns the pointer to this context in
    the device extension for the "FileName" pipe.

--*/
{
    LONG                  ix;
    ULONG                 uval; 
    ULONG                 nameLength;
    ULONG                 umultiplier;
    PDEVICE_EXTENSION     deviceExtension;
    PINTUSB_PIPE_CONTEXT pipeContext;

    //
    // initialize variables
    //
    pipeContext = NULL;
    //
    // typedef WCHAR *PWSTR;
    //
    nameLength = (FileName->Length / sizeof(WCHAR));
    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;

    KdPrint( ("IntUsb_PipeWithName - begins\n"));

    if(nameLength != 0) {
    
        KdPrint( ("Filename = %ws nameLength = %d\n", FileName->Buffer, nameLength));

        //
        // Parse the pipe#
        //
        ix = nameLength - 1;

        // if last char isn't digit, decrement it.
        while((ix > -1) &&
              ((FileName->Buffer[ix] < (WCHAR) '0')  ||
               (FileName->Buffer[ix] > (WCHAR) '9')))             {

            ix--;
        }

        if(ix > -1) {

            uval = 0;
            umultiplier = 1;

            // traversing least to most significant digits.

            while((ix > -1) &&
                  (FileName->Buffer[ix] >= (WCHAR) '0') &&
                  (FileName->Buffer[ix] <= (WCHAR) '9'))          {
        
                uval += (umultiplier *
                         (ULONG) (FileName->Buffer[ix] - (WCHAR) '0'));

                ix--;
                umultiplier *= 10;
            }
        }

        if(uval < 6 && deviceExtension->PipeContext) {
        
            pipeContext = &deviceExtension->PipeContext[uval];
        }
    }

    KdPrint( ("IntUsb_PipeWithName - ends\n"));

    return pipeContext;
}

NTSTATUS
IntUsb_DispatchWrite(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp
    )
/*++
 
Routine Description:

    Dispatch routine for write.
    This routine creates a INTUSB_RW_CONTEXT for a write.
    The write is performed in a single 8 byte transfer.

Arguments:

    DeviceObject - pointer to device object
    Irp - I/O request packet

Return Value:

    NT status value

--*/
{
    PURB                   urb;
    ULONG                  Length;
    ULONG                  urbFlags;
    BOOLEAN                read;
    NTSTATUS               ntStatus;
    PFILE_OBJECT           fileObject;
    PDEVICE_EXTENSION      deviceExtension;
    PIO_STACK_LOCATION     irpStack;
    PIO_STACK_LOCATION     nextStack;
    PINTUSB_RW_CONTEXT    rwContext;
    PUSBD_PIPE_INFORMATION pipeInformation;
	PIO_STACK_LOCATION		IrpStack;

    //
    // initialize variables
    //
    urb = NULL;
    rwContext = NULL;
    Length = 0;
    irpStack = IoGetCurrentIrpStackLocation(Irp);
    fileObject = irpStack->FileObject;
    read = (irpStack->MajorFunction == IRP_MJ_READ) ? TRUE : FALSE;
    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
	IrpStack = IoGetCurrentIrpStackLocation(Irp);
	urbFlags = USBD_SHORT_TRANSFER_OK;
	

    KdPrint( ("IntUsb_DispatchReadWrite - begins\n"));
	
	

    if(deviceExtension->DeviceState != Working) {

        KdPrint( ("Invalid device state\n"));

        ntStatus = STATUS_INVALID_DEVICE_STATE;
        goto IntUsb_DispatchReadWrite_Exit;
    }

    //
    // It is true that the client driver cancelled the selective suspend
    // request in the dispatch routine for create Irps.
    // But there is no guarantee that it has indeed completed.
    // so wait on the NoIdleReqPendEvent and proceed only if this event
    // is signalled.
    //
    KdPrint( ("Waiting on the IdleReqPendEvent\n"));

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线视频一区二区三| 蜜桃av噜噜一区| 91麻豆国产香蕉久久精品| 中文字幕一区免费在线观看| 91免费在线看| 天天影视色香欲综合网老头| 日韩一区二区三区电影| 国产一区二区精品久久| 国产精品美女久久久久久2018 | 老司机午夜精品| xvideos.蜜桃一区二区| 成人国产电影网| 亚洲图片一区二区| 日韩亚洲欧美成人一区| 国产乱理伦片在线观看夜一区| 国产欧美一区二区精品忘忧草| 色综合久久综合网欧美综合网| 亚洲电影你懂得| 久久伊人蜜桃av一区二区| 国产91高潮流白浆在线麻豆| 一区二区三区在线视频观看58 | 99久久精品国产一区二区三区| 一区二区三区四区高清精品免费观看| 欧美精品高清视频| 成人综合婷婷国产精品久久| 亚洲综合一二区| 2024国产精品视频| 在线视频你懂得一区| 国产一区二区三区在线观看免费视频| 亚洲丝袜制服诱惑| 亚洲精品一区二区精华| 在线这里只有精品| 国产美女精品一区二区三区| 夜夜亚洲天天久久| 国产欧美日韩综合精品一区二区| 欧美日韩一二区| 成人综合婷婷国产精品久久蜜臀| 日韩高清不卡在线| 亚洲欧洲一区二区三区| 337p日本欧洲亚洲大胆精品| 在线视频一区二区三| 成人在线视频首页| 蜜桃视频一区二区三区 | 国产日本一区二区| 在线精品国精品国产尤物884a| 国产乱码字幕精品高清av| 亚洲线精品一区二区三区| 国产精品午夜在线观看| 日韩片之四级片| 欧美三级电影网| 91小视频免费看| 成人自拍视频在线观看| 久久国产精品第一页| 亚洲电影欧美电影有声小说| 亚洲色图20p| 国产精品入口麻豆九色| 26uuu亚洲综合色| 日韩欧美一区在线| 欧美日韩一区二区三区四区五区 | 99re成人在线| 国产一区二区三区免费在线观看| 日韩精品乱码免费| 日韩国产精品久久久| 亚洲电影你懂得| 亚洲一区二区免费视频| 亚洲激情中文1区| **性色生活片久久毛片| 国产精品妹子av| 国产亚洲va综合人人澡精品| 精品国产乱码久久久久久蜜臀| 欧美一区二区久久久| 欧美一区二区三区婷婷月色| 欧美久久一区二区| 欧美日韩国产欧美日美国产精品| 欧美影院一区二区| 欧美在线999| 欧美另类久久久品| 欧美放荡的少妇| 日韩一区二区在线观看视频| 日韩欧美国产一区二区三区| 日韩欧美中文字幕制服| 日韩欧美久久一区| 久久众筹精品私拍模特| 国产欧美日韩三区| 中文字幕亚洲视频| 夜夜揉揉日日人人青青一国产精品| 一区二区三区波多野结衣在线观看| 亚洲综合一区二区三区| 日韩av一区二区在线影视| 久久精品国产久精国产爱| 国产美女精品人人做人人爽| 国产成人综合自拍| 99热在这里有精品免费| 欧洲激情一区二区| 91精品国产91久久久久久一区二区| 日韩欧美综合一区| 欧美极品xxx| 亚洲视频小说图片| 日韩高清在线一区| 韩国视频一区二区| 91一区一区三区| 欧美精品三级日韩久久| 精品国产免费一区二区三区四区 | 欧美成人三级电影在线| 精品99999| 中文字幕中文在线不卡住| 亚洲综合色区另类av| 美女久久久精品| 成人精品视频一区二区三区| 色婷婷久久久亚洲一区二区三区 | 成人午夜av在线| 日韩一区二区三区在线| 久久日一线二线三线suv| 国产精品第13页| 免费在线视频一区| 成人av在线一区二区| 7777精品伊人久久久大香线蕉的| 久久精品日产第一区二区三区高清版| 亚洲女同女同女同女同女同69| 日韩av电影免费观看高清完整版| 丰满放荡岳乱妇91ww| 欧美日韩国产高清一区二区三区 | 91亚洲精品一区二区乱码| 欧美丰满少妇xxxbbb| 中文字幕制服丝袜一区二区三区 | 蜜臀av一级做a爰片久久| 不卡一区二区在线| 日韩一区二区免费在线电影| 中文字幕在线观看不卡| 美腿丝袜一区二区三区| 91高清视频免费看| 欧美国产日韩一二三区| 蜜桃视频免费观看一区| 91成人免费在线视频| 亚洲国产精品传媒在线观看| 蜜臀av性久久久久蜜臀aⅴ| 色又黄又爽网站www久久| 国产亚洲人成网站| 日韩国产欧美一区二区三区| 91视频免费观看| 国产午夜精品福利| 久久精品二区亚洲w码| 欧美写真视频网站| 亚洲男人的天堂在线aⅴ视频| 国产精品综合一区二区| 欧美一区二区黄色| 亚洲成a天堂v人片| 色诱亚洲精品久久久久久| 亚洲国产精品ⅴa在线观看| 国内国产精品久久| 日韩美一区二区三区| 亚洲1区2区3区视频| 欧美亚洲国产bt| 亚洲图片激情小说| 不卡的av电影| 国产精品无圣光一区二区| 国产成人亚洲综合a∨婷婷图片| 日韩精品一区二区三区swag| 日本不卡一区二区三区高清视频| 欧美日本国产一区| 亚洲chinese男男1069| 欧美在线一区二区| 亚洲第一久久影院| 欧美精品黑人性xxxx| 视频一区视频二区中文字幕| 7777精品久久久大香线蕉 | 久久婷婷色综合| 国产精品综合二区| 国产日韩高清在线| 成人av网站在线观看免费| 国产精品三级久久久久三级| av日韩在线网站| 亚洲男人的天堂网| 欧美日韩综合不卡| 美女免费视频一区| 久久久一区二区| 在线观看日韩一区| 亚洲欧洲日产国产综合网| 91在线视频播放| 亚洲第一综合色| 精品少妇一区二区三区免费观看 | 中文字幕一区二区视频| 色综合久久久久综合99| 亚洲一区在线观看网站| 欧美久久一区二区| 黑人巨大精品欧美黑白配亚洲| 国产三级一区二区| 91视频你懂的| 日韩二区在线观看| 久久精品视频一区| 色94色欧美sute亚洲线路一ni| 亚洲成人动漫一区| 久久午夜电影网| 色欧美乱欧美15图片| 日本不卡一区二区三区| 久久久91精品国产一区二区精品 | 欧美tickle裸体挠脚心vk| 国产成人av一区| 亚洲乱码国产乱码精品精可以看| 69堂精品视频|