NTSTATUS AT91UsbSounCardDevice::Read(KIrp I){
t << "Entering AT91UsbSounCardDevice::Read, " << I << EOL;
if (FALSE)// If (Request is invalid)
{I.Information() = 0;// Invalid parameter in the Read request
return I.PnpComplete(this, STATUS_INVALID_PARAMETER);}
if (I.ReadSize() == 0)// Always ok to read 0 elements.
{I.Information() = 0;
return I.PnpComplete(this, STATUS_SUCCESS);}
NTSTATUS status = STATUS_SUCCESS;
KMemory Mem(I.Mdl());// Declare a memory object
PUCHAR pBuffer = (PUCHAR) Mem.VirtualAddress();// Use the memory object to create a pointer to the caller's buffer
ULONG dwTotalSize = I.ReadSize(CURRENT); // Requested read size
ULONG dwBytesRead = 0; // Count of bytes read
I.Information() = dwBytesRead;
return I.PnpComplete(this, status);}
NTSTATUS AT91UsbSounCardDevice::Write(KIrp I){
t << "Entering AT91UsbSounCardDevice::Write, " << I << EOL;
if (FALSE)
{I.Information() = 0;// Invalid parameter in the Write request
return I.PnpComplete(this, STATUS_INVALID_PARAMETER);}
if (I.WriteSize() == 0)// Always ok to write 0 elements.
{I.Information() = 0;
return I.PnpComplete(this, STATUS_SUCCESS);}
NTSTATUS status = STATUS_SUCCESS;
KMemory Mem(I.Mdl());// Declare a memory object
PUCHAR pBuffer = (PUCHAR) Mem.VirtualAddress();// Use the memory object to create a pointer to the caller's buffer
ULONG dwTotalSize = I.WriteSize(CURRENT);
ULONG dwBytesSent = 0;
I.Information() = dwBytesSent;
return I.PnpComplete(this, status);}
NTSTATUS AT91UsbSounCardDevice::DeviceControl(KIrp I){
NTSTATUS status;
t << "Entering AT91UsbSounCardDevice::Device Control, " << I << EOL;
switch (I.IoctlCode())
{default:status = STATUS_INVALID_PARAMETER;// Unrecognized IOCTL request
break;}
if (status == STATUS_PENDING){return status;}
else{return I.PnpComplete(this, status);}}
AT91UsbSounCardDevice.h
// AT91UsbSounCardDevice.h // Generated by DriverWizard version DriverStudio 2.0.0 (Build 526)
// Requires Compuware's DriverWorks classes
#ifndef __AT91UsbSounCardDevice_h__
#define __AT91UsbSounCardDevice_h__
class AT91UsbSounCardDevice : public KPnpDevice
{// Constructors
public:
SAFE_DESTRUCTORS;
AT91UsbSounCardDevice(PDEVICE_OBJECT Pdo, ULONG Unit);
~AT91UsbSounCardDevice();
// Member Functions
public:
DEVMEMBER_DISPATCHERS
virtual NTSTATUS OnStartDevice(KIrp I);
virtual NTSTATUS OnStopDevice(KIrp I);
virtual NTSTATUS OnRemoveDevice(KIrp I);
virtual NTSTATUS DefaultPnp(KIrp I);
virtual NTSTATUS DefaultPower(KIrp I);
virtual NTSTATUS OnDevicePowerUp(KIrp I);
virtual NTSTATUS OnDeviceSleep(KIrp I);
#ifdef _COMMENT_ONLY
virtual NTSTATUS CleanUp(KIrp I); // COMMENT_ONLY
virtual NTSTATUS Create(KIrp I); // COMMENT_ONLY
virtual NTSTATUS Close(KIrp I); // COMMENT_ONLY
virtual NTSTATUS DeviceControl(KIrp I); // COMMENT_ONLY
virtual NTSTATUS SystemControl(KIrp I); // COMMENT_ONLY
virtual NTSTATUS Read(KIrp I); // COMMENT_ONLY
virtual NTSTATUS Write(KIrp I); // COMMENT_ONLY
#endif
// Member Data
protected:
// Unit number for this device (0-9)
ULONG m_Unit;
KUsbLowerDevice m_Lower;
KUsbInterface m_Interface;};
#endif
interface.h
// interface.h - device interface classes for AT91UsbSounCard
// This GUID identifies the device interface class used by the AT91UsbSounCardDevice device
#define AT91UsbSounCardDevice_CLASS_GUID \
{ 0xb46f2426, 0x8406, 0x49bc, { 0xb6, 0xbd, 0xb4, 0x51, 0x40, 0xf1, 0xcc, 0x39 } }
function.h
// function.h This file controls which driver functions are enabled.
#ifndef __function_h__
#define __function_h__
#define DRIVER_FUNCTION_CREATE
#define DRIVER_FUNCTION_CLOSE
#define DRIVER_FUNCTION_DEVICE_CONTROL
#define DRIVER_FUNCTION_READ
#define DRIVER_FUNCTION_WRITE
#define DRIVER_FUNCTION_ADD_DEVICE
#define DRIVER_FUNCTION_PNP
#define DRIVER_FUNCTION_POWER
#define DRIVER_FUNCTION_SYSTEM_CONTROL
#define DRIVER_FUNCTION_UNLOAD
#define DRIVER_FUNCTION_CLEANUP
#endif
AT91UsbSounCard.inf
[Version]
Signature="$Windows 95$"
Provider=%ProviderName%
Class=NewDeviceClass
ClassGUID={ff646f80-8def-11d2-9449-00105a075f6b}
; 9X Style
[ClassInstall]
Addreg=Class_AddReg
; NT Style
[ClassInstall32]
Addreg=Class_AddReg
[Class_AddReg]
HKR,,,,%DeviceClassName%
HKR,,Icon,,"-18"
;--------- DestinationDirs Section -------------------------------------------
[DestinationDirs]
AT91UsbSounCard_Files_Driver = 10,System32\Drivers
;--------- Manufacturer and Models Sections ----------------------------------
[Manufacturer]
%MfgName%=Mfg0
[Mfg0]
%DeviceDesc%=AT91UsbSounCard_DDI, USB\VID_FFF1&PID_FFF0
;---------- DDInstall Sections -----------------------------------------------
; --------- Windows 9X -----------------
; Experimentation has shown that DDInstall root names greater than 19 characters
; cause problems in Windows 98
[AT91UsbSounCard_DDI]
CopyFiles=AT91UsbSounCard_Files_Driver
AddReg=AT91UsbSounCard_9X_AddReg
[AT91UsbSounCard_9X_AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,AT91UsbSounCard.sys
HKR, "Parameters", "BreakOnEntry", 0x00010001, 0
; --------- Windows NT -----------------
[AT91UsbSounCard_DDI.NT]
CopyFiles=AT91UsbSounCard_Files_Driver
AddReg=AT91UsbSounCard_NT_AddReg
[AT91UsbSounCard_DDI.NT.Services]
Addservice = AT91UsbSounCard, 0x00000002, AT91UsbSounCard_AddService
[AT91UsbSounCard_AddService]
DisplayName = %SvcDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %10%\System32\Drivers\AT91UsbSounCard.sys
[AT91UsbSounCard_NT_AddReg]
HKLM, "System\CurrentControlSet\Services\AT91UsbSounCard\Parameters",\
"BreakOnEntry", 0x00010001, 0
; --------- Files (common) -------------
[AT91UsbSounCard_Files_Driver]
AT91UsbSounCard.sys
;--------- Strings Section ---------------------------------------------------
[Strings]
ProviderName="Your Company Name here"
MfgName="Name of HW Manufacturer here"
DeviceDesc="Description of Device here"
DeviceClassName="Description of Device class here"
SvcDesc="Description of NT service here"
AT91UsbMassStorage.cpp
// AT91UsbMassStorage.cpp // Generated by DriverWizard version DriverStudio 2.0.0 (Build 526)
// Requires Compuware's DriverWorks classes
#define VDW_MAIN
#include <vdw.h>
#include <kusb.h>
#include "AT91UsbMassStorage.h"
#include "AT91UsbMassStorageDevice.h"
#pragma hdrstop("AT91UsbMassStorage.pch")
POOLTAG DefaultPoolTag('19TA');
KTrace t("AT91UsbMassStorage");
// Begin INIT section
#pragma code_seg("INIT")
DECLARE_DRIVER_CLASS(AT91UsbMassStorage, NULL)
NTSTATUS AT91UsbMassStorage::DriverEntry(PUNICODE_STRING RegistryPath){
t << "In DriverEntry\n";
KRegistryKey Params(RegistryPath, L"Parameters");// Open the "Parameters" key under the driver
if ( NT_SUCCESS(Params.LastError()) )
{#if DBG
ULONG bBreakOnEntry = FALSE;
Params.QueryValue(L"BreakOnEntry", &bBreakOnEntry);// Read "BreakOnEntry" value from registry
if (bBreakOnEntry) DbgBreakPoint();// If requested, break into debugger
#endif
LoadRegistryParameters(Params);// Load driver data members from the registry}
m_Unit = 0;
return STATUS_SUCCESS;}
void AT91UsbMassStorage::LoadRegistryParameters(KRegistryKey &Params){
m_bBreakOnEntry = FALSE;
Params.QueryValue(L"BreakOnEntry", &m_bBreakOnEntry);
t << "m_bBreakOnEntry loaded from registry, resulting value: [" << m_bBreakOnEntry << "]\n";}
// End INIT section
#pragma code_seg()
NTSTATUS AT91UsbMassStorage::AddDevice(PDEVICE_OBJECT Pdo){
t << "AddDevice called\n";
AT91UsbMassStorageDevice * pDevice = new (
static_cast<PCWSTR>(KUnitizedName(L"AT91UsbMassStorageDevice", m_Unit)),
FILE_DEVICE_UNKNOWN,
NULL,
0,
DO_DIRECT_IO)
AT91UsbMassStorageDevice(Pdo, m_Unit);
if (pDevice == NULL){
t << "Error creating device AT91UsbMassStorageDevice"
<< (ULONG) m_Unit << EOL;
return STATUS_INSUFFICIENT_RESOURCES;}
NTSTATUS status = pDevice->ConstructorStatus();
if ( !NT_SUCCESS(status) ){
t << "Error constructing device AT91UsbMassStorageDevice"
<< (ULONG) m_Unit << " status " << (ULONG) status << EOL;
delete pDevice;}
else{m_Unit++;}
return status;}
AT91UsbMassStorage.h
// AT91UsbMassStorage.h // Generated by DriverWizard version DriverStudio 2.0.0 (Build 526)
// Requires Compuware's DriverWorks classes
#ifndef __AT91UsbMassStorage_h__
#define __AT91UsbMassStorage_h__
#define EOL "\n"
extern Trace t; // Global driver trace object
class AT91UsbMassStorage : public KDriver{
SAFE_DESTRUCTORS
public:
virtual NTSTATUS DriverEntry(PUNICODE_STRING RegistryPath);
virtual NTSTATUS AddDevice(PDEVICE_OBJECT Pdo);
void LoadRegistryParameters(KRegistryKey &Params);
int m_Unit;
// The following data members are loaded from the registry during DriverEntry
ULONG m_bBreakOnEntry;};
#endif // __AT91UsbMassStorage_h__
AT91UsbMassStorageDevice.cpp
// AT91UsbMassStorageDevice.cpp // Implementation of AT91UsbMassStorageDevice device class
// Generated by DriverWizard version DriverStudio 2.0.0 (Build 526)
// Requires Compuware's DriverWorks classes
#pragma warning(disable:4065) // Allow switch statement with no cases
#include <vdw.h>
#include <kusb.h>
#include "..\AT91UsbMassStorageDeviceinterface.h"
#include "AT91UsbMassStorage.h"
#include "AT91UsbMassStorageDevice.h"
#pragma hdrstop("AT91UsbMassStorage.pch")
extern KTrace t; // Global driver trace object
GUID AT91UsbMassStorageDevice_Guid = AT91UsbMassStorageDevice_CLASS_GUID;
AT91UsbMassStorageDevice::AT91UsbMassStorageDevice(PDEVICE_OBJECT Pdo, ULONG Unit) :
KPnpDevice(Pdo, &AT91UsbMassStorageDevice_Guid){
t << "Entering AT91UsbMassStorageDevice::AT91UsbMassStorageDevice (constructor)\n";
// Check constructor status
if ( ! NT_SUCCESS(m_ConstructorStatus) ){return;}
m_Unit = Unit;// Remember our unit number
m_Lower.Initialize(this, Pdo);// Initialize the lower device
m_Interface.Initialize(
m_Lower, //KUsbLowerDevice
0, //InterfaceNumber
1, //ConfigurationValue
0 //Initial Interface Alternate Setting);
SetLowerDevice(&m_Lower);
SetPnpPolicy();}
AT91UsbMassStorageDevice::~AT91UsbMassStorageDevice()
{t << "Entering AT91UsbMassStorageDevice::~AT91UsbMassStorageDevice() (destructor)\n";}
char *PNPMinorFunctionName(ULONG mn){
static char* minors[] = {
"IRP_MN_START_DEVICE",
"IRP_MN_QUERY_REMOVE_DEVICE",
"IRP_MN_REMOVE_DEVICE",
"IRP_MN_CANCEL_REMOVE_DEVICE",
"IRP_MN_STOP_DEVICE",
"IRP_MN_QUERY_STOP_DEVICE",
"IRP_MN_CANCEL_STOP_DEVICE",
"IRP_MN_QUERY_DEVICE_RELATIONS",
"IRP_MN_QUERY_INTERFACE",
"IRP_MN_QUERY_CAPABILITIES",
"IRP_MN_QUERY_RESOURCES",
"IRP_MN_QUERY_RESOURCE_REQUIREMENTS",
"IRP_MN_QUERY_DEVICE_TEXT",
"IRP_MN_FILTER_RESOURCE_REQUIREMENTS",
"<unknown minor function>",
"IRP_MN_READ_CONFIG",
"IRP_MN_WRITE_CONFIG",
"IRP_MN_EJECT",
"IRP_MN_SET_LOCK",
"IRP_MN_QUERY_ID",
"IRP_MN_QUERY_PNP_DEVICE_STATE",
"IRP_MN_QUERY_BUS_INFORMATION",
"IRP_MN_DEVICE_USAGE_NOTIFICATION",
"IRP_MN_SURPRISE_REMOVAL"};
if (mn > IRP_MN_SURPRISE_REMOVAL)return "<unknown minor function>";
else return minors[mn];}
NTSTATUS AT91UsbMassStorageDevice::DefaultPnp(KIrp I){
t << "Entering AT91UsbMassStorageDevice::DefaultPnp with IRP minor function="
<< PNPMinorFunctionName(I.MinorFunction()) << EOL;
I.ForceReuseOfCurrentStackLocationInCalldown();
return m_Lower.PnpCall(this, I);}
NTSTATUS AT91UsbMassStorageDevice::DefaultPower(KIrp I){
t << "Entering AT91UsbMassStorageDevice::DefaultPower\n";
I.IndicatePowerIrpProcessed();
I.CopyParametersDown();
return m_Lower.PnpPowerCall(this, I);}
NTSTATUS AT91UsbMassStorageDevice::SystemControl(KIrp I){
t << "Entering AT91UsbMassStorageDevice::SystemControl\n";
I.ForceReuseOfCurrentStackLocationInCalldown();
return m_Lower.PnpCall(this, I);}
NTSTATUS AT91UsbMassStorageDevice::OnStartDevice(KIrp I){
t << "Entering AT91UsbMassStorageDevice::OnStartDevice\n";
NTSTATUS status = STATUS_UNSUCCESSFUL;
AC_STATUS acStatus = AC_SUCCESS;
I.Information() = 0;
acStatus = m_Lower.ActivateConfiguration(1);// ConfigurationValue 1 (the first configuration)
switch (acStatus){
case AC_SUCCESS:t << "USB Configuration OK\n";
status = STATUS_SUCCESS;break;
case AC_COULD_NOT_LOCATE_INTERFACE:t << "Could not locate interface\n";break;
case AC_COULD_NOT_PRECONFIGURE_INTERFACE:
t << "Could not get configuration descriptor\n";break;
case AC_CONFIGURATION_REQUEST_FAILED:
t << "Board did not accept configuration URB\n";break;
case AC_FAILED_TO_INITIALIZE_INTERFACE_OBJECT:
t << "Failed to initialize interface object\n";break;
case AC_FAILED_TO_GET_DESCRIPTOR:t << "Failed to get device descriptor\n";break;
case AC_FAILED_TO_OPEN_PIPE_OBJECT:status = STATUS_SUCCESS;
t << "Failed to open pipe object\n";break;
default:t << "Unexpected error activating USB configuration\n";break;}
return status; // base class completes the IRP}
NTSTATUS AT91UsbMassStorageDevice::OnStopDevice(KIrp I){
NTSTATUS status = STATUS_SUCCESS;
t << "Entering AT91UsbMassStorageDevice::OnStopDevice\n";
m_Lower.DeActivateConfiguration();
return status;
UNREFERENCED_PARAMETER(I);}
NTSTATUS AT91UsbMassStorageDevice::OnRemoveDevice(KIrp I){
t << "Entering AT91UsbMassStorageDevice::OnRemoveDevice\n";
// Device removed, release the system resources used by the USB lower device.
m_Lower.ReleaseResources();
return STATUS_SUCCESS;
UNREFERENCED_PARAMETER(I);}
NTSTATUS AT91UsbMassStorageDevice::Create(KIrp I){
NTSTATUS status;
t << "Entering AT91UsbMassStorageDevice::Create, " << I << EOL;
status = I.PnpComplete(this, STATUS_SUCCESS, IO_NO_INCREMENT);
t << "AT91UsbMassStorageDevice::Create Status " << (ULONG)status << EOL;
return status;}
NTSTATUS AT91UsbMassStorageDevice::Close(KIrp I){
NTSTATUS status;
t << "Entering AT91UsbMassStorageDevice::Close, " << I << EOL;
status = I.PnpComplete(this, STATUS_SUCCESS, IO_NO_INCREMENT);
t << "AT91UsbMassStorageDevice::Close Status " << (ULONG)status << EOL;
return status;}
NTSTATUS AT91UsbMassStorageDevice::CleanUp(KIrp I){
t << "Entering CleanUp, " << I << EOL;
return I.PnpComplete(this, STATUS_SUCCESS);}
NTSTATUS AT91UsbMassStorageDevice::Read(KIrp I){
t << "Entering AT91UsbMassStorageDevice::Read, " << I << EOL;
if (FALSE) // If (Request is invalid)
{I.Information() = 0;// Invalid parameter in the Read request
return I.PnpComplete(this, STATUS_INVALID_PARAMETER);}
if (I.ReadSize() == 0)// Always ok to read 0 elements.
{I.Information() = 0;
return I.PnpComplete(this, STATUS_SUCCESS);}
NTSTATUS status = STATUS_SUCCESS;
KMemory Mem(I.Mdl()); // Declare a memory object
// Use the memory object to create a pointer to the caller's buffer
PUCHAR pBuffer = (PUCHAR) Mem.VirtualAddress();