Re: Problem while linking sdbus.lib file, also AddDevice is crahsing when a call to IoAttachDeviceToDeviceStack() is made.
- From: "Doron Holan [MS]" <doronh@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 22 May 2006 23:27:17 -0700
#include <initguid.h>
before the sd headers
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Eshanye_kp" <esha@xxxxxxxxxxx> wrote in message
news:erdmgzWfGHA.1276@xxxxxxxxxxxxxxxxxxxxxxx
I'm facing two problems in my SDIO client driver.
1. Whenever the call to IoAttachDeviceToDeviceStack() happens, the
system crashes. I have taken the usbbulk as the base code to start off
the development. The IoCreatDevice call is successful and all the
pointers are valid. I have attached my code, pls suggest me what could
be wrong ?
2. I have made #if 0 for the above call and proceeding to add the
further code which is initializing the SDIO bus interface by calling
SdBusOpenInterface(). I have linked the sdbus.lib also in the source
file, and have included the ntddsd. but when i compile i get the error
"Unresolved external symbol _GUID_SDBUS_INTERFACE_STANDARD". What should
i do to avoid this ?
-Esha
-------------------------------------------------------------------------
--------------------------------------------------------------------------------
/*++
Copyright (c) 2000 Microsoft Corporation
Module Name:
Sdiousb.c
Abstract:
Sdiomain device driver for Windows xp
Author: Saravanan
Environment:
kernel mode only
Notes:
Copyright (c) 2000 Microsoft Corporation.
All Rights Reserved.
--*/
#include "Sdiomain.h"
#include "SdioDev.h"
SDIOGLOBALS SdioGlobals;
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING UniRegistryPath
);
NTSTATUS
BulkUsb_AddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
);
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING UniRegistryPath
)
{
NTSTATUS ntStatus;
PUNICODE_STRING pregistryPath;
DbgPrint("\nDriverEntry Entered...");
//
// initialization of variables
//
//registryPath = &Globals.BulkUsb_RegistryPath;
pregistryPath = &SdioGlobals.Sdio_RegistryPath;
DbgPrint("\nEntered Device Entry\n"); //print format for free build
environment
//
// Allocate pool to hold a null-terminated copy of the path.
// Safe in paged pool since all registry routines execute at
// PASSIVE_LEVEL.
//
pregistryPath->MaximumLength = UniRegistryPath->Length +
sizeof(UNICODE_NULL);
pregistryPath->Length = UniRegistryPath->Length;
pregistryPath->Buffer = ExAllocatePool(PagedPool,
pregistryPath->MaximumLength);
if (!(pregistryPath->Buffer)) {
DbgPrint("DriverEntry: Failed to allocate memory for
registryPath\n");
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
goto DriverEntry_Exit;
}
//print format for free build environment
DbgPrint("\nDriverEntry:Registry path info stored in the local buffer\n");
// KdPrint("in sdio"); //print format for checked build environment
RtlZeroMemory (pregistryPath->Buffer,
pregistryPath->MaximumLength);
RtlMoveMemory (pregistryPath->Buffer,
UniRegistryPath->Buffer,
UniRegistryPath->Length);
ntStatus = STATUS_SUCCESS;
//
// Initialize the driver object with this driver's entry points.
//
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
SdioClientDrv_DispatchDevCtrl;
DriverObject->MajorFunction[IRP_MJ_POWER] =
SdioClientDrv_DispatchPower;
DriverObject->MajorFunction[IRP_MJ_PNP] =
SdioClientDrv_DispatchPnP;
DriverObject->MajorFunction[IRP_MJ_CREATE] =
SdioClientDrv_DispatchCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] =
SdioClientDrv_DispatchClose;
DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
SdioClientDrv_DispatchClean;
DriverObject->MajorFunction[IRP_MJ_READ] =
DriverObject->MajorFunction[IRP_MJ_WRITE] =
SdioClientDrv_DispatchReadWrite;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] =
SdioClientDrv_DispatchSysCtrl;
DriverObject->DriverUnload =
SdioClientDrv_DriverUnload;
DriverObject->DriverExtension->AddDevice =
(PDRIVER_ADD_DEVICE)
SdioClientDrv_AddDevice;
//print format for free build environment
DbgPrint("\nDriverEntry:Updated start address of kernel mode drivers\n");
DriverEntry_Exit:
DbgPrint("\nDriverEntry Exit...");
return ntStatus;
}
NTSTATUS
SdioClientDrv_AddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
)
{
NTSTATUS ntStatus;
PDEVICE_OBJECT deviceObject = NULL;
PDEVICE_EXTENSION deviceExtension = NULL;
// SDBUS_INTERFACE_STANDARD sdbus_interface_standard;
// POWER_STATE state;
// KIRQL oldIrql;
DbgPrint("\nAddDevice Entered...");
ntStatus = IoCreateDevice(
DriverObject, // our driver object
sizeof(DEVICE_EXTENSION), // extension size for
us
NULL, // name for this device
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN , // device characteristics
FALSE, // Not exclusive
&deviceObject); // Our device object
DbgPrint("\nAddDevice:ntstatus 0x%x deviceObject addr
0x%x",ntStatus,deviceObject);
if(!NT_SUCCESS(ntStatus))
{
//
// returning failure here prevents the entire stack from
functioning,
// but most likely the rest of the stack will not be able to create
// device objects either, so it is still OK.
//
DbgPrint("\nAddDevice:device obj not created\n");
return ntStatus;
}
DbgPrint("\nAddDevice: device obj created\n");
//
// Initialize the device extension
//
ntStatus = STATUS_SUCCESS;
// Initialize the device extension
//
deviceExtension = (PDEVICE_EXTENSION) deviceObject->DeviceExtension;
// Set all Device Extension pointers to NULL and all variable to zero
//
RtlZeroMemory(deviceExtension, sizeof(DEVICE_EXTENSION));
deviceExtension->FunctionalDeviceObject = deviceObject;
deviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
deviceObject->Flags |= DO_DIRECT_IO;
//
//initialize OpenHandleCount
//
deviceExtension->OpenHandleCount = 0;
//
// Initialize the selective suspend variables
//
KeInitializeSpinLock(&deviceExtension->IdleReqStateLock);
deviceExtension->IdleReqPend = 0;
deviceExtension->PendingIdleIrp = NULL;
DbgPrint("\nAddDevice: Done 3");
//
// set the flags as underlying PDO
//
if(PhysicalDeviceObject->Flags & DO_POWER_PAGABLE) {
deviceObject->Flags |= DO_POWER_PAGABLE;
}
//
// attach our driver to device stack
// The return value of IoAttachDeviceToDeviceStack is the top of the
// attachment chain. This is where all the IRPs should be routed.
//
#if 0
//problem of crahsing
deviceExtension->TopOfStackDeviceObject =
IoAttachDeviceToDeviceStack(deviceObject,
PhysicalDeviceObject);
if(NULL == deviceExtension->TopOfStackDeviceObject) {
DbgPrint("\nAddDevice: IoAttachDeviceToDeviceStack failed");
IoDeleteDevice(deviceObject);
return STATUS_NO_SUCH_DEVICE;
}
#endif
ntStatus = IoRegisterDeviceInterface(
PhysicalDeviceObject,
(LPGUID) &GUID_DEVINTERFACE_SDIO_T3,
NULL,
&deviceExtension->InterfaceName);
if (!NT_SUCCESS (ntStatus)) {
DbgPrint("\nAddDevice: IoRegisterDeviceInterface failed %x",
ntStatus);
IoDetachDevice(deviceExtension->TopOfStackDeviceObject);
IoDeleteDevice(deviceObject);
return ntStatus;
}
DbgPrint("\nAddDevice: Done 7");
#if 1
//Open the SD Bus Interface
//Lib routine returns ptr to the
ntStatus = SdBusOpenInterface (
deviceExtension->PhysicalDeviceObject,
deviceExtension->pInterfaceStandard,
sizeof(SDBUS_INTERFACE_STANDARD),
SDBUS_INTERFACE_VERSION);
DbgPrint("\nAddDevive: SDBusOpenInterface-ntStatus 0x%x",ntStatus);
if (NT_SUCCESS(ntStatus))
{
DbgPrint("\nSd Bus initialization success\n");
}
//Call to Bus Driver routine that initialize the interface(with ptr to
call back routine)
//(*PSDBUS_INITIALIZE_INTERFACE_ROUTINE)
//(
// IN PVOID Context,
// IN PSDBUS_INTERFACE_PARAMETERS InterfaceParameters
//)
#endif
// Clear the DO_DEVICE_INITIALIZING flag.
deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
ntStatus = STATUS_SUCCESS;
DbgPrint("\nAddDevice: Exit..");
return ntStatus;
}
void
SdioClientDrv_DriverUnload(
IN PDRIVER_OBJECT DriverObject
)
{
DbgPrint("\nriverUnload: in driver unload routine\n");
return;
}
#if 0
NTSTATUS ReadDirect(PDEVICE_OBJECT fdo, long function, int Offset,
unsigned short
*Data)
{
NTSTATUS status;
PSDBUS_REQUEST_PACKET sdrp = NULL;
SD_RW_DIRECT_ARGUMENT sdIoArgument;
PWDM_DEVICE_EXTENSION dx =
(PWDM_DEVICE_EXTENSION)fdo->DeviceExtension;
DbgPrint ("Entering ReadDirect\n");
sdrp = (PSDBUS_REQUEST_PACKET)ExAllocatePool(NonPagedPool,
sizeof(SDBUS_REQUEST_PACKET));
if (!sdrp) {
DbgPrint ("Error : Insufficient Memory\n");
return
STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(sdrp, sizeof(SDBUS_REQUEST_PACKET));
sdrp->RequestFunction = SDRF_DEVICE_COMMAND;
sdrp->Parameters.DeviceCommand.CmdDesc = ReadIoDirectDesc;
//
// Set up the argument and command descriptor
//
sdIoArgument.u.AsULONG =
0;
sdIoArgument.u.bits.Address = Offset; //offset = 0xa
sdIoArgument.u.bits.Function = function; // function = 1
sdrp->Parameters.DeviceCommand.Argument =
sdIoArgument.u.AsULONG;
sdrp->Parameters.DeviceCommand.Length = 1; //Byte Access
//
// submit the request
//
status = SdBusSubmitRequest(dx->BusInterface.Context, sdrp);
if (NT_SUCCESS(status)) {
// for direct IO, the data comes in the
response
//*Data = sdrp->ResponseData.AsUCHAR[0];
DbgPrint ("Msg : SdBusSubmitRequest success \n");
RtlCopyMemory (Data, sdrp->ResponseData.AsUCHAR, sizeof
(unsigned short));
}
else
{
DbgPrint ("Msg : SdBusSubmitRequest Failed \n");
}
DbgPrint ("Msg : Data Read : %d\n", Data);
ExFreePool(sdrp);
DbgPrint ("Exiting ReadDirect \n");
return status;
}
#endif
--------------------------------------------------------------------------------
/*++
Copyright (c) 2000 Microsoft Corporation
Module Name:
Sdiomain.h
Abstract:
Environment:
Kernel mode
Notes:
Copyright (c) 2000 Microsoft Corporation.
All Rights Reserved.
--*/
#include <wdm.h>
#include <ntddsd.h>
#include <initguid.h>
// Define an Interface Guid for bus enumerator class.
// This GUID is used to register (IoRegisterDeviceInterface)
// an instance of an interface so that enumerator application
// can send an ioctl to the bus driver.
//
//DEFINE_GUID (GUID_DEVINTERFACE_BUSENUM_TOASTER,
// 0xD35F7840, 0x6A0C, 0x11d2, 0xB8, 0x41, 0x00, 0xC0, 0x4F, 0xAD,
0x51, 0x71);
// {D35F7840-6A0C-11d2-B841-00C04FAD5171}
DEFINE_GUID (GUID_DEVINTERFACE_SDIO_T3,
0x4d36e97d, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1,
0x03, 0x18);
//{4d36e97d-e325-11ce-bfc1-08002be10318}
typedef struct _SDIOGLOBALS {
UNICODE_STRING Sdio_RegistryPath;
} SDIOGLOBALS;
typedef enum _DEVSTATE {
NotStarted, // not started
Stopped, // device stopped
Working, // started and working
PendingStop, // stop pending
PendingRemove, // remove pending
SurpriseRemoved, // removed by surprise
Removed // removed
} DEVSTATE;
//
// A structure representing the instance information associated with
// this particular device.
//
typedef struct _DEVICE_EXTENSION {
// Functional Device Object
PDEVICE_OBJECT FunctionalDeviceObject;
// Device object we call when submitting Urbs
PDEVICE_OBJECT TopOfStackDeviceObject;
// The bus driver object
PDEVICE_OBJECT PhysicalDeviceObject;
// Name buffer for our named Functional device object link
// The name is generated based on the driver's class GUID
UNICODE_STRING InterfaceName;
// Bus drivers set the appropriate values in this structure in response
// to an IRP_MN_QUERY_CAPABILITIES IRP. Function and filter drivers
might
// alter the capabilities set by the bus driver.
DEVICE_CAPABILITIES DeviceCapabilities;
//structure holds pointers to the SD bus interface routines
PSDBUS_INTERFACE_STANDARD pInterfaceStandard;
#if 0
// Configuration Descriptor
//PUSB_CONFIGURATION_DESCRIPTOR UsbConfigurationDescriptor;
// Interface Information structure
//PUSBD_INTERFACE_INFORMATION UsbInterface;
// Pipe context for the bulkusb driver
//PBULKUSB_PIPE_CONTEXT PipeContext;
// current state of device
DEVSTATE DeviceState;
// state prior to removal query
DEVSTATE PrevDevState;
// obtain and hold this lock while changing the device state,
// the queue state and while processing the queue.
KSPIN_LOCK DevStateLock;
// current system power state
SYSTEM_POWER_STATE SysPower;
// current device power state
DEVICE_POWER_STATE DevPower;
// Pending I/O queue state
QUEUE_STATE QueueState;
// Pending I/O queue
LIST_ENTRY NewRequestsQueue;
// I/O Queue Lock
KSPIN_LOCK QueueLock;
KEVENT RemoveEvent;
KEVENT StopEvent;
ULONG OutStandingIO;
KSPIN_LOCK IOCountLock;
// selective suspend variables
LONG SSEnable;
LONG SSRegistryEnable;
//PUSB_IDLE_CALLBACK_INFO IdleCallbackInfo;
#endif
PIRP PendingIdleIrp;
LONG IdleReqPend;
LONG FreeIdleIrpCount;
KSPIN_LOCK IdleReqStateLock;
KEVENT NoIdleReqPendEvent;
// default power state to power down to on self-susped
ULONG PowerDownLevel;
// remote wakeup variables
PIRP WaitWakeIrp;
LONG FlagWWCancel;
LONG FlagWWOutstanding;
LONG WaitWakeEnable;
// open handle count
LONG OpenHandleCount;
// selective suspend model uses timers, dpcs and work item.
KTIMER Timer;
KDPC DeferredProcCall;
// This event is cleared when a DPC/Work Item is queued.
// and signaled when the work-item completes.
// This is essential to prevent the driver from unloading
// while we have DPC or work-item queued up.
KEVENT NoDpcWorkItemPendingEvent;
#if 0
// WMI information
WMILIB_CONTEXT WmiLibInfo;
// WDM version
WDM_VERSION WdmVersion;
#endif
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
typedef struct _IRP_COMPLETION_CONTEXT {
PDEVICE_EXTENSION DeviceExtension;
PKEVENT Event;
} IRP_COMPLETION_CONTEXT, *PIRP_COMPLETION_CONTEXT;
//extern GLOBALS Globals;
//extern ULONG DebugLevel;
.
- References:
- Prev by Date: Re: Writing data out before the system dies
- Next by Date: Re: Two filter drivers with the same FilterClass
- Previous by thread: Problem while linking sdbus.lib file, also AddDevice is crahsing when a call to IoAttachDeviceToDeviceStack() is made.
- Next by thread: Minifilter and Memory mapped i/o
- Index(es):
Relevant Pages
|