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

📄 test98.c

📁 usb开发的资料!!USB标准
💻 C
字号:
// ===================================================================

//

//

//      test98.c

//

//      rev 1.0 beta

//

//      USB device driver for USB Device Example as depicted in

//      the book "Developing USB PC Peripherals" 

//

//      kernel mode driver 

//

//      author  : Wooi Ming Tan 

//      date    : 31 May 98

//

//      test98.c  - main module containing DriverEntry routine 

//      testpnp.c - handles USB PnP and power IRPs

//      testusb.c - handles some USB IRPs         

//

//      developed under  

//      - Windows 98 Beta 3 DDK environment 

//      - users can create and copy to \98DDK\src\usb\test98\sys directory

//     

//      NOTE:

//      The driver (testdrv.sys) generated by the codes (test98.c, testpnp.c and 

//      testusb.c) has been tested under a few Windows 98 Beta 3 systems.   

//      The driver has been made compatible with the applications software and 

//      device firmware supplied with the book "Developing USB PC Peripherals".

//      For more information on the code examples, please also refer to 

//      Chapter 8 "USB Application Software, WDM Driver, and Firmware Examples" 

//      of the book.

//

//      The author would also like to thank Kenneth Ray for his

//      advice on revising the code.

//

//

// ==============================================================================



#include <wdm.h>

#include <initguid.h>



#include "test98.h"

#include "stdio.h"

#include "testdrv.h"



NTSTATUS DriverEntry (PDRIVER_OBJECT, PUNICODE_STRING);



NTSTATUS

DriverEntry (

    IN  PDRIVER_OBJECT  DriverObject,

    IN  PUNICODE_STRING UniRegistryPath

    )

/*

    Entry point for the loading of the drivr.   



*/

{

    PDEVICE_OBJECT  device;



    UNREFERENCED_PARAMETER (UniRegistryPath);



    DriverObject->MajorFunction [IRP_MJ_CREATE] =

    DriverObject->MajorFunction [IRP_MJ_CLOSE]  = Test_Create;  

    

    // routines to handle system PnP and power management reqeusts 

    DriverObject->MajorFunction [IRP_MJ_PNP]    = Test98_PnP;

    DriverObject->MajorFunction [IRP_MJ_POWER]  = Test98_Power;

    

    // handles user mode DeviceIoControl() calls

    DriverObject->MajorFunction [IRP_MJ_DEVICE_CONTROL] = Test_ProcessIOCTL;

    

    DriverObject->DriverUnload = Test98_DriverUnload;

    

    // called when device plug-in to reat Funtional Device Object (FDO) 

    DriverObject->DriverExtension->AddDevice = Test98_AddDevice;

    

    DriverObject->MajorFunction[IRP_MJ_WRITE] = Test_Write;

    DriverObject->MajorFunction[IRP_MJ_READ] = Test_Read;



    return STATUS_SUCCESS;

}



// =======================================================================

VOID

Test98_DriverUnload (

    IN PDRIVER_OBJECT Driver

    )

/*

        to clean up the stuff we did in driver entry.



*/

{

    UNREFERENCED_PARAMETER (Driver);

    PAGED_CODE();



    ASSERT (NULL == Driver->DeviceObject);



    //

    // Here we free any resources allocated in DriverEntry

    //



    return;

}



// =======================================================================

VOID

Test98_DecIoCount (

    PFDO_DEVICE_DATA Data

    )

{

    if (0 == InterlockedDecrement (&Data->OutstandingIO)) {

        KeSetEvent (&Data->RemoveEvent, 0, FALSE);

    }

}



// =======================================================================

NTSTATUS

Test98_IncIoCount (

    PFDO_DEVICE_DATA Data

    )

{

    InterlockedIncrement (&Data->OutstandingIO);

    if (Data->Removed) {



        if (0 == InterlockedDecrement (&Data->OutstandingIO)) {

            KeSetEvent (&Data->RemoveEvent, 0, FALSE);

        }

        return STATUS_DELETE_PENDING;

    }

    return STATUS_SUCCESS;

}



⌨️ 快捷键说明

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