/*++
Copyright (c) 2000 Microsoft Corporation
Module Name:
bulkpnp.c
Abstract:
Bulk USB device driver for Intel 82930 USB test board
Plug and Play module.
This file contains routines to handle pnp requests.
These routines are not USB specific but is required
for every driver which conforms to the WDM model.
Environment:
Kernel mode
Notes:
Copyright (c) 2000 Microsoft Corporation.
All Rights Reserved.
--*/
#include "bulkusb.h"
#include "bulkpnp.h"
#include "bulkpwr.h"
#include "bulkdev.h"
#include "bulkrwr.h"
#include "bulkwmi.h"
#include "bulkusr.h"
NTSTATUS
BulkUsb_DispatchPnP(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
The plug and play dispatch routines.
Most of these requests the driver will completely ignore.
In all cases it must pass on the IRP to the lower driver.
Arguments:
DeviceObject - pointer to a device object.
Irp - pointer to an I/O Request Packet.
Return Value:
NT status value
--*/
{
PIO_STACK_LOCATION irpStack;
PDEVICE_EXTENSION deviceExtension;
KEVENT startDeviceEvent;
NTSTATUS ntStatus;
//
// initialize variables
//
irpStack = IoGetCurrentIrpStackLocation(Irp);
deviceExtension = DeviceObject->DeviceExtension;
//
// since the device is removed, fail the Irp.
//
if(Removed == deviceExtension->DeviceState) {
ntStatus = STATUS_DELETE_PENDING;
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return ntStatus;
}
BulkUsb_DbgPrint(3, ("///////////////////////////////////////////\n"));
BulkUsb_DbgPrint(3, ("BulkUsb_DispatchPnP::"));
BulkUsb_IoIncrement(deviceExtension);
if(irpStack->MinorFunction == IRP_MN_START_DEVICE) {
ASSERT(deviceExtension->IdleReqPend == 0);
}
else {
if(deviceExtension->SSEnable) {
CancelSelectSuspend(deviceExtension);
}
}
BulkUsb_DbgPrint(2, (PnPMinorFunctionString(irpStack->MinorFunction)));
switch(irpStack->MinorFunction) {
case IRP_MN_START_DEVICE:
ntStatus = HandleStartDevice(DeviceObject, Irp);
break;
case IRP_MN_QUERY_STOP_DEVICE:
//
// if we cannot stop the device, we fail the query stop irp
//
ntStatus = CanStopDevice(DeviceObject, Irp);
if(NT_SUCCESS(ntStatus)) {
ntStatus = HandleQueryStopDevice(DeviceObject, Irp);
return ntStatus;
}
break;
case IRP_MN_CANCEL_STOP_DEVICE:
ntStatus = HandleCancelStopDevice(DeviceObject, Irp);
break;
case IRP_MN_STOP_DEVICE:
ntStatus = HandleStopDevice(DeviceObject, Irp);
BulkUsb_DbgPrint(3, ("BulkUsb_DispatchPnP::IRP_MN_STOP_DEVICE::"));
BulkUsb_IoDecrement(deviceExtension);
return ntStatus;
case IRP_MN_QUERY_REMOVE_DEVICE:
//
// if we cannot remove the device, we fail the query remove irp
//
ntStatus = HandleQueryRemoveDevice(DeviceObject, Irp);
return ntStatus;
case IRP_MN_CANCEL_REMOVE_DEVICE:
ntStatus = HandleCancelRemoveDevice(DeviceObject, Irp);
break;
case IRP_MN_SURPRISE_REMOVAL:
ntStatus = HandleSurpriseRemoval(DeviceObject, Irp);
BulkUsb_DbgPrint(3, ("BulkUsb_DispatchPnP::IRP_MN_SURPRISE_REMOVAL::"));
BulkUsb_IoDecrement(deviceExtension);
return ntStatus;
case IRP_MN_REMOVE_DEVICE:
ntStatus = HandleRemoveDevice(DeviceObject, Irp);
return ntStatus;
case IRP_MN_QUERY_CAPABILITIES:
ntStatus = HandleQueryCapabilities(DeviceObject, Irp);
break;
default:
IoSkipCurrentIrpStackLocation(Irp);
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
BulkUsb_DbgPrint(3, ("BulkUsb_DispatchPnP::default::"));
BulkUsb_IoDecrement(deviceExtension);
return ntStatus;
} // switch
//
// complete request
//
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
//
// decrement count
//
BulkUsb_DbgPrint(3, ("BulkUsb_DispatchPnP::"));
BulkUsb_IoDecrement(deviceExtension);
return ntStatus;
}
NTSTATUS
HandleStartDevice(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
This is the dispatch routine for IRP_MN_START_DEVICE
Arguments:
DeviceObject - pointer to a device object.
Irp - I/O request packet
Return Value:
NT status value
--*/
{
KIRQL oldIrql;
KEVENT startDeviceEvent;
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
LARGE_INTEGER dueTime;
BulkUsb_DbgPrint(3, ("HandleStartDevice - begins\n"));
//
// initialize variables
//
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
deviceExtension->UsbConfigurationDescriptor = NULL;
deviceExtension->UsbInterface = NULL;
deviceExtension->PipeContext = NULL;
//
// We cannot touch the device (send it any non pnp irps) until a
// start device has been passed down to the lower drivers.
// first pass the Irp down
//
KeInitializeEvent(&startDeviceEvent, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp,
(PIO_COMPLETION_ROUTINE)IrpCompletionRoutine,
(PVOID)&startDeviceEvent,
TRUE,
TRUE,
TRUE);
ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
if(ntStatus == STATUS_PENDING) {
KeWaitForSingleObject(&startDeviceEvent,
Executive,
KernelMode,
FALSE,
NULL);
ntStatus = Irp->IoStatus.Status;
}
if(!NT_SUCCESS(ntStatus)) {
BulkUsb_DbgPrint(1, ("Lower drivers failed this Irp\n"));
return ntStatus;
}
//
// Read the device descriptor, configuration descriptor
// and select the interface descriptors
//
ntStatus = ReadandSelectDescriptors(DeviceObject);
if(!NT_SUCCESS(ntStatus)) {
BulkUsb_DbgPrint(1, ("ReadandSelectDescriptors failed\n"));
return ntStatus;
}
//
// enable the symbolic links for system components to open
// handles to the device
//
ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName,
TRUE);
if(!NT_SUCCESS(ntStatus)) {
BulkUsb_DbgPrint(1, ("IoSetDeviceInterfaceState:enable:failed\n"));
return ntStatus;
}
KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
SET_NEW_PNP_STATE(deviceExtension, Working);
deviceExtension->QueueState = AllowRequests;
KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
//
// initialize wait wake outstanding flag to false.
// and issue a wait wake.
deviceExtension->FlagWWOutstanding = 0;
deviceExtension->FlagWWCancel = 0;
deviceExtension->WaitWakeIrp = NULL;
if(deviceExtension->WaitWakeEnable) {
IssueWaitWake(deviceExtension);
}
ProcessQueuedRequests(deviceExtension);
if(WinXpOrBetter == deviceExtension->WdmVersion) {
deviceExtension->SSEnable = deviceExtension->SSRegistryEnabl
没有合适的资源?快使用搜索试试~ 我知道了~
ddkusb-DDK开发例子
共53个文件
c:7个
h:7个
obj:7个
3星 · 超过75%的资源 需积分: 6 11 下载量 188 浏览量
2010-04-04
18:01:43
上传
评论
收藏 338KB RAR 举报
温馨提示
ddkusb-DDK开发例子,非常详尽.USB在Windows下的设备驱动例子 。驱动开发实例和讲解
资源推荐
资源详情
资源评论
收起资源包目录
ddkusb-DDK开发例子,非常详尽.USB在Windows下的设备驱动例子.rar (53个子文件)
ddk_usb
bulkusb.plg 339B
usb.ppg 89B
bulkusb.opt 48KB
bulkusb.pnps 163B
dirs 29B
make.bat 110B
bulkusb.ncb 57KB
readme.htm 27KB
bulkusb.dsw 539B
bulkusb.dsp 4KB
bulkusb.htm 4KB
Debug
buildchk_wxp_x86.log 8KB
bulkusb.pnproj 1KB
exe
sources 262B
rwbulk.c 29KB
makefile 269B
rwbulk.rc 322B
objchk_wxp_x86
i386
RwBulk.pdb 203KB
rwbulk.res 892B
rwbulk.obj 40KB
RwBulk.exe 35KB
_objects.mac 570B
sys
bulkrwr.c 17KB
sources 511B
bulkrwr.h 1KB
bulkdev.c 36KB
bulkpnp.c 71KB
bulkpnp.h 3KB
bulkusb.c 12KB
bulkusr.h 1KB
bulkpwr.c 39KB
bulkusb.h 5KB
bulkwmi.h 2KB
bulkusb.inf 2KB
makefile 673B
bulkusb.rc 367B
bulkusb.mof 568B
objchk_wxp_x86
i386
bulkwmi.obj 56KB
bulkusb.sys 48KB
bulkpwr.obj 77KB
bulkrwr.obj 59KB
bulkusb.res 2KB
bulkusb.pdb 163KB
bulkusb.obj 48KB
bulkpnp.obj 105KB
bulkdev.obj 74KB
_objects.mac 1KB
bulkwmi.c 16KB
bulkpwr.h 3KB
bulkdev.h 2KB
bulkusb.bmf 689B
makefile.inc 134B
www.pudn.com.txt 218B
共 53 条
- 1
资源评论
- kevinyao01262013-08-15没有说明文档,不好用
namewchwch
- 粉丝: 4
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功